inet_ntop.c revision 16a68807e13caea3183a41a5292f1b3f48b81a26
5784N/A * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 5784N/A * Copyright (C) 1996-2001 Internet Software Consortium. 5784N/A * Permission to use, copy, modify, and distribute this software for any 5784N/A * purpose with or without fee is hereby granted, provided that the above 5784N/A * copyright notice and this permission notice appear in all copies. 5784N/A * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 6982N/A * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 6982N/A * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 5784N/A * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 5784N/A * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 5784N/A * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 6982N/A * PERFORMANCE OF THIS SOFTWARE. 5784N/A#
endif /* LIBC_SCCS and not lint */ 5784N/A * WARNING: Don't even consider trying to compile this on a system where 5784N/A * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. 5784N/A * isc_net_ntop(af, src, dst, size) 5784N/A * convert a network format address to presentation format. 5784N/A * pointer to presentation format address (`dst'), or NULL (see errno). 5784N/A * inet_ntop4(src, dst, size) 5784N/A * (2) takes a unsigned char* not an in_addr as input 5784N/A * isc_inet_ntop6(src, dst, size) 5784N/A * convert IPv6 binary address into presentation (printable) format 5784N/A * Note that int32_t and int16_t need only be "at least" large enough 5784N/A * to contain a value of the specified size. On some systems, like 5784N/A * Crays, there is no such thing as an integer variable with 16 bits. 5784N/A * Keep this in mind if you think this function should have been coded 5784N/A * to use pointer overlays. All the world's not a VAX. 5784N/A char tmp[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *
tp;
5784N/A * Copy the input (bytewise) array into a wordwise array. 5784N/A * Find the longest run of 0x00's in src[] for :: shorthanding. 5784N/A /* Are we inside the best run of 0x00's? */ 5784N/A /* Are we following an initial run of 0x00s or any real hex? */ 5784N/A /* Is this address an encapsulated IPv4? */ 5784N/A /* Was it a trailing run of 0x00's? */ 5784N/A * Check for overflow, copy, and we're done.