tcpdump mailing list archives
[PATCH] tiny make target for embedded systems
From: "Jesse Dutton" <jessedutton () gmail com>
Date: Thu, 27 Jul 2006 15:31:17 -0700
This patch against 3.9.4 adds the tiny target to the Makefile, which is size optimized for embedded systems. It includes printers for ethernet, llc, 802.11, ppp, ppoe, ip, tcp, and udp only. The resulting binary is 67k larger than libpcap (stripped). The normal target is 468k larger than pcap on my machine. Jesse --- diff -ruNa tcpdump-3.9.4/Makefile.in changed/Makefile.in --- tcpdump-3.9.4/Makefile.in 2005-09-20 00:05:36.000000000 -0600 +++ changed/Makefile.in 2006-07-26 21:52:16.000000000 -0600 @@ -89,6 +89,11 @@ print-timed.c print-token.c print-udp.c print-vjc.c print-vrrp.c \ print-wb.c print-zephyr.c setsignal.c tcpdump.c util.c +TINY = 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-ascii.c \ + print-ether.c print-icmp.c print-ip.c print-llc.c print-ppp.c \ + print-pppoe.c print-tcp.c print-udp.c setsignal.c tcpdump.c util.c + LOCALSRC = @LOCALSRC@ GENSRC = version.c LIBOBJS = @LIBOBJS@ @@ -126,6 +131,10 @@ @rm -f $@ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) +tiny: $(GENSRC:.c=.o) $(LIBOBJS) @V_PCAPDEP@ + @rm -f tcpdump $(TINY:.c=.o) + $(CC) -DTINY $(CFLAGS) $(LDFLAGS) -o tcpdump $(TINY) $(GENSRC:.c=.o) $(LIBOBJS) $(LIBS) + datalinks.o: $(srcdir)/missing/datalinks.c $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/datalinks.c dlnames.o: $(srcdir)/missing/dlnames.c diff -ruNa tcpdump-3.9.4/addrtoname.c changed/addrtoname.c --- tcpdump-3.9.4/addrtoname.c 2005-09-29 01:46:45.000000000 -0600 +++ changed/addrtoname.c 2006-07-26 20:15:20.000000000 -0600 @@ -1113,6 +1113,7 @@ init_ipxsaparray(); } +#ifndef TINY const char * dnaddr_string(u_short dnaddr) { @@ -1132,6 +1133,7 @@ return(tp->name); } +#endif /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */ struct hnamemem * diff -ruNa tcpdump-3.9.4/print-ether.c changed/print-ether.c --- tcpdump-3.9.4/print-ether.c 2005-07-10 08:47:57.000000000 -0600 +++ changed/print-ether.c 2006-07-26 21:06:00.000000000 -0600 @@ -190,6 +190,7 @@ ip_print(gndo, p, length); return (1); +#ifndef TINY #ifdef INET6 case ETHERTYPE_IPV6: ip6_print(p, length); @@ -200,7 +201,6 @@ case ETHERTYPE_REVARP: arp_print(gndo, p, length, caplen); return (1); - case ETHERTYPE_DN: decnet_print(p, length, caplen); return (1); @@ -279,16 +279,18 @@ case ETHERTYPE_ISO: isoclns_print(p+1, length-1, length-1); return(1); +#endif case ETHERTYPE_PPPOED: case ETHERTYPE_PPPOES: pppoe_print(p, length); return (1); +#ifndef TINY case ETHERTYPE_EAPOL: eap_print(gndo, p, length); return (1); - +#endif case ETHERTYPE_PPP: if (length) { printf(": "); @@ -296,6 +298,7 @@ } return (1); +#ifndef TINY case ETHERTYPE_SLOW: slow_print(p, length); return (1); @@ -313,6 +316,7 @@ case ETHERTYPE_MOPRC: case ETHERTYPE_MOPDL: /* default_print for now */ +#endif default: return (0); } diff -ruNa tcpdump-3.9.4/print-ip.c changed/print-ip.c --- tcpdump-3.9.4/print-ip.c 2005-09-20 00:05:38.000000000 -0600 +++ changed/print-ip.c 2006-07-26 20:25:55.000000000 -0600 @@ -372,7 +372,7 @@ again: switch (ipds->nh) { - +/* case IPPROTO_AH: ipds->nh = *ipds->cp; ipds->advance = ah_print(ipds->cp); @@ -415,7 +415,7 @@ case IPPROTO_DCCP: dccp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); break; - +*/ case IPPROTO_TCP: tcp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, (ipds->off &~ 0x6000)); @@ -431,7 +431,8 @@ icmp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, (ipds->off & 0x3fff)); break; - + +#ifndef TINY case IPPROTO_PIGP: /* * XXX - the current IANA protocol number assignments @@ -509,7 +510,7 @@ case IPPROTO_PGM: pgm_print(ipds->cp, ipds->len, (const u_char *)ipds->ip); break; - +#endif default: if ((proto = getprotobynumber(ipds->nh)) != NULL) ND_PRINT((ndo, " %s", proto->p_name)); @@ -710,11 +711,13 @@ case 4: ip_print (gndo, bp, length); return; +#ifndef TINY #ifdef INET6 case 6: ip6_print (bp, length); return; #endif +#endif default: (void)printf("unknown ip %d", IP_V(&hdr)); return; diff -ruNa tcpdump-3.9.4/print-llc.c changed/print-llc.c --- tcpdump-3.9.4/print-llc.c 2005-09-29 01:40:13.000000000 -0600 +++ changed/print-llc.c 2006-07-26 21:20:06.000000000 -0600 @@ -179,6 +179,7 @@ is_u = 0; } +#ifndef TINY if (ssap == LLCSAP_GLOBAL && dsap == LLCSAP_GLOBAL) { /* * This is an Ethernet_802.3 IPX frame; it has an @@ -201,6 +202,7 @@ ipx_print(p, length); return (1); } +#endif if (eflag) { printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x)", @@ -216,11 +218,13 @@ } } +#ifndef TINY if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D && control == LLC_UI) { stp_print(p+3, length-3); return (1); } +#endif if (ssap == LLCSAP_IP && dsap == LLCSAP_IP && control == LLC_UI) { @@ -228,6 +232,7 @@ return (1); } +#ifndef TINY if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX && control == LLC_UI) { /* @@ -292,6 +297,7 @@ if (ret) return (ret); } +#endif if (!eflag) { if (ssap == dsap) { @@ -404,6 +410,7 @@ return (ret); break; +#ifndef TINY case OUI_APPLETALK: if (et == ETHERTYPE_ATALK) { /* @@ -427,6 +434,7 @@ return (1); } break; +#endif case OUI_RFC2684: switch (et) { @@ -451,6 +459,7 @@ ether_print(p, length, caplen); return (1); +#ifndef TINY case PID_RFC2684_802_5_FCS: case PID_RFC2684_802_5_NOFCS: /* @@ -496,6 +505,7 @@ case PID_RFC2684_BPDU: stp_print(p, length); return (1); +#endif } } return (0); diff -ruNa tcpdump-3.9.4/print-ppp.c changed/print-ppp.c --- tcpdump-3.9.4/print-ppp.c 2005-06-18 17:56:40.000000000 -0600 +++ changed/print-ppp.c 2006-07-26 21:22:37.000000000 -0600 @@ -1234,11 +1234,13 @@ case PPP_IP: ip_print(gndo, b+1, t - b - 1); goto cleanup; +#ifndef TINY #ifdef INET6 case PPP_IPV6: ip6_print(b+1, t - b - 1); goto cleanup; #endif +#endif default: /* no luck - try next guess */ break; } @@ -1298,6 +1300,7 @@ case PPP_IP: ip_print(gndo, p, length); break; +#ifndef TINY #ifdef INET6 case ETHERTYPE_IPV6: /*XXX*/ case PPP_IPV6: @@ -1315,6 +1318,7 @@ case PPP_MPLS_MCAST: mpls_print(p, length); break; +#endif case PPP_COMP: printf("compressed PPP data"); break; @@ -1498,9 +1502,11 @@ handle_ppp(proto, p, length); break; +#ifndef TINY case CHDLC_UNICAST: case CHDLC_BCAST: return (chdlc_if_print(h, p)); +#endif default: if (eflag) @@ -1610,6 +1616,7 @@ case PPP_IP: ip_print(p, length); break; +#ifndef TINY #ifdef INET6 case PPP_IPV6: ip6_print(p, length); @@ -1621,6 +1628,7 @@ break; } goto printx; +#endif case PPP_VJNC: ptype = vjc_print(q, ptype); hdrlength = PPP_BSDI_HDRLEN; @@ -1629,6 +1637,7 @@ case PPP_IP: ip_print(p, length); break; +#ifndef TINY #ifdef INET6 case PPP_IPV6: ip6_print(p, length); @@ -1640,6 +1649,7 @@ break; } goto printx; +#endif default: if (eflag) { printf("CH=["); @@ -1661,6 +1671,7 @@ case PPP_IP: ip_print(p, length); break; +#ifndef TINY #ifdef INET6 case PPP_IPV6: ip6_print(p, length); @@ -1670,6 +1681,7 @@ case PPP_MPLS_MCAST: mpls_print(p, length); break; +#endif default: printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)); } diff -ruNa tcpdump-3.9.4/print-tcp.c changed/print-tcp.c --- tcpdump-3.9.4/print-tcp.c 2005-04-21 00:36:05.000000000 -0600 +++ changed/print-tcp.c 2006-07-26 21:10:45.000000000 -0600 @@ -30,6 +30,10 @@ #include "config.h" #endif +#ifdef TINY +#undef INET6 +#endif + #include <tcpdump-stdinc.h> #include <stdio.h> @@ -224,6 +228,7 @@ hlen = TH_OFF(tp) * 4; +#ifndef TINY /* * If data present, header length valid, and NFS port used, * assume NFS. @@ -244,6 +249,7 @@ return; } } +#endif #ifdef INET6 if (ip6) { if (ip6->ip6_nxt == IPPROTO_TCP) { @@ -653,6 +659,8 @@ if (flags & TH_RST) { if (vflag) print_tcp_rst_data(bp, length); + +#ifndef TINY } else { if (sport == TELNET_PORT || dport == TELNET_PORT) { if (!qflag && vflag) @@ -681,6 +689,7 @@ else if (length > 0 && (sport == LDP_PORT || dport == LDP_PORT)) { ldp_print(bp, length); } +#endif } return; bad: diff -ruNa tcpdump-3.9.4/print-udp.c changed/print-udp.c --- tcpdump-3.9.4/print-udp.c 2005-04-06 18:28:17.000000000 -0600 +++ changed/print-udp.c 2006-07-26 21:14:36.000000000 -0600 @@ -28,6 +28,10 @@ #include "config.h" #endif +#ifdef TINY +#undef INET6 +#endif + #include <tcpdump-stdinc.h> #ifdef SEGSIZE @@ -467,6 +471,7 @@ (void)printf("truncated-udplength %d", ulen); return; } +#ifndef TINY if (packettype) { register struct sunrpc_msg *rp; enum sunrpc_msg_type direction; @@ -566,6 +571,7 @@ return; } } +#endif udpipaddr_print(ip, sport, dport); if (IP_V(ip) == 4 && (vflag > 1) && !fragmented) { @@ -595,6 +601,7 @@ #endif if (!qflag) { +#ifndef TINY #define ISPORT(p) (dport == (p) || sport == (p)) if (ISPORT(NAMESERVER_PORT)) ns_print((const u_char *)(up + 1), length, 0); @@ -689,6 +696,7 @@ (void)printf("UDP, length %u", (u_int32_t)(ulen - sizeof(*up))); #undef ISPORT +#endif } else (void)printf("UDP, length %u", (u_int32_t)(ulen - sizeof(*up))); } diff -ruNa tcpdump-3.9.4/tcpdump.c changed/tcpdump.c --- tcpdump-3.9.4/tcpdump.c 2005-08-23 04:29:41.000000000 -0600 +++ changed/tcpdump.c 2006-07-26 21:25:43.000000000 -0600 @@ -135,6 +135,31 @@ int type; }; +#ifdef TINY +static struct printer printers[] = { + { ether_if_print, DLT_EN10MB }, + { ppp_if_print, DLT_PPP }, +#ifdef DLT_PPP_WITHDIRECTION + { ppp_if_print, DLT_PPP_WITHDIRECTION }, +#endif +#ifdef DLT_PPP_BSDOS + { ppp_bsdos_if_print, DLT_PPP_BSDOS }, +#endif +#ifdef DLT_PPP_SERIAL + { ppp_hdlc_if_print, DLT_PPP_SERIAL }, +#endif +#ifdef DLT_PPP_ETHER + { pppoe_if_print, DLT_PPP_ETHER }, +#endif +#ifdef DLT_IEEE802_11 + { ieee802_11_if_print, DLT_IEEE802_11}, +#endif +#ifdef DLT_IEEE802_11_RADIO + { ieee802_11_radio_if_print, DLT_IEEE802_11_RADIO }, +#endif + { NULL, 0 }, +}; +#else static struct printer printers[] = { { arcnet_if_print, DLT_ARCNET }, #ifdef DLT_ARCNET_LINUX @@ -267,6 +292,7 @@ #endif { NULL, 0 }, }; +#endif static if_printer lookup_printer(int type) - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
Current thread:
- [PATCH] tiny make target for embedded systems Jesse Dutton (Jul 27)