source: web/old/remctl-2.14/portable/inet_ntoa.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * Replacement for a missing or broken inet_ntoa.
3 *
4 * Provides the same functionality as the standard library routine inet_ntoa
5 * for those platforms that don't have it or where it doesn't work right (such
6 * as on IRIX when using gcc to compile).  inet_ntoa is not thread-safe since
7 * it uses static storage (inet_ntop should be used instead when available).
8 *
9 * Written by Russ Allbery <rra@stanford.edu>
10 * This work is hereby placed in the public domain by its author.
11 */
12
13#include <config.h>
14#include <portable/system.h>
15#include <portable/socket.h>
16
17/*
18 * If we're running the test suite, rename inet_ntoa to avoid conflicts with
19 * the system version.
20 */
21#if TESTING
22# define inet_ntoa test_inet_ntoa
23const char *test_inet_ntoa(const struct in_addr);
24#endif
25
26const char *
27inet_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}
Note: See TracBrowser for help on using the repository browser.