2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * Copyright (c) 1996 by Internet Software Consortium. 2N/A * Permission to use, copy, modify, and distribute this software for any 2N/A * purpose with or without fee is hereby granted, provided that the above 2N/A * copyright notice and this permission notice appear in all copies. 2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 2N/A * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 2N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 2N/A * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 2N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 2N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 2N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * inet_ntop(af, src, dst, size) 2N/A * convert a network format address to presentation format. 2N/A * pointer to presentation format address (`dst'), or NULL (see errno). 2N/A * inet_ntop4(src, dst, size) 2N/A * format an IPv4 address, more or less like inet_ntoa() 2N/A * `dst' (as a const) 2N/A * (1) uses no statics 2N/A * (2) takes a uchar_t* not an in_addr as input 2N/A static const char fmt[] =
"%u.%u.%u.%u";
2N/A char tmp[
sizeof (
"255.255.255.255")];
2N/A * inet_ntop6(src, dst, size) 2N/A * convert IPv6 binary address into presentation (printable) format 2N/A * Note that int32_t and int16_t need only be "at least" large enough 2N/A * to contain a value of the specified size. On some systems, like 2N/A * Crays, there is no such thing as an integer variable with 16 bits. 2N/A * Keep this in mind if you think this function should have been coded 2N/A * to use pointer overlays. All the world's not a VAX. 2N/A char tmp[
sizeof (
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *
tp;
2N/A * Copy the input (bytewise) array into a wordwise array. 2N/A * Find the longest run of 0x00's in src[] for :: shorthanding. 2N/A * Format the result. 2N/A /* Are we inside the best run of 0x00's? */ 2N/A /* Are we following an initial run of 0x00s or any real hex? */ 2N/A /* Is this address an encapsulated IPv4? */ 2N/A /* Was it a trailing run of 0x00's? */ 2N/A * Check for overflow, copy, and we're done.