4 #include <sys/socket.h>
5 #include <netpacket/packet.h>
6 #include <net/ethernet.h>
12 int s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
13 struct sockaddr_ll sll;
15 memset(&ifr, 0, sizeof(ifr));
16 strncpy(ifr.ifr_name, "eth0", sizeof(ifr));
17 if (ioctl(s, SIOCGIFINDEX, &ifr) == -1)
22 memset(&sll, 0, sizeof(struct sockaddr_ll));
23 sll.sll_family = AF_PACKET;
25 // Aparentemente no es necesario
26 //sll.sll_addr[0] = 0x00;
27 //sll.sll_addr[1] = 0x80;
28 //sll.sll_addr[2] = 0xc7;
29 //sll.sll_addr[3] = 0x42;
30 //sll.sll_addr[4] = 0x8d;
31 //sll.sll_addr[5] = 0x27;
32 sll.sll_ifindex = ifr.ifr_ifindex;
33 sll.sll_pkttype = PACKET_HOST; // nada de recibir broadcasts, etc.
34 unsigned char buf[] = // Mi supuesto frame
37 0x00, 0xd0, 0x09, 0xac, 0x32, 0xe0, // MAC destino
38 0x00, 0x0c, 0x6e, 0x37, 0x19, 0xbf, // MAC origen
39 0x08, 0x00, // Type IP
41 0x45, // Version 4, Header length 5 (5*4 = 20)
43 0x00, 0x21, // Total length 33
45 0x40, 0x00, // Fragmentación: Don't Fragment / Offset 0
46 0x40, // TTL 64 (porque parece que le gusta a la gente)
48 0x00, 0x82, // Checsum
49 0x0a, 0x0a, 0x0a, 0x02, // Source 10.10.10.2
50 0x0a, 0x0a, 0x0a, 0x01, // Destination 10.10.10.1
52 0x81, 0x0d, // Src Port 33037
53 0x0b, 0x54, // Dst Port 2900
54 0x00, 0x0d, // Length 13
55 0x76, 0x8b, // Checksum
57 0x68, 0x6f, 0x6c, 0x61, 0x00 // "hola"
60 if (sendto(s, buf, sizeof(buf), 0, (struct sockaddr*) &sll,
61 sizeof(struct sockaddr_ll)) < 0)