1261190Sgshapiro/*
2261190Sgshapiro * Copyright (c) 2013 Proofpoint, Inc. and its suppliers.
3261190Sgshapiro *      All rights reserved.
4261190Sgshapiro *
5261190Sgshapiro * By using this file, you agree to the terms and conditions set
6261190Sgshapiro * forth in the LICENSE file which can be found at the top level of
7261190Sgshapiro * the sendmail distribution.
8261190Sgshapiro *
9261190Sgshapiro */
10261190Sgshapiro
11261190Sgshapiro#include <sm/gen.h>
12266692SgshapiroSM_RCSID("@(#)$Id: inet6_ntop.c,v 1.2 2013-11-22 20:51:43 ca Exp $")
13261190Sgshapiro
14261190Sgshapiro#if NETINET6
15261190Sgshapiro# include <sm/conf.h>
16261190Sgshapiro# include <sm/types.h>
17261190Sgshapiro# include <sm/io.h>
18261190Sgshapiro# include <sm/string.h>
19261190Sgshapiro# include <netinet/in.h>
20261190Sgshapiro
21261190Sgshapiro/*
22261190Sgshapiro**  SM_INET6_NTOP -- convert IPv6 address to ASCII string (uncompressed)
23261190Sgshapiro**
24261190Sgshapiro**	Parameters:
25261190Sgshapiro**		ipv6 -- IPv6 address
26261190Sgshapiro**		dst -- ASCII representation of address (output)
27261190Sgshapiro**		len -- length of dst
28261190Sgshapiro**
29261190Sgshapiro**	Returns:
30261190Sgshapiro**		error: NULL
31261190Sgshapiro*/
32261190Sgshapiro
33261190Sgshapirochar *
34261190Sgshapirosm_inet6_ntop(ipv6, dst, len)
35261190Sgshapiro	const void *ipv6;
36261190Sgshapiro	char *dst;
37261190Sgshapiro	size_t len;
38261190Sgshapiro{
39261190Sgshapiro	SM_UINT16 *u16;
40261190Sgshapiro	int r;
41261190Sgshapiro
42261190Sgshapiro	u16 = (SM_UINT16 *)ipv6;
43261190Sgshapiro	r = sm_snprintf(dst, len,
44261190Sgshapiro		"%x:%x:%x:%x:%x:%x:%x:%x"
45261190Sgshapiro			, htons(u16[0])
46261190Sgshapiro			, htons(u16[1])
47261190Sgshapiro			, htons(u16[2])
48261190Sgshapiro			, htons(u16[3])
49261190Sgshapiro			, htons(u16[4])
50261190Sgshapiro			, htons(u16[5])
51261190Sgshapiro			, htons(u16[6])
52261190Sgshapiro			, htons(u16[7])
53261190Sgshapiro		);
54261190Sgshapiro	if (r > 0)
55261190Sgshapiro		return dst;
56261190Sgshapiro	return NULL;
57261190Sgshapiro}
58261190Sgshapiro#endif /* NETINET6 */
59