1*5f4c09ddSEd Maste /* $NetBSD: sockaddr_snprintf.c,v 1.11 2016/06/01 22:57:51 christos Exp $ */
2*5f4c09ddSEd Maste
3*5f4c09ddSEd Maste /*-
4*5f4c09ddSEd Maste * Copyright (c) 2004 The NetBSD Foundation, Inc.
5*5f4c09ddSEd Maste * All rights reserved.
6*5f4c09ddSEd Maste *
7*5f4c09ddSEd Maste * This code is derived from software contributed to The NetBSD Foundation
8*5f4c09ddSEd Maste * by Christos Zoulas.
9*5f4c09ddSEd Maste *
10*5f4c09ddSEd Maste * Redistribution and use in source and binary forms, with or without
11*5f4c09ddSEd Maste * modification, are permitted provided that the following conditions
12*5f4c09ddSEd Maste * are met:
13*5f4c09ddSEd Maste * 1. Redistributions of source code must retain the above copyright
14*5f4c09ddSEd Maste * notice, this list of conditions and the following disclaimer.
15*5f4c09ddSEd Maste * 2. Redistributions in binary form must reproduce the above copyright
16*5f4c09ddSEd Maste * notice, this list of conditions and the following disclaimer in the
17*5f4c09ddSEd Maste * documentation and/or other materials provided with the distribution.
18*5f4c09ddSEd Maste *
19*5f4c09ddSEd Maste * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*5f4c09ddSEd Maste * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*5f4c09ddSEd Maste * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*5f4c09ddSEd Maste * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*5f4c09ddSEd Maste * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*5f4c09ddSEd Maste * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*5f4c09ddSEd Maste * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*5f4c09ddSEd Maste * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*5f4c09ddSEd Maste * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*5f4c09ddSEd Maste * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*5f4c09ddSEd Maste * POSSIBILITY OF SUCH DAMAGE.
30*5f4c09ddSEd Maste */
31*5f4c09ddSEd Maste #ifdef HAVE_CONFIG_H
32*5f4c09ddSEd Maste #include "config.h"
33*5f4c09ddSEd Maste #endif
34*5f4c09ddSEd Maste
35*5f4c09ddSEd Maste #include <sys/cdefs.h>
36*5f4c09ddSEd Maste #if defined(LIBC_SCCS) && !defined(lint)
37*5f4c09ddSEd Maste __RCSID("$NetBSD: sockaddr_snprintf.c,v 1.11 2016/06/01 22:57:51 christos Exp $");
38*5f4c09ddSEd Maste #endif /* LIBC_SCCS and not lint */
39*5f4c09ddSEd Maste
40*5f4c09ddSEd Maste #include <sys/param.h>
41*5f4c09ddSEd Maste #include <sys/types.h>
42*5f4c09ddSEd Maste #include <sys/socket.h>
43*5f4c09ddSEd Maste #include <sys/un.h>
44*5f4c09ddSEd Maste
45*5f4c09ddSEd Maste #include <netinet/in.h>
46*5f4c09ddSEd Maste #ifdef __linux__
47*5f4c09ddSEd Maste #undef HAVE_NETATALK_AT_H
48*5f4c09ddSEd Maste #endif
49*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
50*5f4c09ddSEd Maste #include <netatalk/at.h>
51*5f4c09ddSEd Maste #endif
52*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
53*5f4c09ddSEd Maste #include <net/if_dl.h>
54*5f4c09ddSEd Maste #endif
55*5f4c09ddSEd Maste
56*5f4c09ddSEd Maste #include <stdio.h>
57*5f4c09ddSEd Maste #include <string.h>
58*5f4c09ddSEd Maste #include <errno.h>
59*5f4c09ddSEd Maste #include <stdlib.h>
60*5f4c09ddSEd Maste #ifdef HAVE_LIBUTIL_H
61*5f4c09ddSEd Maste #include <libutil.h>
62*5f4c09ddSEd Maste #endif
63*5f4c09ddSEd Maste #ifdef HAVE_UTIL_H
64*5f4c09ddSEd Maste #include <util.h>
65*5f4c09ddSEd Maste #endif
66*5f4c09ddSEd Maste #include <netdb.h>
67*5f4c09ddSEd Maste
68*5f4c09ddSEd Maste #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
69*5f4c09ddSEd Maste #define SLEN(a) (a)->a ## _len
70*5f4c09ddSEd Maste #else
71*5f4c09ddSEd Maste static socklen_t
socklen(u_int af)72*5f4c09ddSEd Maste socklen(u_int af)
73*5f4c09ddSEd Maste {
74*5f4c09ddSEd Maste switch (af) {
75*5f4c09ddSEd Maste case AF_INET:
76*5f4c09ddSEd Maste return sizeof(struct sockaddr_in);
77*5f4c09ddSEd Maste case AF_INET6:
78*5f4c09ddSEd Maste return sizeof(struct sockaddr_in6);
79*5f4c09ddSEd Maste case AF_LOCAL:
80*5f4c09ddSEd Maste return sizeof(struct sockaddr_un);
81*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
82*5f4c09ddSEd Maste case AF_LINK:
83*5f4c09ddSEd Maste return sizeof(struct sockaddr_dl);
84*5f4c09ddSEd Maste #endif
85*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
86*5f4c09ddSEd Maste case AF_APPLETALK:
87*5f4c09ddSEd Maste return sizeof(struct sockaddr_at);
88*5f4c09ddSEd Maste #endif
89*5f4c09ddSEd Maste default:
90*5f4c09ddSEd Maste return sizeof(struct sockaddr_storage);
91*5f4c09ddSEd Maste }
92*5f4c09ddSEd Maste }
93*5f4c09ddSEd Maste
94*5f4c09ddSEd Maste #define SLEN(a) socklen((a)->a ## _family)
95*5f4c09ddSEd Maste #endif
96*5f4c09ddSEd Maste
97*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
98*5f4c09ddSEd Maste static int
debug_at(char * str,size_t len,const struct sockaddr_at * sat)99*5f4c09ddSEd Maste debug_at(char *str, size_t len, const struct sockaddr_at *sat)
100*5f4c09ddSEd Maste {
101*5f4c09ddSEd Maste return snprintf(str, len, "sat_len=%u, sat_family=%u, sat_port=%u, "
102*5f4c09ddSEd Maste "sat_addr.s_net=%u, sat_addr.s_node=%u, "
103*5f4c09ddSEd Maste "sat_range.r_netrange.nr_phase=%u, "
104*5f4c09ddSEd Maste "sat_range.r_netrange.nr_firstnet=%u, "
105*5f4c09ddSEd Maste "sat_range.r_netrange.nr_lastnet=%u",
106*5f4c09ddSEd Maste SLEN(sat), sat->sat_family, sat->sat_port,
107*5f4c09ddSEd Maste sat->sat_addr.s_net, sat->sat_addr.s_node,
108*5f4c09ddSEd Maste sat->sat_range.r_netrange.nr_phase,
109*5f4c09ddSEd Maste sat->sat_range.r_netrange.nr_firstnet,
110*5f4c09ddSEd Maste sat->sat_range.r_netrange.nr_lastnet);
111*5f4c09ddSEd Maste }
112*5f4c09ddSEd Maste #endif
113*5f4c09ddSEd Maste
114*5f4c09ddSEd Maste static int
debug_in(char * str,size_t len,const struct sockaddr_in * sin)115*5f4c09ddSEd Maste debug_in(char *str, size_t len, const struct sockaddr_in *sin)
116*5f4c09ddSEd Maste {
117*5f4c09ddSEd Maste return snprintf(str, len, "sin_len=%u, sin_family=%u, sin_port=%u, "
118*5f4c09ddSEd Maste "sin_addr.s_addr=%08x",
119*5f4c09ddSEd Maste SLEN(sin), sin->sin_family, sin->sin_port,
120*5f4c09ddSEd Maste sin->sin_addr.s_addr);
121*5f4c09ddSEd Maste }
122*5f4c09ddSEd Maste
123*5f4c09ddSEd Maste static int
debug_in6(char * str,size_t len,const struct sockaddr_in6 * sin6)124*5f4c09ddSEd Maste debug_in6(char *str, size_t len, const struct sockaddr_in6 *sin6)
125*5f4c09ddSEd Maste {
126*5f4c09ddSEd Maste const uint8_t *s = sin6->sin6_addr.s6_addr;
127*5f4c09ddSEd Maste
128*5f4c09ddSEd Maste return snprintf(str, len, "sin6_len=%u, sin6_family=%u, sin6_port=%u, "
129*5f4c09ddSEd Maste "sin6_flowinfo=%u, "
130*5f4c09ddSEd Maste "sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:"
131*5f4c09ddSEd Maste "%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u",
132*5f4c09ddSEd Maste SLEN(sin6), sin6->sin6_family, sin6->sin6_port,
133*5f4c09ddSEd Maste sin6->sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
134*5f4c09ddSEd Maste s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd],
135*5f4c09ddSEd Maste s[0xe], s[0xf], sin6->sin6_scope_id);
136*5f4c09ddSEd Maste }
137*5f4c09ddSEd Maste
138*5f4c09ddSEd Maste static int
debug_un(char * str,size_t len,const struct sockaddr_un * sun)139*5f4c09ddSEd Maste debug_un(char *str, size_t len, const struct sockaddr_un *sun)
140*5f4c09ddSEd Maste {
141*5f4c09ddSEd Maste return snprintf(str, len, "sun_len=%u, sun_family=%u, sun_path=%*s",
142*5f4c09ddSEd Maste SLEN(sun), sun->sun_family, (int)sizeof(sun->sun_path),
143*5f4c09ddSEd Maste sun->sun_path);
144*5f4c09ddSEd Maste }
145*5f4c09ddSEd Maste
146*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
147*5f4c09ddSEd Maste static int
debug_dl(char * str,size_t len,const struct sockaddr_dl * sdl)148*5f4c09ddSEd Maste debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl)
149*5f4c09ddSEd Maste {
150*5f4c09ddSEd Maste const uint8_t *s = (const void *)sdl->sdl_data;
151*5f4c09ddSEd Maste
152*5f4c09ddSEd Maste return snprintf(str, len, "sdl_len=%u, sdl_family=%u, sdl_index=%u, "
153*5f4c09ddSEd Maste "sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data="
154*5f4c09ddSEd Maste "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
155*5f4c09ddSEd Maste SLEN(sdl), sdl->sdl_family, sdl->sdl_index,
156*5f4c09ddSEd Maste sdl->sdl_type, sdl->sdl_nlen, sdl->sdl_alen, sdl->sdl_slen,
157*5f4c09ddSEd Maste s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
158*5f4c09ddSEd Maste s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb]);
159*5f4c09ddSEd Maste }
160*5f4c09ddSEd Maste #endif
161*5f4c09ddSEd Maste
162*5f4c09ddSEd Maste int
sockaddr_snprintf(char * const sbuf,const size_t len,const char * const fmt,const struct sockaddr * const sa)163*5f4c09ddSEd Maste sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
164*5f4c09ddSEd Maste const struct sockaddr * const sa)
165*5f4c09ddSEd Maste {
166*5f4c09ddSEd Maste const void *a = NULL;
167*5f4c09ddSEd Maste char abuf[1024], nbuf[1024], *addr = NULL;
168*5f4c09ddSEd Maste
169*5f4c09ddSEd Maste char Abuf[1024], pbuf[32], *name = NULL, *port = NULL;
170*5f4c09ddSEd Maste char *ebuf = &sbuf[len - 1], *buf = sbuf;
171*5f4c09ddSEd Maste const char *ptr, *s;
172*5f4c09ddSEd Maste int p = -1;
173*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
174*5f4c09ddSEd Maste const struct sockaddr_at *sat = NULL;
175*5f4c09ddSEd Maste #endif
176*5f4c09ddSEd Maste const struct sockaddr_in *sin4 = NULL;
177*5f4c09ddSEd Maste const struct sockaddr_in6 *sin6 = NULL;
178*5f4c09ddSEd Maste const struct sockaddr_un *sun = NULL;
179*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
180*5f4c09ddSEd Maste const struct sockaddr_dl *sdl = NULL;
181*5f4c09ddSEd Maste char *w = NULL;
182*5f4c09ddSEd Maste #endif
183*5f4c09ddSEd Maste int na = 1;
184*5f4c09ddSEd Maste
185*5f4c09ddSEd Maste #define ADDC(c) do { if (buf < ebuf) *buf++ = c; else buf++; } \
186*5f4c09ddSEd Maste while (/*CONSTCOND*/0)
187*5f4c09ddSEd Maste #define ADDS(p) do { for (s = p; *s; s++) ADDC(*s); } \
188*5f4c09ddSEd Maste while (/*CONSTCOND*/0)
189*5f4c09ddSEd Maste #define ADDNA() do { if (na) ADDS("N/A"); } \
190*5f4c09ddSEd Maste while (/*CONSTCOND*/0)
191*5f4c09ddSEd Maste
192*5f4c09ddSEd Maste switch (sa->sa_family) {
193*5f4c09ddSEd Maste case AF_UNSPEC:
194*5f4c09ddSEd Maste goto done;
195*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
196*5f4c09ddSEd Maste case AF_APPLETALK:
197*5f4c09ddSEd Maste sat = ((const struct sockaddr_at *)(const void *)sa);
198*5f4c09ddSEd Maste p = ntohs(sat->sat_port);
199*5f4c09ddSEd Maste (void)snprintf(addr = abuf, sizeof(abuf), "%u.%u",
200*5f4c09ddSEd Maste ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node);
201*5f4c09ddSEd Maste (void)snprintf(port = pbuf, sizeof(pbuf), "%d", p);
202*5f4c09ddSEd Maste break;
203*5f4c09ddSEd Maste #endif
204*5f4c09ddSEd Maste case AF_LOCAL:
205*5f4c09ddSEd Maste sun = ((const struct sockaddr_un *)(const void *)sa);
206*5f4c09ddSEd Maste (void)strlcpy(addr = abuf, sun->sun_path, sizeof(abuf));
207*5f4c09ddSEd Maste break;
208*5f4c09ddSEd Maste case AF_INET:
209*5f4c09ddSEd Maste sin4 = ((const struct sockaddr_in *)(const void *)sa);
210*5f4c09ddSEd Maste p = ntohs(sin4->sin_port);
211*5f4c09ddSEd Maste a = &sin4->sin_addr;
212*5f4c09ddSEd Maste break;
213*5f4c09ddSEd Maste case AF_INET6:
214*5f4c09ddSEd Maste sin6 = ((const struct sockaddr_in6 *)(const void *)sa);
215*5f4c09ddSEd Maste p = ntohs(sin6->sin6_port);
216*5f4c09ddSEd Maste a = &sin6->sin6_addr;
217*5f4c09ddSEd Maste break;
218*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
219*5f4c09ddSEd Maste case AF_LINK:
220*5f4c09ddSEd Maste sdl = ((const struct sockaddr_dl *)(const void *)sa);
221*5f4c09ddSEd Maste (void)strlcpy(addr = abuf, link_ntoa(sdl), sizeof(abuf));
222*5f4c09ddSEd Maste if ((w = strchr(addr, ':')) != NULL) {
223*5f4c09ddSEd Maste *w++ = '\0';
224*5f4c09ddSEd Maste addr = w;
225*5f4c09ddSEd Maste }
226*5f4c09ddSEd Maste break;
227*5f4c09ddSEd Maste #endif
228*5f4c09ddSEd Maste default:
229*5f4c09ddSEd Maste errno = EAFNOSUPPORT;
230*5f4c09ddSEd Maste return -1;
231*5f4c09ddSEd Maste }
232*5f4c09ddSEd Maste
233*5f4c09ddSEd Maste if (addr == abuf)
234*5f4c09ddSEd Maste name = addr;
235*5f4c09ddSEd Maste
236*5f4c09ddSEd Maste if (a && getnameinfo(sa, (socklen_t)SLEN(sa), addr = abuf,
237*5f4c09ddSEd Maste (unsigned int)sizeof(abuf), NULL, 0,
238*5f4c09ddSEd Maste NI_NUMERICHOST|NI_NUMERICSERV) != 0)
239*5f4c09ddSEd Maste return -1;
240*5f4c09ddSEd Maste
241*5f4c09ddSEd Maste for (ptr = fmt; *ptr; ptr++) {
242*5f4c09ddSEd Maste if (*ptr != '%') {
243*5f4c09ddSEd Maste ADDC(*ptr);
244*5f4c09ddSEd Maste continue;
245*5f4c09ddSEd Maste }
246*5f4c09ddSEd Maste next_char:
247*5f4c09ddSEd Maste switch (*++ptr) {
248*5f4c09ddSEd Maste case '?':
249*5f4c09ddSEd Maste na = 0;
250*5f4c09ddSEd Maste goto next_char;
251*5f4c09ddSEd Maste case 'a':
252*5f4c09ddSEd Maste ADDS(addr);
253*5f4c09ddSEd Maste break;
254*5f4c09ddSEd Maste case 'p':
255*5f4c09ddSEd Maste if (p != -1) {
256*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf), "%d", p);
257*5f4c09ddSEd Maste ADDS(nbuf);
258*5f4c09ddSEd Maste } else
259*5f4c09ddSEd Maste ADDNA();
260*5f4c09ddSEd Maste break;
261*5f4c09ddSEd Maste case 'f':
262*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf), "%d", sa->sa_family);
263*5f4c09ddSEd Maste ADDS(nbuf);
264*5f4c09ddSEd Maste break;
265*5f4c09ddSEd Maste case 'l':
266*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf), "%d", SLEN(sa));
267*5f4c09ddSEd Maste ADDS(nbuf);
268*5f4c09ddSEd Maste break;
269*5f4c09ddSEd Maste case 'A':
270*5f4c09ddSEd Maste if (name)
271*5f4c09ddSEd Maste ADDS(name);
272*5f4c09ddSEd Maste else if (!a)
273*5f4c09ddSEd Maste ADDNA();
274*5f4c09ddSEd Maste else {
275*5f4c09ddSEd Maste getnameinfo(sa, (socklen_t)SLEN(sa),
276*5f4c09ddSEd Maste name = Abuf,
277*5f4c09ddSEd Maste (unsigned int)sizeof(nbuf), NULL, 0, 0);
278*5f4c09ddSEd Maste ADDS(name);
279*5f4c09ddSEd Maste }
280*5f4c09ddSEd Maste break;
281*5f4c09ddSEd Maste case 'P':
282*5f4c09ddSEd Maste if (port)
283*5f4c09ddSEd Maste ADDS(port);
284*5f4c09ddSEd Maste else if (p == -1)
285*5f4c09ddSEd Maste ADDNA();
286*5f4c09ddSEd Maste else {
287*5f4c09ddSEd Maste getnameinfo(sa, (socklen_t)SLEN(sa), NULL, 0,
288*5f4c09ddSEd Maste port = pbuf,
289*5f4c09ddSEd Maste (unsigned int)sizeof(pbuf), 0);
290*5f4c09ddSEd Maste ADDS(port);
291*5f4c09ddSEd Maste }
292*5f4c09ddSEd Maste break;
293*5f4c09ddSEd Maste case 'I':
294*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
295*5f4c09ddSEd Maste if (sdl && addr != abuf) {
296*5f4c09ddSEd Maste ADDS(abuf);
297*5f4c09ddSEd Maste } else
298*5f4c09ddSEd Maste #endif
299*5f4c09ddSEd Maste {
300*5f4c09ddSEd Maste ADDNA();
301*5f4c09ddSEd Maste }
302*5f4c09ddSEd Maste break;
303*5f4c09ddSEd Maste case 'F':
304*5f4c09ddSEd Maste if (sin6) {
305*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf), "%d",
306*5f4c09ddSEd Maste sin6->sin6_flowinfo);
307*5f4c09ddSEd Maste ADDS(nbuf);
308*5f4c09ddSEd Maste break;
309*5f4c09ddSEd Maste } else {
310*5f4c09ddSEd Maste ADDNA();
311*5f4c09ddSEd Maste }
312*5f4c09ddSEd Maste break;
313*5f4c09ddSEd Maste case 'S':
314*5f4c09ddSEd Maste if (sin6) {
315*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf), "%d",
316*5f4c09ddSEd Maste sin6->sin6_scope_id);
317*5f4c09ddSEd Maste ADDS(nbuf);
318*5f4c09ddSEd Maste break;
319*5f4c09ddSEd Maste } else {
320*5f4c09ddSEd Maste ADDNA();
321*5f4c09ddSEd Maste }
322*5f4c09ddSEd Maste break;
323*5f4c09ddSEd Maste case 'R':
324*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
325*5f4c09ddSEd Maste if (sat) {
326*5f4c09ddSEd Maste const struct netrange *n =
327*5f4c09ddSEd Maste &sat->sat_range.r_netrange;
328*5f4c09ddSEd Maste (void)snprintf(nbuf, sizeof(nbuf),
329*5f4c09ddSEd Maste "%d:[%d,%d]", n->nr_phase , n->nr_firstnet,
330*5f4c09ddSEd Maste n->nr_lastnet);
331*5f4c09ddSEd Maste ADDS(nbuf);
332*5f4c09ddSEd Maste } else
333*5f4c09ddSEd Maste #endif
334*5f4c09ddSEd Maste {
335*5f4c09ddSEd Maste ADDNA();
336*5f4c09ddSEd Maste }
337*5f4c09ddSEd Maste break;
338*5f4c09ddSEd Maste case 'D':
339*5f4c09ddSEd Maste switch (sa->sa_family) {
340*5f4c09ddSEd Maste #ifdef HAVE_NETATALK_AT_H
341*5f4c09ddSEd Maste case AF_APPLETALK:
342*5f4c09ddSEd Maste debug_at(nbuf, sizeof(nbuf), sat);
343*5f4c09ddSEd Maste break;
344*5f4c09ddSEd Maste #endif
345*5f4c09ddSEd Maste case AF_LOCAL:
346*5f4c09ddSEd Maste debug_un(nbuf, sizeof(nbuf), sun);
347*5f4c09ddSEd Maste break;
348*5f4c09ddSEd Maste case AF_INET:
349*5f4c09ddSEd Maste debug_in(nbuf, sizeof(nbuf), sin4);
350*5f4c09ddSEd Maste break;
351*5f4c09ddSEd Maste case AF_INET6:
352*5f4c09ddSEd Maste debug_in6(nbuf, sizeof(nbuf), sin6);
353*5f4c09ddSEd Maste break;
354*5f4c09ddSEd Maste #ifdef HAVE_NET_IF_DL_H
355*5f4c09ddSEd Maste case AF_LINK:
356*5f4c09ddSEd Maste debug_dl(nbuf, sizeof(nbuf), sdl);
357*5f4c09ddSEd Maste break;
358*5f4c09ddSEd Maste #endif
359*5f4c09ddSEd Maste default:
360*5f4c09ddSEd Maste abort();
361*5f4c09ddSEd Maste }
362*5f4c09ddSEd Maste ADDS(nbuf);
363*5f4c09ddSEd Maste break;
364*5f4c09ddSEd Maste default:
365*5f4c09ddSEd Maste ADDC('%');
366*5f4c09ddSEd Maste if (na == 0)
367*5f4c09ddSEd Maste ADDC('?');
368*5f4c09ddSEd Maste if (*ptr == '\0')
369*5f4c09ddSEd Maste goto done;
370*5f4c09ddSEd Maste /*FALLTHROUGH*/
371*5f4c09ddSEd Maste case '%':
372*5f4c09ddSEd Maste ADDC(*ptr);
373*5f4c09ddSEd Maste break;
374*5f4c09ddSEd Maste }
375*5f4c09ddSEd Maste na = 1;
376*5f4c09ddSEd Maste }
377*5f4c09ddSEd Maste done:
378*5f4c09ddSEd Maste if (buf < ebuf)
379*5f4c09ddSEd Maste *buf = '\0';
380*5f4c09ddSEd Maste else if (len != 0)
381*5f4c09ddSEd Maste sbuf[len - 1] = '\0';
382*5f4c09ddSEd Maste return (int)(buf - sbuf);
383*5f4c09ddSEd Maste }
384