summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannes <hannes>2004-10-07 14:53:09 +0000
committerhannes <hannes>2004-10-07 14:53:09 +0000
commit4d399db49937fa423cefe179173e351205796036 (patch)
tree20e3d68d769b6b66a19fab39303ba2f020382eb9
parent18c020c000d2cc939d52364e7812cb038e804838 (diff)
downloadtcpdump-4d399db49937fa423cefe179173e351205796036.tar.gz
-move the nlpid definitions and tokens to a dedicated file(s)
-make use of it in the ISO, Frame-relay and CDP printers
-rw-r--r--Makefile.in5
-rwxr-xr-xnlpid.c43
-rw-r--r--nlpid.h30
-rw-r--r--print-cdp.c5
-rw-r--r--print-fr.c65
-rw-r--r--print-isoclns.c26
6 files changed, 92 insertions, 82 deletions
diff --git a/Makefile.in b/Makefile.in
index 443f9211..fffe83e2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -17,7 +17,7 @@
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
-# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.290 2004-09-23 21:57:24 dyoung Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.291 2004-10-07 14:53:10 hannes Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -65,7 +65,8 @@ INSTALL_DATA = @INSTALL_DATA@
@rm -f $@
$(CC) $(CFLAGS) -c $(srcdir)/$*.c
-CSRC = addrtoname.c cpack.c gmpls.c oui.c gmt2local.c ipproto.c l2vpn.c machdep.c parsenfsfh.c \
+CSRC = addrtoname.c cpack.c gmpls.c oui.c gmt2local.c ipproto.c \
+ nlpid.c l2vpn.c machdep.c parsenfsfh.c \
print-802_11.c print-ap1394.c print-ah.c print-arcnet.c \
print-aodv.c print-arp.c print-ascii.c print-atalk.c print-atm.c \
print-beep.c print-bfd.c print-bgp.c print-bootp.c print-cdp.c \
diff --git a/nlpid.c b/nlpid.c
new file mode 100755
index 00000000..d903c125
--- /dev/null
+++ b/nlpid.c
@@ -0,0 +1,43 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code
+ * distributions retain the above copyright notice and this paragraph
+ * in its entirety, and (2) distributions including binary code include
+ * the above copyright notice and this paragraph in its entirety in
+ * the documentation or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
+ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE.
+ *
+ * Original code by Hannes Gredler (hannes@juniper.net)
+ */
+
+#ifndef lint
+static const char rcsid[] _U_ =
+ "@(#) $Header: /tcpdump/master/tcpdump/nlpid.c,v 1.1 2004-10-07 14:53:10 hannes Exp $ (LBL)";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tcpdump-stdinc.h>
+#include "interface.h"
+#include "nlpid.h"
+
+struct tok nlpid_values[] = {
+ { NLPID_NULLNS, "NULL" },
+ { NLPID_LMI, "LMI" },
+ { NLPID_CISCO_LMI, "Cisco LMI" },
+ { NLPID_SNAP, "SNAP" },
+ { NLPID_CLNP, "CLNP" },
+ { NLPID_ESIS, "ES-IS" },
+ { NLPID_ISIS, "IS-IS" },
+ { NLPID_CONS, "CONS" },
+ { NLPID_IDRP, "IDRP" },
+ { NLPID_IP, "IPv4" },
+ { NLPID_X25_ESIS, "X25 ES-IS" },
+ { NLPID_IP6, "IPv6" },
+ { 0, NULL }
+};
diff --git a/nlpid.h b/nlpid.h
new file mode 100644
index 00000000..69641121
--- /dev/null
+++ b/nlpid.h
@@ -0,0 +1,30 @@
+/* @(#) $Header: /tcpdump/master/tcpdump/nlpid.h,v 1.1 2004-10-07 14:53:10 hannes Exp $ (LBL) */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code
+ * distributions retain the above copyright notice and this paragraph
+ * in its entirety, and (2) distributions including binary code include
+ * the above copyright notice and this paragraph in its entirety in
+ * the documentation or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
+ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE.
+ *
+ * Original code by Hannes Gredler (hannes@juniper.net)
+ */
+
+extern struct tok nlpid_values[];
+
+#define NLPID_NULLNS 0x00
+#define NLPID_LMI 0x08 /* ANSI T1.617 Annex D or ITU-T Q.933 Annex A */
+#define NLPID_CISCO_LMI 0x09 /* The original, aka Cisco, aka Gang of Four */
+#define NLPID_SNAP 0x80
+#define NLPID_CLNP 0x81 /* iso9577 */
+#define NLPID_ESIS 0x82 /* iso9577 */
+#define NLPID_ISIS 0x83 /* iso9577 */
+#define NLPID_CONS 0x84
+#define NLPID_IDRP 0x85
+#define NLPID_IP 0xcc
+#define NLPID_X25_ESIS 0x8a
+#define NLPID_IP6 0x8e
diff --git a/print-cdp.c b/print-cdp.c
index 6b345e25..f8f4427c 100644
--- a/print-cdp.c
+++ b/print-cdp.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.24 2004-03-24 05:59:16 guy Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.25 2004-10-07 14:53:11 hannes Exp $";
#endif
#ifdef HAVE_CONFIG_H
@@ -41,6 +41,7 @@ static const char rcsid[] _U_ =
#include "interface.h"
#include "addrtoname.h"
#include "extract.h" /* must come after interface.h */
+#include "nlpid.h"
#define CDP_HEADER_LEN 4
@@ -260,7 +261,7 @@ cdp_print_addr(const u_char * p, int l)
goto trunc;
al = EXTRACT_16BITS(&p[pl]); /* address length */
- if (pt == PT_NLPID && pl == 1 && *p == 0xcc && al == 4) {
+ if (pt == PT_NLPID && pl == 1 && *p == NLPID_IP && al == 4) {
/*
* IPv4: protocol type = NLPID, protocol length = 1
* (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
diff --git a/print-fr.c b/print-fr.c
index b0fe6e1f..9c9aec57 100644
--- a/print-fr.c
+++ b/print-fr.c
@@ -21,7 +21,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.21 2004-04-02 06:53:19 guy Exp $ (LBL)";
+ "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.22 2004-10-07 14:53:10 hannes Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -37,22 +37,11 @@ static const char rcsid[] _U_ =
#include "addrtoname.h"
#include "interface.h"
#include "ethertype.h"
+#include "nlpid.h"
#include "extract.h"
static void lmi_print(const u_char *, u_int);
-#define NLPID_LMI 0x08 /* ANSI T1.617 Annex D or ITU-T Q.933 Annex A */
-#define NLPID_CISCO_LMI 0x09 /* The original, aka Cisco, aka Gang of Four */
-#define NLPID_SNAP 0x80
-#define NLPID_CLNP 0x81
-#define NLPID_ESIS 0x82
-#define NLPID_ISIS 0x83
-#define NLPID_CONS 0x84
-#define NLPID_IDRP 0x85
-#define NLPID_X25_ESIS 0x8a
-#define NLPID_IPV6 0x8e
-#define NLPID_IP 0xcc
-
#define FR_EA_BIT 0x01
@@ -106,32 +95,6 @@ static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *addr_len,
return 0;
}
-
-static const char *fr_nlpids[256];
-
-static void
-init_fr_nlpids(void)
-{
- int i;
- static int fr_nlpid_flag = 0;
-
- if (!fr_nlpid_flag) {
- for (i=0; i < 256; i++)
- fr_nlpids[i] = NULL;
- fr_nlpids[NLPID_LMI] = "LMI";
- fr_nlpids[NLPID_CISCO_LMI] = "Cisco LMI";
- fr_nlpids[NLPID_SNAP] = "SNAP";
- fr_nlpids[NLPID_CLNP] = "CLNP";
- fr_nlpids[NLPID_ESIS] = "ESIS";
- fr_nlpids[NLPID_ISIS] = "ISIS";
- fr_nlpids[NLPID_CONS] = "CONS";
- fr_nlpids[NLPID_IDRP] = "IDRP";
- fr_nlpids[NLPID_X25_ESIS] = "X25_ESIS";
- fr_nlpids[NLPID_IP] = "IP";
- }
- fr_nlpid_flag = 1;
-}
-
/* Frame Relay packet structure, with flags and CRC removed
+---------------------------+
@@ -168,30 +131,18 @@ fr_hdrlen(const u_char *p, u_int addr_len, u_int caplen)
return addr_len + 1 /* UI */ + 1 /* NLPID */;
}
-static const char *
-fr_protostring(u_int8_t proto)
-{
- static char buf[5+1+2+1];
-
- init_fr_nlpids();
-
- if (nflag || fr_nlpids[proto] == NULL) {
- snprintf(buf, sizeof(buf), "proto %02x", proto);
- return buf;
- }
- return fr_nlpids[proto];
-}
-
static void
fr_hdr_print(int length, u_int dlci, char *flags, u_char nlpid)
{
if (qflag)
- (void)printf("DLCI %u, %s%slength %d: ",
+ (void)printf("DLCI %u, %s%slength %u: ",
dlci, flags, *flags ? ", " : "", length);
else
- (void)printf("DLCI %u, %s%s%s, length %d: ",
+ (void)printf("DLCI %u, %s%sNLPID %s (0x%02x), length %u: ",
dlci, flags, *flags ? ", " : "",
- fr_protostring(nlpid), length);
+ tok2str(nlpid_values,"unknown", nlpid),
+ nlpid,
+ length);
}
u_int
@@ -249,7 +200,7 @@ fr_if_print(const struct pcap_pkthdr *h, register const u_char *p)
break;
#ifdef INET6
- case NLPID_IPV6:
+ case NLPID_IP6:
ip6_print(p, length);
break;
#endif
diff --git a/print-isoclns.c b/print-isoclns.c
index 56737044..19026582 100644
--- a/print-isoclns.c
+++ b/print-isoclns.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.121 2004-09-15 17:54:11 hannes Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.122 2004-10-07 14:53:09 hannes Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -42,27 +42,11 @@ static const char rcsid[] _U_ =
#include "addrtoname.h"
#include "ethertype.h"
#include "ether.h"
+#include "nlpid.h"
#include "extract.h"
#include "gmpls.h"
#include "oui.h"
-#define NLPID_CLNP 0x81 /* iso9577 */
-#define NLPID_ESIS 0x82 /* iso9577 */
-#define NLPID_ISIS 0x83 /* iso9577 */
-#define NLPID_IP6 0x8e
-#define NLPID_IP 0xcc
-#define NLPID_NULLNS 0
-
-static struct tok osi_nlpid_values[] = {
- { NLPID_NULLNS, "NULL-NS"},
- { NLPID_CLNP, "CLNP"},
- { NLPID_ESIS, "ES-IS"},
- { NLPID_ISIS, "IS-IS"},
- { NLPID_IP, "IPv4"},
- { NLPID_IP6, "IPv6"},
- { 0, NULL }
-};
-
#define IPV4 1 /* AFI value */
#define IPV6 2 /* AFI value */
@@ -509,7 +493,7 @@ void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
return;
}
- printf("%s",tok2str(osi_nlpid_values,"Unknown NLPID (0x%02x)",*p));
+ printf("%s",tok2str(nlpid_values,"Unknown NLPID (0x%02x)",*p));
switch (*p) {
@@ -838,7 +822,7 @@ esis_print(const u_int8_t *pptr, u_int length)
case ESIS_OPTION_PROTOCOLS:
while (opli>0) {
printf("%s (0x%02x)",
- tok2str(osi_nlpid_values,
+ tok2str(nlpid_values,
"unknown",
*tptr),
*tptr);
@@ -1974,7 +1958,7 @@ static int isis_print (const u_int8_t *p, u_int length)
if (!TTEST2(*(tptr), 1))
goto trunctlv;
printf("%s (0x%02x)",
- tok2str(osi_nlpid_values,
+ tok2str(nlpid_values,
"unknown",
*tptr),
*tptr);