· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Wake OnLAN

Wake on LAN (WOL)

Magic packetÀÇ »ý¼º

  • Wake on LAN (WOL)À» UDP»ó¿¡¼­ ±¸Çö ÇÏ´Â °æ¿ì UDP packetÀÇ Ã¹ 6 byte´Â FFH·Î ä¿öÁö°í ÀÌÈÄ ´ë»ó PCÀÇ Ethenet MAC address 6 byte°¡ 16ȸ ¹Ýº¹½ÃÄѼ­ UDP Magic packetÀ» ¸¸µé¼ö ÀÖ½À´Ï´Ù. ¸¸¾à MAC address°¡ "44:87:FC:8F:BB:B4" ¶ó°í ÇÑ´Ù¸é ´ÙÀ½°ú °°Àº UDP packetÀ» ¸¸µé¾î Broadcast³ª Unicast·Î ¼ÛÃâÇÏ¸é µË´Ï´Ù.
    00000000 FF FF FF FF FF FF 44 87 | FC 8F BB B4 44 87 FC 8F [......D.....D...]
    00000010 BB B4 44 87 FC 8F BB B4 | 44 87 FC 8F BB B4 44 87 [..D.....D.....D.]
    00000020 FC 8F BB B4 44 87 FC 8F | BB B4 44 87 FC 8F BB B4 [....D.....D.....]
    00000030 44 87 FC 8F BB B4 44 87 | FC 8F BB B4 44 87 FC 8F [D.....D.....D...]
    00000040 BB B4 44 87 FC 8F BB B4 | 44 87 FC 8F BB B4 44 87 [..D.....D.....D.]
    00000050 FC 8F BB B4 44 87 FC 8F | BB B4 44 87 FC 8F BB B4 [....D.....D.....]
    00000060 44 87 FC 8F BB B4                                 [D.....          ]
    


Wake on LAN (WOL) packetÀ» ¼ö½ÅÇÏ¿´´Âµ¥µµ ÄÑÁöÁö ¾Ê´Â °æ¿ì

¿Ïº®ÇÏ°Ô Wake on LAN (WOL)À» Áö¿øÇÏ´Â °æ¿ì´Â »ó°ü¾øÀ¸³ª H/W °¡°ÝÀ» ¶³¾î¶ß¸®±â À§Çؼ­ ÀϺΠÀü¿øÀÌ Àΰ¡ÇÏ¿© 1ȸ ºÎÆÃÈÄ Ä¿³Îµî¿¡ ÀÇÇؼ­ Wake on LAN (WOL)À» µ¿ÀÛ½Ãų¼ö ÀÖµµ·Ï ¸Å¹ø ¼³Á¤ÇØ¾ß µ¿ÀÛÇÏ´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù.

Áï, Á¤Àüµî¿¡ ÀÇÇؼ­ ¿ÏÀüÈ÷ Àü¿øÀÌ ¼Ò½ÇµÈ °æ¿ì Àû¾îµµ ÇѹøÀº ºÎÆÃÈÄ Á¤»óÀûÀÎ shutdown ÀýÂ÷¸¦ ¹à¾Æ¾ß¸¸ Wake on LAN (WOL)ÀÌ µ¿ÀÛÇϵµ·Ï ¼³°èµÈ H/W °¡ ¸¹¾Æ¼­ À̸¦ Á¤È®È÷ È®ÀÎÈÄ »ç¿ëÇÏ½Ã´Â°Ô ÁÁ½À´Ï´Ù.

