print-atalk.c (66644) | print-atalk.c (75118) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 6 unchanged lines hidden (view full) --- 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Format and print AppleTalk packets. 22 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 6 unchanged lines hidden (view full) --- 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Format and print AppleTalk packets. 22 * |
23 * $FreeBSD: head/contrib/tcpdump/print-atalk.c 66644 2000-10-05 02:49:49Z kris $ | 23 * $FreeBSD: head/contrib/tcpdump/print-atalk.c 75118 2001-04-03 07:50:46Z fenner $ |
24 */ 25 26#ifndef lint 27static const char rcsid[] = | 24 */ 25 26#ifndef lint 27static const char rcsid[] = |
28 "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.51 1999/11/21 09:36:48 fenner Exp $ (LBL)"; | 28 "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.64 2000/10/30 06:22:14 guy Exp $ (LBL)"; |
29#endif 30 31#ifdef HAVE_CONFIG_H 32#include "config.h" 33#endif 34 35#include <sys/param.h> 36#include <sys/time.h> 37#include <sys/socket.h> 38 | 29#endif 30 31#ifdef HAVE_CONFIG_H 32#include "config.h" 33#endif 34 35#include <sys/param.h> 36#include <sys/time.h> 37#include <sys/socket.h> 38 |
39#if __STDC__ 40struct mbuf; 41struct rtentry; 42#endif 43#include <net/if.h> 44 | |
45#include <netinet/in.h> | 39#include <netinet/in.h> |
46#include <netinet/in_systm.h> 47#include <netinet/ip.h> 48#include <netinet/ip_var.h> 49#include <net/ethernet.h> 50#include <netinet/udp.h> 51#include <netinet/udp_var.h> 52#include <netinet/tcp.h> | |
53 54#include <stdio.h> 55#include <stdlib.h> 56#include <string.h> | 40 41#include <stdio.h> 42#include <stdlib.h> 43#include <string.h> |
44#include <netdb.h> /* for MAXHOSTNAMELEN on some platforms */ |
|
57 58#include "interface.h" 59#include "addrtoname.h" 60#include "ethertype.h" 61#include "extract.h" /* must come after interface.h */ 62#include "appletalk.h" 63#include "savestr.h" 64 65static struct tok type2str[] = { 66 { ddpRTMP, "rtmp" }, 67 { ddpRTMPrequest, "rtmpReq" }, 68 { ddpECHO, "echo" }, 69 { ddpIP, "IP" }, 70 { ddpARP, "ARP" }, 71 { ddpKLAP, "KLAP" }, 72 { 0, NULL } 73}; 74 75struct aarp { | 45 46#include "interface.h" 47#include "addrtoname.h" 48#include "ethertype.h" 49#include "extract.h" /* must come after interface.h */ 50#include "appletalk.h" 51#include "savestr.h" 52 53static struct tok type2str[] = { 54 { ddpRTMP, "rtmp" }, 55 { ddpRTMPrequest, "rtmpReq" }, 56 { ddpECHO, "echo" }, 57 { ddpIP, "IP" }, 58 { ddpARP, "ARP" }, 59 { ddpKLAP, "KLAP" }, 60 { 0, NULL } 61}; 62 63struct aarp { |
76 u_short htype, ptype; 77 u_char halen, palen; 78 u_short op; 79 u_char hsaddr[6]; 80 u_char psaddr[4]; 81 u_char hdaddr[6]; 82 u_char pdaddr[4]; | 64 u_int16_t htype, ptype; 65 u_int8_t halen, palen; 66 u_int16_t op; 67 u_int8_t hsaddr[6]; 68 u_int8_t psaddr[4]; 69 u_int8_t hdaddr[6]; 70 u_int8_t pdaddr[4]; |
83}; 84 85static char tstr[] = "[|atalk]"; 86 87static void atp_print(const struct atATP *, u_int); 88static void atp_bitmap_print(u_char); 89static void nbp_print(const struct atNBP *, u_int, u_short, u_char, u_char); 90static const char *print_cstring(const char *, const u_char *); 91static const struct atNBPtuple *nbp_tuple_print(const struct atNBPtuple *, 92 const u_char *, 93 u_short, u_char, u_char); 94static const struct atNBPtuple *nbp_name_print(const struct atNBPtuple *, 95 const u_char *); 96static const char *ataddr_string(u_short, u_char); 97static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); 98static const char *ddpskt_string(int); 99 100/* | 71}; 72 73static char tstr[] = "[|atalk]"; 74 75static void atp_print(const struct atATP *, u_int); 76static void atp_bitmap_print(u_char); 77static void nbp_print(const struct atNBP *, u_int, u_short, u_char, u_char); 78static const char *print_cstring(const char *, const u_char *); 79static const struct atNBPtuple *nbp_tuple_print(const struct atNBPtuple *, 80 const u_char *, 81 u_short, u_char, u_char); 82static const struct atNBPtuple *nbp_name_print(const struct atNBPtuple *, 83 const u_char *); 84static const char *ataddr_string(u_short, u_char); 85static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); 86static const char *ddpskt_string(int); 87 88/* |
101 * Print AppleTalk Datagram Delivery Protocol packets. | 89 * Print AppleTalk LLAP packets. |
102 */ 103void | 90 */ 91void |
104atalk_print(register const u_char *bp, u_int length) | 92llap_print(register const u_char *bp, u_int length) |
105{ 106 register const struct LAP *lp; 107 register const struct atDDP *dp; 108 register const struct atShortDDP *sdp; 109 u_short snet; 110 111#if 0 112 lp = (struct LAP *)bp; --- 47 unchanged lines hidden (view full) --- 160 161 default: 162 printf("%d > %d at-lap#%d %d", 163 lp->src, lp->dst, lp->type, length); 164 break; 165 } 166} 167 | 93{ 94 register const struct LAP *lp; 95 register const struct atDDP *dp; 96 register const struct atShortDDP *sdp; 97 u_short snet; 98 99#if 0 100 lp = (struct LAP *)bp; --- 47 unchanged lines hidden (view full) --- 148 149 default: 150 printf("%d > %d at-lap#%d %d", 151 lp->src, lp->dst, lp->type, length); 152 break; 153 } 154} 155 |
156/* 157 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called 158 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk 159 * packets in them). 160 */ 161void 162atalk_print(register const u_char *bp, u_int length) 163{ 164 register const struct atDDP *dp; 165 u_short snet; 166 167 if (length < ddpSize) { 168 (void)printf(" [|ddp %d]", length); 169 return; 170 } 171 dp = (const struct atDDP *)bp; 172 snet = EXTRACT_16BITS(&dp->srcNet); 173 printf("%s.%s", ataddr_string(snet, dp->srcNode), 174 ddpskt_string(dp->srcSkt)); 175 printf(" > %s.%s:", 176 ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode), 177 ddpskt_string(dp->dstSkt)); 178 bp += ddpSize; 179 length -= ddpSize; 180 ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); 181} 182 |
|
168/* XXX should probably pass in the snap header and do checks like arp_print() */ 169void 170aarp_print(register const u_char *bp, u_int length) 171{ 172 register const struct aarp *ap; 173 174#define AT(member) ataddr_string((ap->member[1]<<8)|ap->member[2],ap->member[3]) 175 --- 13 unchanged lines hidden (view full) --- 189 AT(psaddr), etheraddr_string(ap->hsaddr)); 190 return; 191 192 case 3: /* probe (oy!) */ 193 (void)printf("probe %s tell %s", 194 AT(pdaddr), AT(psaddr)); 195 return; 196 } | 183/* XXX should probably pass in the snap header and do checks like arp_print() */ 184void 185aarp_print(register const u_char *bp, u_int length) 186{ 187 register const struct aarp *ap; 188 189#define AT(member) ataddr_string((ap->member[1]<<8)|ap->member[2],ap->member[3]) 190 --- 13 unchanged lines hidden (view full) --- 204 AT(psaddr), etheraddr_string(ap->hsaddr)); 205 return; 206 207 case 3: /* probe (oy!) */ 208 (void)printf("probe %s tell %s", 209 AT(pdaddr), AT(psaddr)); 210 return; 211 } |
197 (void)printf("len %d op %d htype %d ptype %#x halen %d palen %d", 198 length, ap->op, ap->htype, ap->ptype, ap->halen, ap->palen ); | 212 (void)printf("len %u op %u htype %u ptype %#x halen %u palen %u", 213 length, ntohs(ap->op), ntohs(ap->htype), ntohs(ap->ptype), 214 ap->halen, ap->palen); |
199} 200 | 215} 216 |
217/* 218 * Print AppleTalk Datagram Delivery Protocol packets. 219 */ |
|
201static void 202ddp_print(register const u_char *bp, register u_int length, register int t, 203 register u_short snet, register u_char snode, u_char skt) 204{ 205 206 switch (t) { 207 208 case ddpNBP: --- 297 unchanged lines hidden (view full) --- 506 507 /* 508 * if this is the first call, see if there's an AppleTalk 509 * number to name map file. 510 */ 511 if (first && (first = 0, !nflag) 512 && (fp = fopen("/etc/atalk.names", "r"))) { 513 char line[256]; | 220static void 221ddp_print(register const u_char *bp, register u_int length, register int t, 222 register u_short snet, register u_char snode, u_char skt) 223{ 224 225 switch (t) { 226 227 case ddpNBP: --- 297 unchanged lines hidden (view full) --- 525 526 /* 527 * if this is the first call, see if there's an AppleTalk 528 * number to name map file. 529 */ 530 if (first && (first = 0, !nflag) 531 && (fp = fopen("/etc/atalk.names", "r"))) { 532 char line[256]; |
514 int i1, i2; | 533 int i1, i2, i3; |
515 516 while (fgets(line, sizeof(line), fp)) { 517 if (line[0] == '\n' || line[0] == 0 || line[0] == '#') 518 continue; | 534 535 while (fgets(line, sizeof(line), fp)) { 536 if (line[0] == '\n' || line[0] == 0 || line[0] == '#') 537 continue; |
519 if (sscanf(line, "%d.%d %s", &i1, &i2, nambuf) == 3) | 538 if (sscanf(line, "%d.%d.%d %256s", &i1, &i2, &i3, 539 nambuf) == 4) |
520 /* got a hostname. */ | 540 /* got a hostname. */ |
521 i2 |= (i1 << 8); 522 else if (sscanf(line, "%d %s", &i1, nambuf) == 2) | 541 i3 |= ((i1 << 8) | i2) << 8; 542 else if (sscanf(line, "%d.%d %256s", &i1, &i2, 543 nambuf) == 3) |
523 /* got a net name */ | 544 /* got a net name */ |
524 i2 = (i1 << 8) | 255; | 545 i3 = (((i1 << 8) | i2) << 8) | 255; |
525 else 526 continue; 527 528 for (tp = &hnametable[i2 & (HASHNAMESIZE-1)]; 529 tp->nxt; tp = tp->nxt) 530 ; 531 tp->addr = i2; 532 tp->nxt = newhnamemem(); --- 7 unchanged lines hidden (view full) --- 540 return (tp->name); 541 542 /* didn't have the node name -- see if we've got the net name */ 543 i |= 255; 544 for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt) 545 if (tp2->addr == i) { 546 tp->addr = (atnet << 8) | athost; 547 tp->nxt = newhnamemem(); | 546 else 547 continue; 548 549 for (tp = &hnametable[i2 & (HASHNAMESIZE-1)]; 550 tp->nxt; tp = tp->nxt) 551 ; 552 tp->addr = i2; 553 tp->nxt = newhnamemem(); --- 7 unchanged lines hidden (view full) --- 561 return (tp->name); 562 563 /* didn't have the node name -- see if we've got the net name */ 564 i |= 255; 565 for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt) 566 if (tp2->addr == i) { 567 tp->addr = (atnet << 8) | athost; 568 tp->nxt = newhnamemem(); |
548 (void)snprintf(nambuf, sizeof(nambuf), "%s.%d", tp2->name, athost); | 569 (void)snprintf(nambuf, sizeof(nambuf), "%s.%d", 570 tp2->name, athost); |
549 tp->name = savestr(nambuf); 550 return (tp->name); 551 } 552 553 tp->addr = (atnet << 8) | athost; 554 tp->nxt = newhnamemem(); 555 if (athost != 255) | 571 tp->name = savestr(nambuf); 572 return (tp->name); 573 } 574 575 tp->addr = (atnet << 8) | athost; 576 tp->nxt = newhnamemem(); 577 if (athost != 255) |
556 (void)sprintf(nambuf, "%d.%d", atnet, athost); | 578 (void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d", 579 atnet >> 8, atnet & 0xff, athost); |
557 else | 580 else |
558 (void)sprintf(nambuf, "%d", atnet); | 581 (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8, 582 atnet & 0xff); |
559 tp->name = savestr(nambuf); 560 561 return (tp->name); 562} 563 564static struct tok skt2str[] = { 565 { rtmpSkt, "rtmp" }, /* routing table maintenance */ 566 { nbpSkt, "nis" }, /* name info socket */ 567 { echoSkt, "echo" }, /* AppleTalk echo protocol */ 568 { zipSkt, "zip" }, /* zone info protocol */ 569 { 0, NULL } 570}; 571 572static const char * 573ddpskt_string(register int skt) 574{ 575 static char buf[8]; 576 577 if (nflag) { | 583 tp->name = savestr(nambuf); 584 585 return (tp->name); 586} 587 588static struct tok skt2str[] = { 589 { rtmpSkt, "rtmp" }, /* routing table maintenance */ 590 { nbpSkt, "nis" }, /* name info socket */ 591 { echoSkt, "echo" }, /* AppleTalk echo protocol */ 592 { zipSkt, "zip" }, /* zone info protocol */ 593 { 0, NULL } 594}; 595 596static const char * 597ddpskt_string(register int skt) 598{ 599 static char buf[8]; 600 601 if (nflag) { |
578 (void)sprintf(buf, "%d", skt); | 602 (void)snprintf(buf, sizeof(buf), "%d", skt); |
579 return (buf); 580 } 581 return (tok2str(skt2str, "%d", skt)); 582} | 603 return (buf); 604 } 605 return (tok2str(skt2str, "%d", skt)); 606} |