chiark / gitweb /
Fix HOSTNAME thing in configure.in
[inn-innduct.git] / lib / inet_ntoa.c
1 /*  $Id: inet_ntoa.c 5049 2001-12-12 09:06:00Z rra $
2 **
3 **  Replacement for a missing or broken inet_ntoa.
4 **
5 **  Written by Russ Allbery <rra@stanford.edu>
6 **  This work is hereby placed in the public domain by its author.
7 **
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).
13 */
14
15 #include "config.h"
16 #include "clibrary.h"
17 #include <netinet/in.h>
18
19 /* If we're running the test suite, rename inet_ntoa to avoid conflicts with
20    the system version. */
21 #if TESTING
22 # define inet_ntoa test_inet_ntoa
23 const char *test_inet_ntoa(const struct in_addr);
24 #endif
25
26 const char *
27 inet_ntoa(const struct in_addr in)
28 {
29     static char buf[16];
30     const unsigned char *p;
31
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));
36     return buf;
37 }