1 /* $Id: inet_ntoa.c 5049 2001-12-12 09:06:00Z rra $
3 ** Replacement for a missing or broken inet_ntoa.
5 ** Written by Russ Allbery <rra@stanford.edu>
6 ** This work is hereby placed in the public domain by its author.
8 ** Provides the same functionality as the standard library routine
9 ** inet_ntoa for those platforms that don't have it or where it doesn't
10 ** work right (such as on IRIX when using gcc to compile). inet_ntoa is
11 ** not thread-safe since it uses static storage (inet_ntop should be used
12 ** instead when available).
17 #include <netinet/in.h>
19 /* If we're running the test suite, rename inet_ntoa to avoid conflicts with
20 the system version. */
22 # define inet_ntoa test_inet_ntoa
23 const char *test_inet_ntoa(const struct in_addr);
27 inet_ntoa(const struct in_addr in)
30 const unsigned char *p;
32 p = (const unsigned char *) &in.s_addr;
33 sprintf(buf, "%u.%u.%u.%u",
34 (unsigned int) (p[0] & 0xff), (unsigned int) (p[1] & 0xff),
35 (unsigned int) (p[2] & 0xff), (unsigned int) (p[3] & 0xff));