Lines 109-115
Link Here
|
109 |
if(datalink != DLT_EN10MB) return(0); /* validate is our ethernet */ |
109 |
if(datalink != DLT_EN10MB) return(0); /* validate is our ethernet */ |
110 |
if(length < LIBNET_ETH_H) return(0); /* validate can be ethernet */ |
110 |
if(length < LIBNET_ETH_H) return(0); /* validate can be ethernet */ |
111 |
|
111 |
|
112 |
(char *)x->eth = (char *)packet; |
112 |
x->eth = (char *)packet; |
113 |
l2_offset=LIBNET_ETH_H; |
113 |
l2_offset=LIBNET_ETH_H; |
114 |
ok += l2_offset; |
114 |
ok += l2_offset; |
115 |
|
115 |
|
Lines 118-124
Link Here
|
118 |
case ETHERTYPE_ARP: |
118 |
case ETHERTYPE_ARP: |
119 |
if(length < LIBNET_ETH_H + LIBNET_ARP_H) |
119 |
if(length < LIBNET_ETH_H + LIBNET_ARP_H) |
120 |
return(0); |
120 |
return(0); |
121 |
(char *)x->arp = (char *)x->eth + LIBNET_ETH_H; |
121 |
x->arp = (char *)x->eth + LIBNET_ETH_H; |
122 |
ok+=LIBNET_ARP_H; |
122 |
ok+=LIBNET_ARP_H; |
123 |
return(ok); |
123 |
return(ok); |
124 |
break; |
124 |
break; |
Lines 133-140
Link Here
|
133 |
if(length < l2_offset + LIBNET_IP_H) /* Could we be IP? */ |
133 |
if(length < l2_offset + LIBNET_IP_H) /* Could we be IP? */ |
134 |
return(0); |
134 |
return(0); |
135 |
ok+=LIBNET_IP_H; |
135 |
ok+=LIBNET_IP_H; |
136 |
if(x->eth) (char *)x->ip = (char *)x->eth + l2_offset; |
136 |
if(x->eth) x->ip = (char *)x->eth + l2_offset; |
137 |
else (char *)x->ip = (char *)packet; |
137 |
else x->ip = (char *)packet; |
138 |
|
138 |
|
139 |
if(x->ip->ip_off != 0 && x->ip->ip_off != ntohs(16384)) return(0); |
139 |
if(x->ip->ip_off != 0 && x->ip->ip_off != ntohs(16384)) return(0); |
140 |
if(x->ip->ip_v != 4) return(0); |
140 |
if(x->ip->ip_v != 4) return(0); |
Lines 164-182
Link Here
|
164 |
return(0); |
164 |
return(0); |
165 |
ok+=LIBNET_TCP_H; |
165 |
ok+=LIBNET_TCP_H; |
166 |
} |
166 |
} |
167 |
(char *)x->tcp = (char *)x->ip + ((int)x->ip->ip_hl*4); |
167 |
x->tcp = (char *)x->ip + ((int)x->ip->ip_hl*4); |
168 |
break; |
168 |
break; |
169 |
case IPPROTO_UDP: |
169 |
case IPPROTO_UDP: |
170 |
if(length < l2_offset + (int)x->ip->ip_hl*4 + LIBNET_UDP_H) |
170 |
if(length < l2_offset + (int)x->ip->ip_hl*4 + LIBNET_UDP_H) |
171 |
return(0); |
171 |
return(0); |
172 |
ok+=LIBNET_UDP_H; |
172 |
ok+=LIBNET_UDP_H; |
173 |
(char *)x->udp = (char *)x->ip + ((int)x->ip->ip_hl*4); |
173 |
x->udp = (char *)x->ip + ((int)x->ip->ip_hl*4); |
174 |
break; |
174 |
break; |
175 |
case IPPROTO_ICMP: |
175 |
case IPPROTO_ICMP: |
176 |
if(length < l2_offset + (int)x->ip->ip_hl*4 + 8) |
176 |
if(length < l2_offset + (int)x->ip->ip_hl*4 + 8) |
177 |
return(0); |
177 |
return(0); |
178 |
ok+=LIBNET_ICMP_H; |
178 |
ok+=LIBNET_ICMP_H; |
179 |
(char *)x->icmp= (char *)x->ip + ((int)x->ip->ip_hl*4); |
179 |
x->icmp= (char *)x->ip + ((int)x->ip->ip_hl*4); |
180 |
break; |
180 |
break; |
181 |
default: |
181 |
default: |
182 |
return(0); |
182 |
return(0); |
Lines 317-323
Link Here
|
317 |
char buf[MX_B], buf2[MX_B]; |
317 |
char buf[MX_B], buf2[MX_B]; |
318 |
struct frame x; |
318 |
struct frame x; |
319 |
|
319 |
|
320 |
(char *)x.ip = target; |
320 |
x.ip = target; |
321 |
snprintf(buf, sizeof(buf), "%s", inet_ntoa(x.ip->ip_src)); |
321 |
snprintf(buf, sizeof(buf), "%s", inet_ntoa(x.ip->ip_src)); |
322 |
snprintf(buf2, sizeof(buf2), "%s", inet_ntoa(x.ip->ip_dst)); |
322 |
snprintf(buf2, sizeof(buf2), "%s", inet_ntoa(x.ip->ip_dst)); |
323 |
fprintf(stderr, " IP: i=%s->%s v=%hu hl=%hu s=%hu id=%i o=%hu ttl=%hu pay=%u\n", |
323 |
fprintf(stderr, " IP: i=%s->%s v=%hu hl=%hu s=%hu id=%i o=%hu ttl=%hu pay=%u\n", |
Lines 334-340
Link Here
|
334 |
char tmp = '\n'; |
334 |
char tmp = '\n'; |
335 |
|
335 |
|
336 |
if(!short_tcp)tmp=' '; |
336 |
if(!short_tcp)tmp=' '; |
337 |
(char *)x.tcp = target; |
337 |
x.tcp = target; |
338 |
fprintf(stderr, "TCP: p=%u->%u, s/a=%u%c", |
338 |
fprintf(stderr, "TCP: p=%u->%u, s/a=%u%c", |
339 |
ntohs(x.tcp->th_sport), ntohs(x.tcp->th_dport), ntohl(x.tcp->th_seq),tmp); |
339 |
ntohs(x.tcp->th_sport), ntohs(x.tcp->th_dport), ntohl(x.tcp->th_seq),tmp); |
340 |
if(!short_tcp) fprintf(stderr, "-> %u o=%hu f=%hu w=%u u=%u optl=%i\n", |
340 |
if(!short_tcp) fprintf(stderr, "-> %u o=%hu f=%hu w=%u u=%u optl=%i\n", |