xref: /freebsd/contrib/tcpdump/addrtoname.h (revision ee67461e)
14edb46e9SPaul Traina /*
24644f044SBill Fenner  * Copyright (c) 1990, 1992, 1993, 1994, 1995, 1996, 1997
34edb46e9SPaul Traina  *	The Regents of the University of California.  All rights reserved.
44edb46e9SPaul Traina  *
54edb46e9SPaul Traina  * Redistribution and use in source and binary forms, with or without
64edb46e9SPaul Traina  * modification, are permitted provided that: (1) source code distributions
74edb46e9SPaul Traina  * retain the above copyright notice and this paragraph in its entirety, (2)
84edb46e9SPaul Traina  * distributions including binary code include the above copyright notice and
94edb46e9SPaul Traina  * this paragraph in its entirety in the documentation or other materials
104edb46e9SPaul Traina  * provided with the distribution, and (3) all advertising materials mentioning
114edb46e9SPaul Traina  * features or use of this software display the following acknowledgement:
124edb46e9SPaul Traina  * ``This product includes software developed by the University of California,
134edb46e9SPaul Traina  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
144edb46e9SPaul Traina  * the University nor the names of its contributors may be used to endorse
154edb46e9SPaul Traina  * or promote products derived from this software without specific prior
164edb46e9SPaul Traina  * written permission.
174edb46e9SPaul Traina  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
184edb46e9SPaul Traina  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
194edb46e9SPaul Traina  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
204edb46e9SPaul Traina  */
214edb46e9SPaul Traina 
22ee67461eSJoseph Mingrone #include "extract.h"
23ee67461eSJoseph Mingrone 
24ee67461eSJoseph Mingrone #ifdef HAVE_CASPER
25ee67461eSJoseph Mingrone #include <libcasper.h>
26ee67461eSJoseph Mingrone extern cap_channel_t *capdns;
27ee67461eSJoseph Mingrone #endif
28ee67461eSJoseph Mingrone 
293340d773SGleb Smirnoff /*
30ee67461eSJoseph Mingrone  * Definition to let us compile most of the IPv6 code even on systems
313340d773SGleb Smirnoff  * without IPv6 support.
323340d773SGleb Smirnoff  */
333340d773SGleb Smirnoff #ifndef INET6_ADDRSTRLEN
343340d773SGleb Smirnoff #define INET6_ADDRSTRLEN	46
353340d773SGleb Smirnoff #endif
363340d773SGleb Smirnoff 
374edb46e9SPaul Traina /* Name to address translation routines. */
384edb46e9SPaul Traina 
39a5779b6eSRui Paulo enum {
40a5779b6eSRui Paulo     LINKADDR_ETHER,
41a5779b6eSRui Paulo     LINKADDR_FRELAY,
42a5779b6eSRui Paulo     LINKADDR_IEEE1394,
430bff6a5aSEd Maste     LINKADDR_ATM,
440bff6a5aSEd Maste     LINKADDR_OTHER
45a5779b6eSRui Paulo };
46a5779b6eSRui Paulo 
47a5779b6eSRui Paulo #define BUFSIZE 128
48a5779b6eSRui Paulo 
49ee67461eSJoseph Mingrone extern const char *linkaddr_string(netdissect_options *, const uint8_t *, const unsigned int, const unsigned int);
50ee67461eSJoseph Mingrone extern const char *etheraddr_string(netdissect_options *, const uint8_t *);
51ee67461eSJoseph Mingrone extern const char *le64addr_string(netdissect_options *, const uint8_t *);
523340d773SGleb Smirnoff extern const char *tcpport_string(netdissect_options *, u_short);
533340d773SGleb Smirnoff extern const char *udpport_string(netdissect_options *, u_short);
54ee67461eSJoseph Mingrone extern const char *isonsap_string(netdissect_options *, const uint8_t *, u_int);
553c602fabSXin LI extern const char *dnaddr_string(netdissect_options *, u_short);
563340d773SGleb Smirnoff extern const char *ipxsap_string(netdissect_options *, u_short);
57ee67461eSJoseph Mingrone extern const char *ipaddr_string(netdissect_options *, const u_char *);
58ee67461eSJoseph Mingrone extern const char *ip6addr_string(netdissect_options *, const u_char *);
593c602fabSXin LI extern const char *intoa(uint32_t);
604edb46e9SPaul Traina 
613c602fabSXin LI extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
623340d773SGleb Smirnoff extern struct hnamemem *newhnamemem(netdissect_options *);
633340d773SGleb Smirnoff extern struct h6namemem *newh6namemem(netdissect_options *);
648bdc5a62SPatrick Kelsey extern const char * ieee8021q_tci_string(const uint16_t);
654edb46e9SPaul Traina 
66ee67461eSJoseph Mingrone /* macro(s) and inline function(s) with setjmp/longjmp logic to call
67ee67461eSJoseph Mingrone  * the X_string() function(s) after bounds checking.
68ee67461eSJoseph Mingrone  * The macro(s) must be used on a packet buffer pointer.
69ee67461eSJoseph Mingrone  */
70ee67461eSJoseph Mingrone 
71ee67461eSJoseph Mingrone static inline const char *
get_linkaddr_string(netdissect_options * ndo,const uint8_t * p,const unsigned int type,const unsigned int len)72ee67461eSJoseph Mingrone get_linkaddr_string(netdissect_options *ndo, const uint8_t *p,
73ee67461eSJoseph Mingrone     const unsigned int type, const unsigned int len)
74ee67461eSJoseph Mingrone {
75ee67461eSJoseph Mingrone         if (!ND_TTEST_LEN(p, len))
76ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
77ee67461eSJoseph Mingrone         return linkaddr_string(ndo, p, type, len);
78ee67461eSJoseph Mingrone }
79ee67461eSJoseph Mingrone 
80ee67461eSJoseph Mingrone static inline const char *
get_etheraddr_string(netdissect_options * ndo,const uint8_t * p)81ee67461eSJoseph Mingrone get_etheraddr_string(netdissect_options *ndo, const uint8_t *p)
82ee67461eSJoseph Mingrone {
83ee67461eSJoseph Mingrone         if (!ND_TTEST_LEN(p, MAC_ADDR_LEN))
84ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
85ee67461eSJoseph Mingrone         return etheraddr_string(ndo, p);
86ee67461eSJoseph Mingrone }
87ee67461eSJoseph Mingrone 
88ee67461eSJoseph Mingrone static inline const char *
get_le64addr_string(netdissect_options * ndo,const u_char * p)89ee67461eSJoseph Mingrone get_le64addr_string(netdissect_options *ndo, const u_char *p)
90ee67461eSJoseph Mingrone {
91ee67461eSJoseph Mingrone         if (!ND_TTEST_8(p))
92ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
93ee67461eSJoseph Mingrone         return le64addr_string(ndo, p);
94ee67461eSJoseph Mingrone }
95ee67461eSJoseph Mingrone 
96ee67461eSJoseph Mingrone static inline const char *
get_isonsap_string(netdissect_options * ndo,const uint8_t * nsap,u_int nsap_length)97ee67461eSJoseph Mingrone get_isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
98ee67461eSJoseph Mingrone     u_int nsap_length)
99ee67461eSJoseph Mingrone {
100ee67461eSJoseph Mingrone 	if (!ND_TTEST_LEN(nsap, nsap_length))
101ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
102ee67461eSJoseph Mingrone         return isonsap_string(ndo, nsap, nsap_length);
103ee67461eSJoseph Mingrone }
104ee67461eSJoseph Mingrone 
105ee67461eSJoseph Mingrone static inline const char *
get_ipaddr_string(netdissect_options * ndo,const u_char * p)106ee67461eSJoseph Mingrone get_ipaddr_string(netdissect_options *ndo, const u_char *p)
107ee67461eSJoseph Mingrone {
108ee67461eSJoseph Mingrone         if (!ND_TTEST_4(p))
109ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
110ee67461eSJoseph Mingrone         return ipaddr_string(ndo, p);
111ee67461eSJoseph Mingrone }
112ee67461eSJoseph Mingrone 
113ee67461eSJoseph Mingrone static inline const char *
get_ip6addr_string(netdissect_options * ndo,const u_char * p)114ee67461eSJoseph Mingrone get_ip6addr_string(netdissect_options *ndo, const u_char *p)
115ee67461eSJoseph Mingrone {
116ee67461eSJoseph Mingrone         if (!ND_TTEST_16(p))
117ee67461eSJoseph Mingrone                 nd_trunc_longjmp(ndo);
118ee67461eSJoseph Mingrone         return ip6addr_string(ndo, p);
119ee67461eSJoseph Mingrone }
120ee67461eSJoseph Mingrone 
121ee67461eSJoseph Mingrone #define GET_LINKADDR_STRING(p, type, len) get_linkaddr_string(ndo, (const u_char *)(p), type, len)
122ee67461eSJoseph Mingrone #define GET_ETHERADDR_STRING(p) get_etheraddr_string(ndo, (const u_char *)(p))
123ee67461eSJoseph Mingrone #define GET_LE64ADDR_STRING(p) get_le64addr_string(ndo, (const u_char *)(p))
124ee67461eSJoseph Mingrone #define GET_ISONSAP_STRING(nsap, nsap_length) get_isonsap_string(ndo, (const u_char *)(nsap), nsap_length)
125ee67461eSJoseph Mingrone #define GET_IPADDR_STRING(p) get_ipaddr_string(ndo, (const u_char *)(p))
126ee67461eSJoseph Mingrone #define GET_IP6ADDR_STRING(p) get_ip6addr_string(ndo, (const u_char *)(p))
127