]> git.pld-linux.org Git - packages/trafshow.git/blob - trafshow-3.1-ipv6.patch
- updated to 5.2.3
[packages/trafshow.git] / trafshow-3.1-ipv6.patch
1 Subject: a patch to make trafshow 3.1 IPv6 ready
2 From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
3 Date: Wed, 21 Mar 2001 04:46:17 +0900
4 Sender: itojun@itojun.org
5 Message-Id: <20010320194618.019727E73@starfruit.itojun.org>
6
7         the following patch makes trafshow 3.1 IPv6 ready.
8         there are a lot of internal changes, also i did not check
9         if it is compilable on systems with 4.3BSD-like sockaddr (without
10         sa_len).  let me know if it makes sense to you.
11
12         note: (1) color does not work for IPv6.  (2) pcap_lookupnet() is
13         skipped as the function does not work with IPv6-only machines.
14         basically, libpcap is to be blamed.
15
16 itojun
17
18
19 Index: addrtoname.c
20 ===================================================================
21 RCS file: /cvsroot/apps/trafshow/addrtoname.c,v
22 retrieving revision 1.1.1.1
23 retrieving revision 1.2
24 diff -u -r1.1.1.1 -r1.2
25 --- addrtoname.c        2001/03/20 01:48:18     1.1.1.1
26 +++ addrtoname.c        2001/03/20 19:37:56     1.2
27 @@ -86,6 +86,33 @@
28  static u_int32_t f_localnet;
29  static u_int32_t netmask;
30  
31 +#ifdef INET6
32 +struct h6namemem {
33 +       struct in6_addr addr;
34 +       char *name;
35 +       struct h6namemem *nxt;
36 +};
37 +
38 +struct h6namemem h6nametable[HASHNAMESIZE];
39 +
40 +char *
41 +satoa(sa)
42 +       struct sockaddr *sa;
43 +{
44 +       static char buf[NI_MAXHOST];
45 +#ifdef NI_WITHSCOPEID
46 +       const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
47 +#else
48 +       const int niflags = NI_NUMERICHOST;
49 +#endif
50 +
51 +       if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0,
52 +           niflags) != 0)
53 +               strcpy(buf, "?");
54 +       return buf;
55 +}
56 +#endif /* INET6 */
57 +
58  /*
59   * A faster replacement for inet_ntoa().
60   */
61 @@ -186,6 +213,75 @@
62         /* empty */
63  }
64  #endif
65 +
66 +#ifdef INET6
67 +extern char * getname6();
68 +
69 +char *
70 +getnamebysa(sa)
71 +       struct sockaddr *sa;
72 +{
73 +
74 +       if (sa->sa_family == AF_INET)
75 +               return getname((u_char *)&((struct sockaddr_in *)sa)->sin_addr);
76 +       else /* sa->sa_family == AF_INET6 */
77 +               return getname6(&((struct sockaddr_in6 *)sa)->sin6_addr);
78 +}
79 +
80 +char *
81 +getname6(addr)
82 +       struct in6_addr *addr;
83 +{
84 +       register struct h6namemem *p;
85 +       register struct hostent *hp = NULL;
86 +       register char *cp;
87 +       u_long temp[4];
88 +       char buf[INET6_ADDRSTRLEN];
89 +       static int oldtimer;
90 +       static sigfunc oldalarm;
91 +
92 +       bcopy(addr, temp, sizeof(temp));
93 +       temp[0] ^= temp[1] ^ temp[2] ^ temp[3];
94 +
95 +       p = &h6nametable[temp[0] & (HASHNAMESIZE-1)]; 
96 +       for (; p->nxt; p = p->nxt) {
97 +               if (bcmp(&p->addr, addr, sizeof(*addr)) == 0)
98 +                       return (p->name);
99 +       }
100 +       p->addr = *addr;
101 +       p->nxt = (struct h6namemem *)calloc(1, sizeof (*p));
102 +
103 +       /*
104 +        * Only print names when:
105 +        *      (1) -n was not given.
106 +        *      (2) Address is foreign and -f was given.  If -f was not 
107 +        *          present, f_netmask and f_local are 0 and the second
108 +        *          test will succeed.
109 +        *      (3) The host portion is not 0 (i.e., a network address).
110 +        *      (4) The host portion is not broadcast.
111 +        */
112 +       if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(addr) &&
113 +           !IN6_IS_ADDR_LINKLOCAL(addr)) {
114 +               oldtimer = alarm(dns_timeout);
115 +               oldalarm = signal(SIGALRM, nohostname);
116 +#ifdef HAVE_SIGINTERRUPT
117 +               if (!setjmp(getname_env))
118 +#endif
119 +                       hp = gethostbyaddr((char *)&addr, sizeof(*addr), AF_INET6);
120 +               (void)signal(SIGALRM, oldalarm);
121 +               if (oldtimer < 1) oldtimer = 1;
122 +               (void)alarm(oldtimer);
123 +       }
124 +       if (hp) {
125 +               if (Nflag && (cp = index(hp->h_name, '.')) != NULL) *cp = '\0';
126 +               cp = hp->h_name;
127 +       } else cp = inet_ntop(AF_INET6, addr, buf, sizeof(buf));
128 +
129 +       p->name = (char *)malloc((unsigned)(strlen(cp) + 1));
130 +       return strcpy(p->name, cp);
131 +}
132 +
133 +#endif /* INET6 */
134  
135  /*
136   * Return a name for the IP address pointed to by ap.  This address
137 Index: color.c
138 ===================================================================
139 RCS file: /cvsroot/apps/trafshow/color.c,v
140 retrieving revision 1.1.1.1
141 retrieving revision 1.2
142 diff -u -r1.1.1.1 -r1.2
143 --- color.c     2001/03/20 01:48:18     1.1.1.1
144 +++ color.c     2001/03/20 19:37:56     1.2
145 @@ -386,15 +386,19 @@
146         register struct m_entry *m;
147  
148         for (m = color_mask, i = 0; m != NULL, i < n_masks; m++, i++) {
149 -               if ((e->src.s_addr & m->sm.s_addr) ^ m->src.s_addr)
150 +               if (e->src.ss_family != AF_INET || e->dst.ss_family != AF_INET)
151                         continue;
152 -               if ((e->dst.s_addr & m->dm.s_addr) ^ m->dst.s_addr)
153 +               if ((((struct sockaddr_in *)&e->src)->sin_addr.s_addr & m->sm.s_addr) ^ m->src.s_addr)
154                         continue;
155 +               if ((((struct sockaddr_in *)&e->dst)->sin_addr.s_addr & m->dm.s_addr) ^ m->dst.s_addr)
156 +                       continue;
157                 if (m->proto && e->proto != m->proto)
158                         continue;
159 -               if (m->sport && e->sport != m->sport)
160 +               if (m->sport &&
161 +                   ((struct sockaddr_in *)&e->src)->sin_port == m->sport)
162                         continue;
163 -               if (m->dport && e->dport != m->dport)
164 +               if (m->dport && 
165 +                   ((struct sockaddr_in *)&e->dst)->sin_port == m->dport)
166                         continue;
167  #ifdef HAVE_SLCURSES
168                 attron(COLOR_PAIR(m->pair));
169 Index: display.c
170 ===================================================================
171 RCS file: /cvsroot/apps/trafshow/display.c,v
172 retrieving revision 1.1.1.1
173 retrieving revision 1.2
174 diff -u -r1.1.1.1 -r1.2
175 --- display.c   2001/03/20 01:48:18     1.1.1.1
176 +++ display.c   2001/03/20 19:37:56     1.2
177 @@ -34,6 +34,10 @@
178  #include <netinet/ip_icmp.h>
179  #include <netinet/udp.h>
180  #include <netinet/tcp.h>
181 +#ifdef INET6
182 +#include <netinet/ip6.h>
183 +#include <netinet/icmp6.h>
184 +#endif
185  #include <stdlib.h>
186  #include <signal.h>
187  #include <string.h>
188 @@ -41,6 +45,7 @@
189  #ifdef TIME_WITH_SYS_TIME
190  #include <time.h>
191  #endif
192 +#include <netdb.h>
193  
194  #include "trafshow.h"
195  
196 @@ -120,9 +125,9 @@
197   * Pretty print an Internet address (net address + port).
198   */
199  static char *
200 -inet_print(in, port, proto)
201 -       struct in_addr in;
202 -       u_short port, proto;
203 +inet_print(sa, proto)
204 +       struct sockaddr *sa;
205 +       u_short proto;
206  {
207         register char *cp;
208         char pline[20];
209 @@ -134,9 +139,17 @@
210                 "rtrsolicit", "timeexceed", "paramprobl", "stampreqst",
211                 "stampreply", "inforeqst", "inforeply", "maskreqst",
212                 "maskreply" };
213 +       struct in_addr in;
214 +       u_short port;
215 +       struct protoent *p;
216 +
217 +       in = ((struct sockaddr_in *)sa)->sin_addr;
218 +       port = ((struct sockaddr_in *)sa)->sin_port;
219  
220 -       if (l_nflag) cp = intoa(in.s_addr);
221 -       else cp = ipaddr_string(&in);
222 +       if (l_nflag)
223 +               cp = satoa(sa);
224 +       else
225 +               cp = saddr_string(sa);
226         (void) sprintf(aline, "%-*.*s", addr_size, addr_size, cp);
227  
228         if (port) {
229 @@ -146,10 +159,16 @@
230                         cp = udpport_string(port);
231                 else if (proto == IPPROTO_ICMP && port <= ICMP_MAXTYPE)
232                         cp = icmp_type[port];
233 -               else cp = "unknown";
234 +               else if ((p = getprotobynumber(proto)) != NULL)
235 +                       cp = p->p_name;
236 +               else
237 +                       cp = NULL;
238 +
239 +               if (cp)
240 +                       plen = sprintf(pline, "..%.10s", cp);
241 +               else
242 +                       plen = sprintf(pline, "..%10u", proto);
243  
244 -               plen = sprintf(pline, "..%.10s", cp);
245 -
246                 if ((cp = strchr(aline, ' ')) != NULL)
247                         alen = cp - aline;
248                 else    alen = addr_size;
249 @@ -183,9 +202,9 @@
250  
251                 proto = etherproto_string(entries[i].eh.ether_type);
252         } else {
253 -               addstr(inet_print(entries[i].src, entries[i].sport, entries[i].proto));
254 +               addstr(inet_print(&entries[i].src, entries[i].proto));
255                 addch(' ');
256 -               addstr(inet_print(entries[i].dst, entries[i].dport, entries[i].proto));
257 +               addstr(inet_print(&entries[i].dst, entries[i].proto));
258  
259                 proto = getprotoname(entries[i].proto);
260                 if (proto == NULL) proto = "unknown";
261 @@ -270,6 +289,43 @@
262         refresh();
263  }
264  
265 +int
266 +ipaddr_compar(s1, s2)
267 +       struct sockaddr *s1, *s2;
268 +{
269 +
270 +       if (s1->sa_family != s2->sa_family)
271 +               return 0;
272 +       if (s1->sa_family == AF_INET) {
273 +               struct sockaddr_in *sin1, *sin2;
274 +
275 +               sin1 = (struct sockaddr_in *)s1;
276 +               sin2 = (struct sockaddr_in *)s2;
277 +               if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
278 +                       return 0;
279 +               if (sin1->sin_port != sin2->sin_port)
280 +                       return 0;
281 +               return 1;
282 +       }
283 +#ifdef INET6
284 +       if (s1->sa_family == AF_INET6) {
285 +               struct sockaddr_in6 *sin1, *sin2;
286 +
287 +               sin1 = (struct sockaddr_in6 *)s1;
288 +               sin2 = (struct sockaddr_in6 *)s2;
289 +               if (!IN6_ARE_ADDR_EQUAL(&sin1->sin6_addr, &sin2->sin6_addr))
290 +                       return 0;
291 +               if (sin1->sin6_port != sin2->sin6_port)
292 +                       return 0;
293 +               if (sin1->sin6_scope_id != sin2->sin6_scope_id)
294 +                       return 0;
295 +               return 1;
296 +       }
297 +#endif
298 +
299 +       return 0;
300 +}
301 +
302  /*
303   * Add new entry or add bytes to existed record.
304   */
305 @@ -284,10 +340,8 @@
306         j = page * page_size;
307         for (i = 0; i < n_entry; i++) {
308                 if (memcmp(&e->eh, &entries[i].eh, sizeof(e->eh)) == 0 &&
309 -                   e->src.s_addr == entries[i].src.s_addr &&
310 -                   e->sport == entries[i].sport &&
311 -                   e->dst.s_addr == entries[i].dst.s_addr &&
312 -                   e->dport == entries[i].dport &&
313 +                   ipaddr_compar(&e->src, &e->src) &&
314 +                   ipaddr_compar(&e->dst, &e->dst) &&
315                     e->proto == entries[i].proto) {
316                         entries[i].bytes += e->bytes;
317                         if (i >= j && i < j + page_size)
318 @@ -310,20 +364,51 @@
319  }
320  
321  void
322 -display(eh, ip, length)
323 +display(eh, top, length)
324         struct ether_header *eh;
325 -       register struct ip *ip;
326 +       void *top;
327         int length;
328  {
329 +       struct ip *ip;
330 +#ifdef INET6
331 +       struct ip6_hdr *ip6;
332 +#endif
333         register iplen;
334         int hlen, not_ip = 0;
335         register u_char *cp;
336         struct t_entry te;
337 +       in_port_t sport, dport;
338 +       struct sockaddr_in *sin;
339 +#ifdef INET6
340 +       struct sockaddr_in6 *sin6;
341 +#endif
342 +       int minlen;
343 +       int af;
344  
345 -       if ((u_char *)(ip + 1) > snapend) {
346 +       ip = (struct ip *)top;
347 +       switch (ip->ip_v) {
348 +       case 4:
349 +               af = AF_INET;
350 +               minlen = sizeof(*ip);
351 +               iplen = ntohs(ip->ip_len);
352 +               break;
353 +       case 6:
354 +               af = AF_INET6;
355 +               ip = NULL;
356 +               ip6 = (struct ip6_hdr *)top;
357 +               minlen = sizeof(*ip6);
358 +               iplen = ntohs(ip6->ip6_plen) + sizeof(*ip6);
359 +               break;
360 +       default:
361 +               af = 0;
362 +               ip = NULL;
363 +               break;
364 +       }
365 +
366 +       if ((u_char *)top + minlen > snapend) {
367                 if (!eflag) return; /* not ip proto? discard silently */
368                 not_ip++;
369 -       } else if (length < sizeof(*ip)) {
370 +       } else if (length < minlen) {
371                 if (!eflag) {
372                         mvprintw(LINES-1, err_pos, "\
373  truncated-ip: discard %d bytes", length);
374 @@ -331,15 +416,15 @@
375                         goto refresh_screen;
376                 }
377                 not_ip++;
378 -       } else if (ip->ip_v != IPVERSION) {
379 +       } else if (af == 0) {
380                 if (!eflag) {
381                         mvprintw(LINES-1, err_pos, "\
382 -ip ver != %d: discard %d bytes", IPVERSION, length);
383 +unsupported ip ver: discard %d bytes", length);
384                         clrtoeol();
385                         goto refresh_screen;
386                 }
387                 not_ip++;
388 -       } else if ((iplen = ntohs(ip->ip_len)) < 1) {
389 +       } else if (iplen < 1) {
390                 if (!eflag) return; /* empty ip packet? discard silently */
391                 not_ip++;
392         } else if (length < iplen) {
393 @@ -355,9 +440,9 @@
394         if (eh) te.eh = *eh;
395         else memset(&te.eh, 0, sizeof(te.eh));
396  
397 -       te.sport = te.dport = 0;
398 +       sport = dport = 0;
399  
400 -       if (!not_ip) {  /* parse ip packet */
401 +       if (ip) {       /* parse ip packet */
402  
403                 /*
404                 * If this is fragment zero, hand it to the next higher level
405 @@ -376,8 +461,8 @@
406                                         clrtoeol();
407                                         goto refresh_screen;
408                                 }
409 -                               te.sport = ntohs(((struct tcphdr *)cp)->th_sport);
410 -                               te.dport = ntohs(((struct tcphdr *)cp)->th_dport);
411 +                               sport = ntohs(((struct tcphdr *)cp)->th_sport);
412 +                               dport = ntohs(((struct tcphdr *)cp)->th_dport);
413                         } else if (ip->ip_p == IPPROTO_UDP) {
414                                 if (cp + sizeof(struct udphdr) > snapend ||
415                                     iplen - hlen < sizeof(struct udphdr)) {
416 @@ -386,8 +471,8 @@
417                                         clrtoeol();
418                                         goto refresh_screen;
419                                 }
420 -                               te.sport = ntohs(((struct udphdr *)cp)->uh_sport);
421 -                               te.dport = ntohs(((struct udphdr *)cp)->uh_dport);
422 +                               sport = ntohs(((struct udphdr *)cp)->uh_sport);
423 +                               dport = ntohs(((struct udphdr *)cp)->uh_dport);
424                         } else if (ip->ip_p == IPPROTO_ICMP) {
425                                 if (cp + sizeof(struct icmp) > snapend ||
426                                     iplen - hlen < sizeof(struct icmp)) {
427 @@ -396,15 +481,90 @@
428                                         clrtoeol();
429                                         goto refresh_screen;
430                                 }
431 -                               te.sport = ((struct icmp *)cp)->icmp_type;
432 +                               sport = ((struct icmp *)cp)->icmp_type;
433                         }
434                 }
435 -               te.src.s_addr = ip->ip_src.s_addr;
436 -               te.dst.s_addr = ip->ip_dst.s_addr;
437 +               sin = (struct sockaddr_in *)&te.src;
438 +               memset(sin, 0, sizeof(*sin));
439 +               sin->sin_family = AF_INET;
440 +               sin->sin_len = sizeof(*sin);
441 +               sin->sin_addr.s_addr = ip->ip_src.s_addr;
442 +               sin->sin_port = sport;
443 +               sin = (struct sockaddr_in *)&te.dst;
444 +               memset(sin, 0, sizeof(*sin));
445 +               sin->sin_family = AF_INET;
446 +               sin->sin_len = sizeof(*sin);
447 +               sin->sin_addr.s_addr = ip->ip_dst.s_addr;
448 +               sin->sin_port = dport;
449                 te.proto = ip->ip_p;
450                 te.bytes = iplen;
451 -       } else {        /* other than ip protocol packets */
452 -               te.src.s_addr = te.dst.s_addr = 0;
453 +       }
454 +#ifdef INET6
455 +       else if (ip6) {
456 +               /* XXX should chase header chain */
457 +               cp = (u_char *)(ip6 + 1);
458 +               hlen = sizeof(*ip6);
459 +               switch (ip6->ip6_nxt) {
460 +               case IPPROTO_TCP:
461 +                       if (cp + sizeof(struct tcphdr) > snapend ||
462 +                           iplen - hlen < sizeof(struct tcphdr)) {
463 +                               mvprintw(LINES-1, err_pos, "\
464 +truncated-tcp: wrong ip hdrlen");
465 +                               clrtoeol();
466 +                               goto refresh_screen;
467 +                       }
468 +                       sport = ntohs(((struct tcphdr *)cp)->th_sport);
469 +                       dport = ntohs(((struct tcphdr *)cp)->th_dport);
470 +                       break;
471 +               case IPPROTO_UDP:
472 +                       if (cp + sizeof(struct udphdr) > snapend ||
473 +                           iplen - hlen < sizeof(struct udphdr)) {
474 +                               mvprintw(LINES-1, err_pos, "\
475 +truncated-udp: wrong ip hdrlen");
476 +                               clrtoeol();
477 +                               goto refresh_screen;
478 +                       }
479 +                       sport = ntohs(((struct udphdr *)cp)->uh_sport);
480 +                       dport = ntohs(((struct udphdr *)cp)->uh_dport);
481 +                       break;
482 +               case IPPROTO_ICMPV6:
483 +                       if (cp + sizeof(struct icmp6_hdr) > snapend ||
484 +                           iplen - hlen < sizeof(struct icmp6_hdr)) {
485 +                               mvprintw(LINES-1, err_pos, "\
486 +truncated-icmp6: wrong ip hdrlen");
487 +                               clrtoeol();
488 +                               goto refresh_screen;
489 +                       }
490 +                       sport = ((struct icmp6_hdr *)cp)->icmp6_type;
491 +               }
492 +
493 +               sin6 = (struct sockaddr_in6 *)&te.src;
494 +               memset(sin6, 0, sizeof(*sin6));
495 +               sin6->sin6_family = AF_INET6;
496 +               sin6->sin6_len = sizeof(*sin6);
497 +               sin6->sin6_addr = ip6->ip6_src;
498 +               sin6->sin6_port = sport;
499 +               sin6 = (struct sockaddr_in6 *)&te.dst;
500 +               memset(sin6, 0, sizeof(*sin6));
501 +               sin6->sin6_family = AF_INET6;
502 +               sin6->sin6_len = sizeof(*sin6);
503 +               sin6->sin6_addr = ip6->ip6_dst;
504 +               sin6->sin6_port = dport;
505 +               te.proto = ip6->ip6_nxt;
506 +               te.bytes = iplen;
507 +       }
508 +#endif
509 +       else {  /* other than ip protocol packets */
510 +               sin = (struct sockaddr_in *)&te.src;
511 +               sin->sin_family = AF_INET;
512 +               sin->sin_len = sizeof(*sin);
513 +               sin->sin_addr.s_addr = 0;
514 +               sin->sin_port = sport;
515 +               sin = (struct sockaddr_in *)&te.src;
516 +               sin->sin_family = AF_INET;
517 +               sin->sin_len = sizeof(*sin);
518 +               sin->sin_addr.s_addr = 0;
519 +               sin->sin_port = dport;
520                 te.proto = 0;
521                 te.bytes = length;
522         }
523 Index: getarptab.c
524 ===================================================================
525 RCS file: /cvsroot/apps/trafshow/getarptab.c,v
526 retrieving revision 1.1.1.1
527 retrieving revision 1.2
528 diff -u -r1.1.1.1 -r1.2
529 --- getarptab.c 2001/03/20 01:48:21     1.1.1.1
530 +++ getarptab.c 2001/03/20 19:37:56     1.2
531 @@ -14,8 +14,6 @@
532  #include <config.h>
533  #endif
534  
535 -#ifdef HAVE_RTF_LLINFO         /* BSD systems */
536 -
537  #include <sys/param.h>
538  #include <sys/types.h>
539  #include <sys/socket.h>
540 @@ -26,6 +24,8 @@
541  #include <net/route.h>
542  #include <netinet/in.h>
543  #include <netinet/if_ether.h>
544 +
545 +#ifdef HAVE_RTF_LLINFO         /* BSD systems */
546  
547  #ifdef ETHER_ADDR_LEN
548  #define        MAC_ADDR_LEN    ETHER_ADDR_LEN
549 Index: interfaces.c
550 ===================================================================
551 RCS file: /cvsroot/apps/trafshow/interfaces.c,v
552 retrieving revision 1.1.1.1
553 retrieving revision 1.2
554 diff -u -r1.1.1.1 -r1.2
555 --- interfaces.c        2001/03/20 01:48:18     1.1.1.1
556 +++ interfaces.c        2001/03/20 19:37:56     1.2
557 @@ -77,12 +77,23 @@
558  {
559         u_int caplen = h->caplen;
560         u_int length = h->len;
561 +       int grab;
562  
563         if (caplen < ETHER_HDRLEN) return;
564  
565         snapend = p + caplen;
566 -       if (eflag ||
567 -           ntohs(((struct ether_header *)p)->ether_type) == ETHERTYPE_IP)
568 +       grab = 0;
569 +       if (eflag)
570 +               grab++;
571 +       switch (ntohs(((struct ether_header *)p)->ether_type)) {
572 +       case ETHERTYPE_IP:
573 +#ifdef INET6
574 +       case ETHERTYPE_IPV6:
575 +#endif
576 +               grab++;
577 +               break;
578 +       }
579 +       if (grab)
580                 display(p, p + ETHER_HDRLEN, length - ETHER_HDRLEN);
581  }
582  
583 @@ -135,12 +146,17 @@
584                 p += 2;
585                 hdrlen += 2;
586         }
587 -       if (type == 0x21) {     /* IP protocol */
588 +       switch (type) {
589 +       case 0x21:      /* IPv4 */
590 +#ifdef INET6
591 +       case 0x57:      /* IPv6 */
592 +#endif
593  #ifdef SLC_BPFHDR
594                 p = packetp + SLC_BPFHDR;       /* skip bpf pseudo header */
595                 hdrlen = SLC_BPFHDR;
596  #endif
597                 display(NULL, p, length - hdrlen);
598 +               break;
599         }
600  }
601  
602 @@ -157,8 +173,14 @@
603         if (caplen < CHDLC_HDRLEN) return;
604  
605         snapend = p + caplen;
606 -       if (ntohs(*(u_short *)(p + 2)) == 0x0800) /* IP protocol */
607 +       switch (ntohs(*(u_short *)(p + 2))) {
608 +       case 0x0800: /* IP protocol */
609 +#ifdef INET6
610 +       case 0x86dd: /* IP protocol */
611 +#endif
612                 display(NULL, p + CHDLC_HDRLEN, length - CHDLC_HDRLEN);
613 +               break;
614 +       }
615  }
616  #endif
617  
618 @@ -189,8 +211,14 @@
619  
620         memcpy(&family, p, sizeof(family));
621         snapend = p + caplen;
622 -       if (family == AF_INET)
623 +       switch (family) {
624 +       case AF_INET:
625 +#ifdef INET6
626 +       case AF_INET6:
627 +#endif
628                 display(NULL, p + NULL_HDRLEN, length - NULL_HDRLEN);
629 +               break;
630 +       }
631  }
632  
633  /*
634 Index: trafshow.c
635 ===================================================================
636 RCS file: /cvsroot/apps/trafshow/trafshow.c,v
637 retrieving revision 1.1.1.1
638 retrieving revision 1.2
639 diff -u -r1.1.1.1 -r1.2
640 --- trafshow.c  2001/03/20 01:48:19     1.1.1.1
641 +++ trafshow.c  2001/03/20 19:37:57     1.2
642 @@ -69,7 +69,11 @@
643  {
644         int op, cnt;
645         pcap_t *pd;
646 +#ifdef INET6
647 +       bpf_u_int32 netmask = 0;
648 +#else
649         bpf_u_int32 localnet, netmask;
650 +#endif
651         char *cp, *infile, *expr, ebuf[PCAP_ERRBUF_SIZE];
652         struct bpf_program fcode;
653         extern char *optarg;
654 @@ -160,8 +164,10 @@
655  #endif
656             ) error(0, "interface %s not an Ethernet", device_name);
657  
658 +#ifndef INET6
659         if (pcap_lookupnet(device_name, &localnet, &netmask, ebuf) < 0)
660                 error(0, ebuf);
661 +#endif
662  
663         /* Get back to user process after socket has been opened */
664         setuid(getuid());
665 @@ -175,7 +181,11 @@
666             pcap_setfilter(pd, &fcode) < 0)
667                 error(0, pcap_geterr(pd));
668  
669 +#ifdef INET6
670 +       init_addrtoname(0, 0);
671 +#else
672         init_addrtoname(localnet, netmask);
673 +#endif
674  
675         init_term(FALSE);
676  
677 Index: trafshow.h
678 ===================================================================
679 RCS file: /cvsroot/apps/trafshow/trafshow.h,v
680 retrieving revision 1.1.1.1
681 retrieving revision 1.2
682 diff -u -r1.1.1.1 -r1.2
683 --- trafshow.h  2001/03/20 01:48:19     1.1.1.1
684 +++ trafshow.h  2001/03/20 19:37:57     1.2
685 @@ -20,7 +20,11 @@
686  #define        DEFAULT_DNS     2       /* max timeout for gethostbyaddr() */
687  #define        SCR_OFFS        2       /* first show line on screen */
688  #define        MAX_PAGES       20      /* max pages on screen */
689 +#ifdef INET6
690 +#define        DEFAULT_SNAPLEN 88      /* length of saved portion of packet */
691 +#else
692  #define        DEFAULT_SNAPLEN 68      /* length of saved portion of packet */
693 +#endif
694  
695  #define        DEFAULT_COLS    80      /* full screen width */
696  #define        ADDR_SIZE       28      /* host..port size */
697 @@ -67,10 +71,8 @@
698  /* traffic entry */
699  struct t_entry {
700         struct  ether_header eh;
701 -       struct  in_addr src;    /* source ip address */
702 -       u_short sport;          /* source port */
703 -       struct  in_addr dst;    /* destination ip address */
704 -       u_short dport;          /* destination port */
705 +       struct  sockaddr_storage src;   /* source ip address */
706 +       struct  sockaddr_storage dst;   /* destination ip address */
707         u_short proto;          /* ip protocol */
708         u_long  bytes;          /* bytes in ip datagram */
709         u_long  obytes;         /* old bytes */
710 @@ -151,9 +153,16 @@
711  extern void init_addrtoname(u_int32_t, u_int32_t);
712  extern char *getname(u_char *);
713  extern char *intoa(u_int32_t);
714 +#ifdef INET6
715 +extern char *satoa(struct sockaddr *);
716 +extern char *getnamebysa(struct sockaddr *);
717 +#endif
718  extern char *tcpport_string(u_short);
719  extern char *udpport_string(u_short);
720  #define ipaddr_string(p) getname((u_char *)(p))
721 +#ifdef INET6
722 +#define saddr_string(p) getnamebysa(p)
723 +#endif
724  extern char *entoa(u_char *);
725  extern char *etheraddr_string(u_char *);
726  extern char *etherproto_string(u_short);
727
This page took 0.136966 seconds and 3 git commands to generate.