]>
git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/getnameinfo_link.c
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * Copyright (c) 2000 Ben Harris.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <net/if_types.h>
35 #include <net/if_dl.h>
38 hexname(const uint8_t *cp
, size_t len
, char *host
, size_t hostlen
)
44 for (i
= 0; i
< len
; i
++)
46 n
= snprintf(outp
, hostlen
, "%s%02x", i
? ":" : "", cp
[i
]);
47 if ((n
< 0) || (n
>= hostlen
))
62 * Format a link-layer address into a printable format, paying attention to
65 __private_extern__
int
66 getnameinfo_link(const struct sockaddr
*sa
, socklen_t salen
, char *host
, size_t hostlen
, char *serv
, size_t servlen
, int flags
)
68 const struct sockaddr_dl
*sdl
= (const struct sockaddr_dl
*)(const void *)sa
;
71 if (serv
!= NULL
&& servlen
> 0) *serv
= '\0';
73 if ((sdl
->sdl_nlen
== 0) && (sdl
->sdl_alen
== 0) && (sdl
->sdl_slen
== 0))
75 n
= snprintf(host
, hostlen
, "link#%d", sdl
->sdl_index
);
85 switch (sdl
->sdl_type
)
88 * The following have zero-length addresses.
89 * IFT_ATM (net/if_atmsubr.c)
90 * IFT_FAITH (net/if_faith.c)
91 * IFT_GIF (net/if_gif.c)
92 * IFT_LOOP (net/if_loop.c)
93 * IFT_PPP (net/if_ppp.c, net/if_spppsubr.c)
94 * IFT_SLIP (net/if_sl.c, net/if_strip.c)
95 * IFT_STF (net/if_stf.c)
96 * IFT_L2VLAN (net/if_vlan.c)
97 * IFT_BRIDGE (net/if_bridge.h>
100 * The following use IPv4 addresses as link-layer addresses:
101 * IFT_OTHER (net/if_gre.c)
102 * IFT_OTHER (netinet/ip_ipip.c)
104 /* default below is believed correct for all these. */
111 return hexname((uint8_t *)LLADDR(sdl
), (size_t)sdl
->sdl_alen
, host
, hostlen
);