xref: /dflybsd-src/contrib/tcpdump/addrtoname.h (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1990, 1992, 1993, 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  */
2141c99275SPeter Avalos 
22*ed775ee7SAntonio Huete Jimenez #include "extract.h"
23*ed775ee7SAntonio Huete Jimenez 
24411677aeSAaron LI /*
25*ed775ee7SAntonio Huete Jimenez  * Definition to let us compile most of the IPv6 code even on systems
26411677aeSAaron LI  * without IPv6 support.
27411677aeSAaron LI  */
28411677aeSAaron LI #ifndef INET6_ADDRSTRLEN
29411677aeSAaron LI #define INET6_ADDRSTRLEN	46
30411677aeSAaron LI #endif
31411677aeSAaron LI 
3241c99275SPeter Avalos /* Name to address translation routines. */
3341c99275SPeter Avalos 
34ea7b4bf5SPeter Avalos enum {
35ea7b4bf5SPeter Avalos     LINKADDR_ETHER,
36ea7b4bf5SPeter Avalos     LINKADDR_FRELAY,
37ea7b4bf5SPeter Avalos     LINKADDR_IEEE1394,
38411677aeSAaron LI     LINKADDR_ATM,
39411677aeSAaron LI     LINKADDR_OTHER
40ea7b4bf5SPeter Avalos };
41ea7b4bf5SPeter Avalos 
42ea7b4bf5SPeter Avalos #define BUFSIZE 128
43ea7b4bf5SPeter Avalos 
44*ed775ee7SAntonio Huete Jimenez extern const char *linkaddr_string(netdissect_options *, const uint8_t *, const unsigned int, const unsigned int);
45*ed775ee7SAntonio Huete Jimenez extern const char *etheraddr_string(netdissect_options *, const uint8_t *);
46*ed775ee7SAntonio Huete Jimenez extern const char *le64addr_string(netdissect_options *, const uint8_t *);
47411677aeSAaron LI extern const char *tcpport_string(netdissect_options *, u_short);
48411677aeSAaron LI extern const char *udpport_string(netdissect_options *, u_short);
49*ed775ee7SAntonio Huete Jimenez extern const char *isonsap_string(netdissect_options *, const uint8_t *, u_int);
50411677aeSAaron LI extern const char *dnaddr_string(netdissect_options *, u_short);
51411677aeSAaron LI extern const char *ipxsap_string(netdissect_options *, u_short);
52*ed775ee7SAntonio Huete Jimenez extern const char *ipaddr_string(netdissect_options *, const u_char *);
53*ed775ee7SAntonio Huete Jimenez extern const char *ip6addr_string(netdissect_options *, const u_char *);
54411677aeSAaron LI extern const char *intoa(uint32_t);
5541c99275SPeter Avalos 
56411677aeSAaron LI extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
57411677aeSAaron LI extern struct hnamemem *newhnamemem(netdissect_options *);
58411677aeSAaron LI extern struct h6namemem *newh6namemem(netdissect_options *);
59411677aeSAaron LI extern const char * ieee8021q_tci_string(const uint16_t);
6041c99275SPeter Avalos 
61*ed775ee7SAntonio Huete Jimenez /* macro(s) and inline function(s) with setjmp/longjmp logic to call
62*ed775ee7SAntonio Huete Jimenez  * the X_string() function(s) after bounds checking.
63*ed775ee7SAntonio Huete Jimenez  * The macro(s) must be used on a packet buffer pointer.
64*ed775ee7SAntonio Huete Jimenez  */
65*ed775ee7SAntonio Huete Jimenez 
66*ed775ee7SAntonio Huete Jimenez static inline const char *
get_linkaddr_string(netdissect_options * ndo,const uint8_t * p,const unsigned int type,const unsigned int len)67*ed775ee7SAntonio Huete Jimenez get_linkaddr_string(netdissect_options *ndo, const uint8_t *p,
68*ed775ee7SAntonio Huete Jimenez     const unsigned int type, const unsigned int len)
69*ed775ee7SAntonio Huete Jimenez {
70*ed775ee7SAntonio Huete Jimenez         if (!ND_TTEST_LEN(p, len))
71*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
72*ed775ee7SAntonio Huete Jimenez         return linkaddr_string(ndo, p, type, len);
73*ed775ee7SAntonio Huete Jimenez }
74*ed775ee7SAntonio Huete Jimenez 
75*ed775ee7SAntonio Huete Jimenez static inline const char *
get_etheraddr_string(netdissect_options * ndo,const uint8_t * p)76*ed775ee7SAntonio Huete Jimenez get_etheraddr_string(netdissect_options *ndo, const uint8_t *p)
77*ed775ee7SAntonio Huete Jimenez {
78*ed775ee7SAntonio Huete Jimenez         if (!ND_TTEST_LEN(p, MAC_ADDR_LEN))
79*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
80*ed775ee7SAntonio Huete Jimenez         return etheraddr_string(ndo, p);
81*ed775ee7SAntonio Huete Jimenez }
82*ed775ee7SAntonio Huete Jimenez 
83*ed775ee7SAntonio Huete Jimenez static inline const char *
get_le64addr_string(netdissect_options * ndo,const u_char * p)84*ed775ee7SAntonio Huete Jimenez get_le64addr_string(netdissect_options *ndo, const u_char *p)
85*ed775ee7SAntonio Huete Jimenez {
86*ed775ee7SAntonio Huete Jimenez         if (!ND_TTEST_8(p))
87*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
88*ed775ee7SAntonio Huete Jimenez         return le64addr_string(ndo, p);
89*ed775ee7SAntonio Huete Jimenez }
90*ed775ee7SAntonio Huete Jimenez 
91*ed775ee7SAntonio Huete Jimenez static inline const char *
get_isonsap_string(netdissect_options * ndo,const uint8_t * nsap,u_int nsap_length)92*ed775ee7SAntonio Huete Jimenez get_isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
93*ed775ee7SAntonio Huete Jimenez     u_int nsap_length)
94*ed775ee7SAntonio Huete Jimenez {
95*ed775ee7SAntonio Huete Jimenez 	if (!ND_TTEST_LEN(nsap, nsap_length))
96*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
97*ed775ee7SAntonio Huete Jimenez         return isonsap_string(ndo, nsap, nsap_length);
98*ed775ee7SAntonio Huete Jimenez }
99*ed775ee7SAntonio Huete Jimenez 
100*ed775ee7SAntonio Huete Jimenez static inline const char *
get_ipaddr_string(netdissect_options * ndo,const u_char * p)101*ed775ee7SAntonio Huete Jimenez get_ipaddr_string(netdissect_options *ndo, const u_char *p)
102*ed775ee7SAntonio Huete Jimenez {
103*ed775ee7SAntonio Huete Jimenez         if (!ND_TTEST_4(p))
104*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
105*ed775ee7SAntonio Huete Jimenez         return ipaddr_string(ndo, p);
106*ed775ee7SAntonio Huete Jimenez }
107*ed775ee7SAntonio Huete Jimenez 
108*ed775ee7SAntonio Huete Jimenez static inline const char *
get_ip6addr_string(netdissect_options * ndo,const u_char * p)109*ed775ee7SAntonio Huete Jimenez get_ip6addr_string(netdissect_options *ndo, const u_char *p)
110*ed775ee7SAntonio Huete Jimenez {
111*ed775ee7SAntonio Huete Jimenez         if (!ND_TTEST_16(p))
112*ed775ee7SAntonio Huete Jimenez                 nd_trunc_longjmp(ndo);
113*ed775ee7SAntonio Huete Jimenez         return ip6addr_string(ndo, p);
114*ed775ee7SAntonio Huete Jimenez }
115*ed775ee7SAntonio Huete Jimenez 
116*ed775ee7SAntonio Huete Jimenez #define GET_LINKADDR_STRING(p, type, len) get_linkaddr_string(ndo, (const u_char *)(p), type, len)
117*ed775ee7SAntonio Huete Jimenez #define GET_ETHERADDR_STRING(p) get_etheraddr_string(ndo, (const u_char *)(p))
118*ed775ee7SAntonio Huete Jimenez #define GET_LE64ADDR_STRING(p) get_le64addr_string(ndo, (const u_char *)(p))
119*ed775ee7SAntonio Huete Jimenez #define GET_ISONSAP_STRING(nsap, nsap_length) get_isonsap_string(ndo, (const u_char *)(nsap), nsap_length)
120*ed775ee7SAntonio Huete Jimenez #define GET_IPADDR_STRING(p) get_ipaddr_string(ndo, (const u_char *)(p))
121*ed775ee7SAntonio Huete Jimenez #define GET_IP6ADDR_STRING(p) get_ip6addr_string(ndo, (const u_char *)(p))
122