--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+
+int main()
+{
+ int s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
+ struct sockaddr_ll sll;
+ struct ifreq ifr;
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, "eth0", sizeof(ifr));
+ if (ioctl(s, SIOCGIFINDEX, &ifr) == -1)
+ {
+ perror("ioctl()");
+ return 1;
+ }
+ memset(&sll, 0, sizeof(struct sockaddr_ll));
+ sll.sll_family = AF_PACKET;
+ sll.sll_halen = 6;
+ // Aparentemente no es necesario
+ //sll.sll_addr[0] = 0x00;
+ //sll.sll_addr[1] = 0x80;
+ //sll.sll_addr[2] = 0xc7;
+ //sll.sll_addr[3] = 0x42;
+ //sll.sll_addr[4] = 0x8d;
+ //sll.sll_addr[5] = 0x27;
+ sll.sll_ifindex = ifr.ifr_ifindex;
+ sll.sll_pkttype = PACKET_HOST; // nada de recibir broadcasts, etc.
+ unsigned char buf[] = // Mi supuesto frame
+ {
+ // Ethernet
+ 0x00, 0xd0, 0x09, 0xac, 0x32, 0xe0, // MAC destino
+ 0x00, 0x0c, 0x6e, 0x37, 0x19, 0xbf, // MAC origen
+ 0x08, 0x00, // Type IP
+ // IP
+ 0x45, // Version 4, Header length 5 (5*4 = 20)
+ 0x00, // TOS
+ 0x00, 0x21, // Total length 33
+ 0x12, 0x34, // ID
+ 0x40, 0x00, // Fragmentación: Don't Fragment / Offset 0
+ 0x40, // TTL 64 (porque parece que le gusta a la gente)
+ 0x11, // Protocol UDP
+ 0x00, 0x82, // Checsum
+ 0x0a, 0x0a, 0x0a, 0x02, // Source 10.10.10.2
+ 0x0a, 0x0a, 0x0a, 0x01, // Destination 10.10.10.1
+ // UDP
+ 0x81, 0x0d, // Src Port 33037
+ 0x0b, 0x54, // Dst Port 2900
+ 0x00, 0x0d, // Length 13
+ 0x76, 0x8b, // Checksum
+ // Datos
+ 0x68, 0x6f, 0x6c, 0x61, 0x00 // "hola"
+ };
+ // Trato de mandar...
+ if (sendto(s, buf, sizeof(buf), 0, (struct sockaddr*) &sll,
+ sizeof(struct sockaddr_ll)) < 0)
+ {
+ perror("send()");
+ return 1;
+ }
+ close(s);
+ return 0;
+}
+