xref: /aosp_15_r20/external/tcpdump/addrtoname.h (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*
2*05b00f60SXin Li  * Copyright (c) 1990, 1992, 1993, 1994, 1995, 1996, 1997
3*05b00f60SXin Li  *	The Regents of the University of California.  All rights reserved.
4*05b00f60SXin Li  *
5*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li  * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li  * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li  * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li  * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li  * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li  * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li  * ``This product includes software developed by the University of California,
13*05b00f60SXin Li  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li  * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li  * or promote products derived from this software without specific prior
16*05b00f60SXin Li  * written permission.
17*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li  */
21*05b00f60SXin Li 
22*05b00f60SXin Li #include "extract.h"
23*05b00f60SXin Li 
24*05b00f60SXin Li #ifdef HAVE_CASPER
25*05b00f60SXin Li #include <libcasper.h>
26*05b00f60SXin Li extern cap_channel_t *capdns;
27*05b00f60SXin Li #endif
28*05b00f60SXin Li 
29*05b00f60SXin Li /*
30*05b00f60SXin Li  * Definition to let us compile most of the IPv6 code even on systems
31*05b00f60SXin Li  * without IPv6 support.
32*05b00f60SXin Li  */
33*05b00f60SXin Li #ifndef INET6_ADDRSTRLEN
34*05b00f60SXin Li #define INET6_ADDRSTRLEN	46
35*05b00f60SXin Li #endif
36*05b00f60SXin Li 
37*05b00f60SXin Li /* Name to address translation routines. */
38*05b00f60SXin Li 
39*05b00f60SXin Li enum {
40*05b00f60SXin Li     LINKADDR_ETHER,
41*05b00f60SXin Li     LINKADDR_FRELAY,
42*05b00f60SXin Li     LINKADDR_IEEE1394,
43*05b00f60SXin Li     LINKADDR_ATM,
44*05b00f60SXin Li     LINKADDR_OTHER
45*05b00f60SXin Li };
46*05b00f60SXin Li 
47*05b00f60SXin Li #define BUFSIZE 128
48*05b00f60SXin Li 
49*05b00f60SXin Li extern const char *linkaddr_string(netdissect_options *, const uint8_t *, const unsigned int, const unsigned int);
50*05b00f60SXin Li extern const char *etheraddr_string(netdissect_options *, const uint8_t *);
51*05b00f60SXin Li extern const char *le64addr_string(netdissect_options *, const uint8_t *);
52*05b00f60SXin Li extern const char *tcpport_string(netdissect_options *, u_short);
53*05b00f60SXin Li extern const char *udpport_string(netdissect_options *, u_short);
54*05b00f60SXin Li extern const char *isonsap_string(netdissect_options *, const uint8_t *, u_int);
55*05b00f60SXin Li extern const char *dnaddr_string(netdissect_options *, u_short);
56*05b00f60SXin Li extern const char *ipxsap_string(netdissect_options *, u_short);
57*05b00f60SXin Li extern const char *ipaddr_string(netdissect_options *, const u_char *);
58*05b00f60SXin Li extern const char *ip6addr_string(netdissect_options *, const u_char *);
59*05b00f60SXin Li extern const char *intoa(uint32_t);
60*05b00f60SXin Li 
61*05b00f60SXin Li extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
62*05b00f60SXin Li extern struct hnamemem *newhnamemem(netdissect_options *);
63*05b00f60SXin Li extern struct h6namemem *newh6namemem(netdissect_options *);
64*05b00f60SXin Li extern const char * ieee8021q_tci_string(const uint16_t);
65*05b00f60SXin Li 
66*05b00f60SXin Li /* macro(s) and inline function(s) with setjmp/longjmp logic to call
67*05b00f60SXin Li  * the X_string() function(s) after bounds checking.
68*05b00f60SXin Li  * The macro(s) must be used on a packet buffer pointer.
69*05b00f60SXin Li  */
70*05b00f60SXin Li 
71*05b00f60SXin Li static inline const char *
get_linkaddr_string(netdissect_options * ndo,const uint8_t * p,const unsigned int type,const unsigned int len)72*05b00f60SXin Li get_linkaddr_string(netdissect_options *ndo, const uint8_t *p,
73*05b00f60SXin Li     const unsigned int type, const unsigned int len)
74*05b00f60SXin Li {
75*05b00f60SXin Li         if (!ND_TTEST_LEN(p, len))
76*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
77*05b00f60SXin Li         return linkaddr_string(ndo, p, type, len);
78*05b00f60SXin Li }
79*05b00f60SXin Li 
80*05b00f60SXin Li static inline const char *
get_etheraddr_string(netdissect_options * ndo,const uint8_t * p)81*05b00f60SXin Li get_etheraddr_string(netdissect_options *ndo, const uint8_t *p)
82*05b00f60SXin Li {
83*05b00f60SXin Li         if (!ND_TTEST_LEN(p, MAC_ADDR_LEN))
84*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
85*05b00f60SXin Li         return etheraddr_string(ndo, p);
86*05b00f60SXin Li }
87*05b00f60SXin Li 
88*05b00f60SXin Li static inline const char *
get_le64addr_string(netdissect_options * ndo,const u_char * p)89*05b00f60SXin Li get_le64addr_string(netdissect_options *ndo, const u_char *p)
90*05b00f60SXin Li {
91*05b00f60SXin Li         if (!ND_TTEST_8(p))
92*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
93*05b00f60SXin Li         return le64addr_string(ndo, p);
94*05b00f60SXin Li }
95*05b00f60SXin Li 
96*05b00f60SXin Li static inline const char *
get_isonsap_string(netdissect_options * ndo,const uint8_t * nsap,u_int nsap_length)97*05b00f60SXin Li get_isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
98*05b00f60SXin Li     u_int nsap_length)
99*05b00f60SXin Li {
100*05b00f60SXin Li 	if (!ND_TTEST_LEN(nsap, nsap_length))
101*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
102*05b00f60SXin Li         return isonsap_string(ndo, nsap, nsap_length);
103*05b00f60SXin Li }
104*05b00f60SXin Li 
105*05b00f60SXin Li static inline const char *
get_ipaddr_string(netdissect_options * ndo,const u_char * p)106*05b00f60SXin Li get_ipaddr_string(netdissect_options *ndo, const u_char *p)
107*05b00f60SXin Li {
108*05b00f60SXin Li         if (!ND_TTEST_4(p))
109*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
110*05b00f60SXin Li         return ipaddr_string(ndo, p);
111*05b00f60SXin Li }
112*05b00f60SXin Li 
113*05b00f60SXin Li static inline const char *
get_ip6addr_string(netdissect_options * ndo,const u_char * p)114*05b00f60SXin Li get_ip6addr_string(netdissect_options *ndo, const u_char *p)
115*05b00f60SXin Li {
116*05b00f60SXin Li         if (!ND_TTEST_16(p))
117*05b00f60SXin Li                 nd_trunc_longjmp(ndo);
118*05b00f60SXin Li         return ip6addr_string(ndo, p);
119*05b00f60SXin Li }
120*05b00f60SXin Li 
121*05b00f60SXin Li #define GET_LINKADDR_STRING(p, type, len) get_linkaddr_string(ndo, (const u_char *)(p), type, len)
122*05b00f60SXin Li #define GET_ETHERADDR_STRING(p) get_etheraddr_string(ndo, (const u_char *)(p))
123*05b00f60SXin Li #define GET_LE64ADDR_STRING(p) get_le64addr_string(ndo, (const u_char *)(p))
124*05b00f60SXin Li #define GET_ISONSAP_STRING(nsap, nsap_length) get_isonsap_string(ndo, (const u_char *)(nsap), nsap_length)
125*05b00f60SXin Li #define GET_IPADDR_STRING(p) get_ipaddr_string(ndo, (const u_char *)(p))
126*05b00f60SXin Li #define GET_IP6ADDR_STRING(p) get_ip6addr_string(ndo, (const u_char *)(p))
127