diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-02-26 10:59:08 +0100 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-02-26 10:59:08 +0100 |
commit | 9da864a8da29082369cdd2dd91a735b03577a117 (patch) | |
tree | 543d881f3746ddd4805dd0da449783eb42a8a92c /examples/historical/mbd/derpspan.c | |
parent | 9ecc4690b2546ac117204207bec21ee1f6d585cf (diff) |
Archive old/unused things
Diffstat (limited to 'examples/historical/mbd/derpspan.c')
-rw-r--r-- | examples/historical/mbd/derpspan.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/historical/mbd/derpspan.c b/examples/historical/mbd/derpspan.c new file mode 100644 index 0000000..b9fb362 --- /dev/null +++ b/examples/historical/mbd/derpspan.c @@ -0,0 +1,48 @@ +// gcc -O2 -o derspan derspan.c -lpcap -std=gnu99 -Wall + +#include <pcap.h> +#include <stdlib.h> +#include <netinet/ip.h> +#include <stdint.h> +#include <stdio.h> + +int rawsock; + +void my_callback(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes) +{ + int len = h->caplen; + if (len < 40) { + //printf("skipped short packet\n"); + return; + } + if (bytes[14] != 0x88 || bytes[15] != 0xbe) { + //printf("skipped non-ethernet packet\n"); + return; + } + if (bytes[36] != 0x08 || bytes[37] != 0x00) { + //printf("skipped non-IPv4 packet\n"); + return; + } + + struct sockaddr_in self; + self.sin_family = AF_INET; + self.sin_addr.s_addr = htonl(0x7f000001); // localhost + self.sin_port = htons(1337); + + sendto(rawsock, bytes + 38, len - 38, 0, (struct sockaddr *)&self, sizeof(self)); +} + +int main(int argc, char **argv) +{ + rawsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + if (rawsock == -1) { + perror("socket"); + exit(0); + } + + pcap_t *pcap = pcap_open_live(argv[1], 1500, 1, 1000, NULL); + pcap_activate(pcap); + pcap_loop(pcap, -1, my_callback, NULL); + return 0; +} + |