From: Miek Gieben Date: Thu, 2 Mar 2006 13:38:27 +0000 (+0000) Subject: okay, when everything fails, do it brute force X-Git-Tag: release-1.1.0~332 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f70907258d3ae6b5f6920ecfdc23ea29b464b4a2;p=thirdparty%2Fldns.git okay, when everything fails, do it brute force is it me, or do all udp dns pkt start at offset 42 .... --- diff --git a/examples/ldns-pcap-drill.c b/examples/ldns-pcap-drill.c index b5c92996..259f4ee6 100644 --- a/examples/ldns-pcap-drill.c +++ b/examples/ldns-pcap-drill.c @@ -1,9 +1,19 @@ #include "config.h" #include +#include -#include -#include + +#define ETHER_HDR_SIZE 14 +#define UDP_HDR_SIZE 8 +#define TCP_HDR_SIZE 0 +#define IP6_HDR_SIZE 40 + +#ifndef ETHERTYPE_IPV6 +#define ETHERTYPE_IPV6 0x86dd +#endif + +#define IP_HL(ip) (((ip)->ip_vhl) & 0x0f) /** * general layout @@ -17,9 +27,66 @@ */ int -main(int argc, char **argv) +pcap2ldns_pkt_ip(const u_char *packet, struct pcap_pkthdr *h) { + uint16_t i; + ldns_status s = 0; - return 1; + ldns_pkt *dns; + + for(i = 0; i < h->caplen; i++) { + if ((s = ldns_wire2pkt(&dns, packet + i, (h->caplen - i))) == LDNS_STATUS_OK) { + printf("%d \n", i); + ldns_pkt_print(stdout, dns); + } + } + return 0; +} + +int +pcap2ldns_pkt(const u_char *packet, struct pcap_pkthdr *h) +{ + struct ether_header *eptr; + eptr = (struct ether_header *) h; + switch(eptr->ether_type) { + case ETHERTYPE_IP: + return pcap2ldns_pkt_ip(packet, h); + break; + case ETHERTYPE_IPV6: + /* + return pcap2ldns_pkt_ip6(packet, h); + */ + break; + case ETHERTYPE_ARP: + fprintf(stderr, "ARP pkt, dropping\n"); + break; + default: + fprintf(stderr, "Not IP pkt, dropping\n"); + break; + } + return 0; } + +int +main(int argc, char **argv) +{ + char errbuf[PCAP_ERRBUF_SIZE]; + pcap_t *p; + struct pcap_pkthdr h; + const u_char *x; + size_t i = 0; + + if (!(p = pcap_open_offline("/tmp/K/20011009-134418-q50000.pkt", errbuf))) { + printf("Cannot open pcap lib %s\n", errbuf); + } + + while ((x = pcap_next(p, &h))) { + pcap2ldns_pkt_ip(x, &h); + i++; + } + printf("pkt seen %zd\n", i); + pcap_close(p); + return 0; +} +