#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libsock.h" unsigned char buffer[1514]; unsigned char data[60] = {0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x67,0x69,0x73,0x6E,0x88,0xA4,0x21,0x10, 0x0C,0x00,0x00,0x00,0x01,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x30,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; int sock; RT_TASK demo_task; void sockprintf() { printf("this is Sockprintf...!\n"); } void demo(void *agr) { int len,i; rt_task_set_periodic(NULL, TM_NOW, 100000000); while (1) { rt_task_wait_period(NULL); len = send(sock, data, sizeof(data), 0); if (len < 0) { printf("Sent Failed...!\n"); break; } } } void catch_signal(int sig) { close(sock); } int my_send() { struct sched_param param;// = { .sched_priority = 1 }; struct sockaddr_ll addr; struct ifreq ifr; mlockall(MCL_CURRENT|MCL_FUTURE); if ((sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { perror("socket cannot be created"); return 1; } strncpy(ifr.ifr_name, "rteth0", IFNAMSIZ); if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { perror("cannot get interface index"); close(sock); return 1; } addr.sll_family = AF_PACKET; addr.sll_protocol = htons(ETH_P_ALL); addr.sll_pkttype = PACKET_OTHERHOST; addr.sll_ifindex = ifr.ifr_ifindex; if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("cannot bind"); close(sock); return 1; } rt_task_create(&demo_task, "mytask", 0, 99, 0); rt_task_start(&demo_task, &demo, NULL); pause(); rt_task_delete(&demo_task); return 1; }