inet6_ntop.c revision 261190
1/* 2 * Copyright (c) 2013 Proofpoint, Inc. and its suppliers. 3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 * 9 */ 10 11#include <sm/gen.h> 12SM_RCSID("@(#)$Id: inet6_ntop.c,v 1.2 2013/11/22 20:51:43 ca Exp $") 13 14#if NETINET6 15# include <sm/conf.h> 16# include <sm/types.h> 17# include <sm/io.h> 18# include <sm/string.h> 19# include <netinet/in.h> 20 21/* 22** SM_INET6_NTOP -- convert IPv6 address to ASCII string (uncompressed) 23** 24** Parameters: 25** ipv6 -- IPv6 address 26** dst -- ASCII representation of address (output) 27** len -- length of dst 28** 29** Returns: 30** error: NULL 31*/ 32 33char * 34sm_inet6_ntop(ipv6, dst, len) 35 const void *ipv6; 36 char *dst; 37 size_t len; 38{ 39 SM_UINT16 *u16; 40 int r; 41 42 u16 = (SM_UINT16 *)ipv6; 43 r = sm_snprintf(dst, len, 44 "%x:%x:%x:%x:%x:%x:%x:%x" 45 , htons(u16[0]) 46 , htons(u16[1]) 47 , htons(u16[2]) 48 , htons(u16[3]) 49 , htons(u16[4]) 50 , htons(u16[5]) 51 , htons(u16[6]) 52 , htons(u16[7]) 53 ); 54 if (r > 0) 55 return dst; 56 return NULL; 57} 58#endif /* NETINET6 */ 59