예제 #1
0
void EtherShield::ES_send_wol(uint8_t *buf,uint8_t *wolmac) {
	send_wol(buf,wolmac);
}
예제 #2
0
파일: wol.c 프로젝트: hajuuk/R7000
int main()
{
        char host[100];
        char ip[100];
        char hwa[100];
        char mask[100];
        char line[200];
        char dev[100];
        int type, flags;
        FILE *fp;
        int num;
        char mac[16];
        char bcast_addr[16];
        int hwa_idx;
        int mac_idx;

        host[0] = '\0';

        /* Open the PROCps kernel table. */
        fp = fopen(_PATH_PROCNET_ARP, "r");
        if (fp == NULL) {
                printf("Unable to open the file\n");
                return 0;
        }

        /* get Bcast addr for 'br0' */
        get_bcast_addr(DEV_NAME, (char *)bcast_addr);

        /* Bypass header -- read until newline */
        if (fgets(line, sizeof(line), fp) != (char *) NULL) {
                mask[0] = '-'; mask[1] = '\0';
                dev[0] = '-'; dev[1] = '\0';

                /* Read the ARP cache entries. */
                for (; fgets(line, sizeof(line), fp);) {
                        num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
                                                 ip, &type, &flags, hwa, mask, dev);
                        if (num < 4)
                                break;

//                      printf("ip: %s, hwa: %s, dev: %s\n", ip, hwa, dev);

                        if (!strcmp(dev, DEV_NAME)) {
                                memset(mac, 0, 16);
                                mac_idx = 0;
                                /* exclude ':' from the 'hwa' */
                                for (hwa_idx = 0; hwa_idx <= 17; hwa_idx += 3, mac_idx += 2) {
                                        memcpy(mac + mac_idx, hwa + hwa_idx, 2);
                                }
//                              printf("mac: %s\n", mac);
                                /* Trigger WOL for the mac */
				send_wol(bcast_addr, mac);
//                              sprintf(cmd, "/usr/sbin/wol -b %s -m %s", bcast_addr, mac);
//                              printf("cmd: %s\n", cmd);
//                                system(cmd);
                        }
                }
        }

        fclose(fp);

        return 0;
}