*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.4 1999/01/01 04:17:13 momjian Exp $";
+static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.8 1999/07/17 20:17:56 momjian Exp $";
#endif
#include <arpa/inet.h>
#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <postgres.h>
-#include <utils/builtins.h>
+#include "postgres.h"
+#include "utils/builtins.h"
#ifdef SPRINTF_CHAR
#define SPRINTF(x) strlen(sprintf/**/x)
#endif
static char *inet_net_ntop_ipv4(const u_char *src, int bits,
- char *dst, size_t size);
+ char *dst, size_t size);
static char *inet_cidr_ntop_ipv4(const u_char *src, int bits,
- char *dst, size_t size);
+ char *dst, size_t size);
/*
* char *
{
switch (af)
{
- case AF_INET:
+ case AF_INET:
return (inet_cidr_ntop_ipv4(src, bits, dst, size));
default:
errno = EAFNOSUPPORT;
{
switch (af)
{
- case AF_INET:
+ case AF_INET:
return (inet_net_ntop_ipv4(src, bits, dst, size));
default:
errno = EAFNOSUPPORT;
static char *
inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
{
- char *odst = dst;
- char *t;
- size_t len = 4;
- int b, tb;
+ char *odst = dst;
+ char *t;
+ size_t len = 4;
+ int b,
+ tb;
if (bits < 0 || bits > 32)
{
/* Format whole octets plus nonzero trailing octets. */
tb = (bits == 32) ? 31 : bits;
- for (b = 0; b <= (tb / 8) || (b < len && *src != 0); b++)
+ for (b = 0; bits != 0 && (b <= (tb / 8) || (b < len && *src != 0)); b++)
{
if (size < sizeof "255.")
goto emsgsize;
*dst++ = '.';
*dst = '\0';
}
- size -= (size_t)(dst - t);
+ size -= (size_t) (dst - t);
}
/* don't print masklen if 32 bits */
return (odst);
- emsgsize:
+emsgsize:
errno = EMSGSIZE;
return (NULL);
}