¿¹Á¦¼Ò½º

  • ¿¹Á¦ ¼Ò½º : ¾Æ·¡ÀÇ ¿¹Á¦´Â ¿©·¯°³ÀÇ NIC¸¦ °¡Áø ´ÙÁß IPȯ°æ¿¡¼­¿¡ ´ëÇÑ °í·Á´Â ºüÁ®ÀÖ½À´Ï´Ù. ½ÇÁ¦ ¹ü¿ëÀûÀÎ ±¸ÇöÀ» À§Çؼ­´Â ´ÙÁßIP¿¡ ´ëÇÑ bind ¹× °³º° IPº°·Î broadcast¸¦ ±¸ÇöÇϴ°ÍÀÌ ÁÁ´Ù´Â Á¡ À¯ÀÇ Çϸ鼭 º¸½Ã¸é ÁÁÀ»µí ÇÕ´Ï´Ù.
    /*
      Copyright (C) JAEHYUK CHO
      All rights reserved.
      Code by JaeHyuk Cho <mailto:minzkn@minzkn.com>
    */

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <unistd.h>

    int main(int s_argc, char **s_argv);

    int main(int s_argc, char **s_argv)
    {
        static const unsigned char s_target_mac[6] = { /* ÀÌ ºÎºÐÀ» ÀÚ½ÅÀÌ ±ú¿ì°íÀÚ ÇÏ´Â PCÀÇ Ethernet MAC address·Î ä¿öÁÖ¸é µÇ°Ú½À´Ï´Ù. */
            0x44u, 0x87u, 0xfcu, 0x8fu, 0xbbu, 0xb4u
        };

        int s_socket;
        struct sockaddr_in s_sockaddr_in;
        unsigned char s_magic_packet[ 6 + (6 * 16) ];
        int s_repeat;
        ssize_t s_send_bytes;
        int s_value;

        /* UDP socket open */
        s_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if(s_socket == (-1)) {
            perror("socket");
            return(EXIT_FAILURE);
        }

        /* bind */
        (void)memset((void *)(&s_sockaddr_in), 0, sizeof(s_sockaddr_in));
        s_sockaddr_in.sin_family = AF_INET;
        s_sockaddr_in.sin_addr.s_addr = htonl(INADDR_ANY);
        s_sockaddr_in.sin_port = htons(0);
        if(bind(s_socket, (const struct sockaddr *)(&s_sockaddr_in), (socklen_t)sizeof(s_sockaddr_in)) == (-1)) {
            perror("bind");

            (void)close(s_socket);

            return(EXIT_FAILURE);
        }

        /* broadcast socket option enable (Broadcast¸¦ À§Çؼ­´Â SO_BROADCAST°¡ ¼³Á¤µÇ¾î¾ß ÇÕ´Ï´Ù.) */
        s_value = 1;
        (void)setsockopt(s_socket, SOL_SOCKET, SO_BROADCAST, (const void *)(&s_value), (socklen_t)sizeof(s_value));

        /* WOL packet build (repeat 6) */
        (void)memset((void *)(&s_magic_packet[0]), 0xff, (size_t)6u); /* Ã¹ 6byte´Â FFH·Î ä¿ó´Ï´Ù. */
        for(s_repeat = 0;s_repeat < 16;s_repeat++) { /* ±ú¿ì°íÀÚ ÇÏ´Â MAC address¸¦ 16ȸ ¹Ýº¹ÇÏ¿© ä¿ó´Ï´Ù. */
            (void)memcpy((void *)(&s_magic_packet[6 + (s_repeat * 6)]), (const void *)(&s_target_mac[0]), sizeof(s_target_mac));
        }

        /* broadcast socket address structure set */
        (void)memset((void *)(&s_sockaddr_in), 0, sizeof(s_sockaddr_in));
        s_sockaddr_in.sin_family = AF_INET;
        (void)inet_pton(s_sockaddr_in.sin_family, "255.255.255.255", (void *)(&s_sockaddr_in.sin_addr));
        s_sockaddr_in.sin_port = htons(2304); /* any port ... (»ç½Ç»ó port´Â ¾Æ¹«°Å³ª »ó°üÇÏÁö ¾Ê½À´Ï´Ù. ´Ù¸¸ ´Ù¸¥ ÀÀ¿ëÇÁ·Î±×·¥µé¿¡°Ô ¹æÇØ°¡ µÇÁö ¾Ê´Â Æ÷Æ®¸¦ ¼±ÅÃÇÏ´Â°Í »ÓÀÔ´Ï´Ù.) */

        /* send */
        s_send_bytes = sendto(
            s_socket,
            (const void *)(&s_magic_packet[0]),
            sizeof(s_magic_packet),
            0,
            (const struct sockaddr *)(&s_sockaddr_in),
            (socklen_t)sizeof(s_sockaddr_in)
        );
        if(s_send_bytes == ((ssize_t)(-1))) {
            perror("sendto");

            (void)close(s_socket);

            return(EXIT_FAILURE);
        }

        (void)fprintf(stdout,
            "WOL packet : %ld bytes (Target %02X:%02X:%02X:%02X:%02X:%02X)\n",
            (long)s_send_bytes,
            (unsigned int)s_target_mac[0], (unsigned int)s_target_mac[1], (unsigned int)s_target_mac[2],
            (unsigned int)s_target_mac[3], (unsigned int)s_target_mac[4], (unsigned int)s_target_mac[5]
        );

        /* socket close */
        (void)close(s_socket);

        return(EXIT_SUCCESS);
    }

    /* vim: set expandtab: */
    /* End of source */

ID
Password
Join
Like winter snow on summer lawn, time past is time gone.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2015-02-06 16:11:45
Processing time 0.0054 sec