inet.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Utility functions which help with address and hostname manipulation in a
* mixed IPv4 / IPv6 environment.
*/
#include "config.h"
#include <netdb.h>
#include <string.h>
#include "proto.h"
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
/* Converts a hostname into an IP address in presentation form */
{
#ifdef INET6
static char abuf[INET6_ADDRSTRLEN];
if (addr)
sizeof(abuf));
return str;
}
#else
}
#endif
return NULL;
}
/*
* Converts a socket structures IP address into presentation form.
* Note: returns a pointer to a buffer which is overwritten on each call.
*/
{
#ifdef INET6
static char abuf[INET6_ADDRSTRLEN];
#endif
}
char *wu_gethostbyname(const char *hostname)
{
#ifdef INET6
static char hostbuf[MAXHOSTNAMELEN];
return hostbuf;
}
#else
if (hp)
#endif
return NULL;
}
{
#ifdef INET6
char hostbuf[NI_MAXHOST];
#else
#endif
return 0;
#ifdef INET6
return 1;
}
#else
if (hp) {
return 1;
}
#endif
return 0;
}
/* Compares a socket structures IP address with addr, returning 0 on a match */
#ifdef INET6
/* compare the IPv4 part of an IPv4-mapped IPv6 address */
}
return 1;
}
#endif
}
#ifdef INET6
/* Sets a socket structures IP address to addr */
return;
}
}
/* Compares two socket structure IP addresses, returning 0 if they match */
sizeof(struct in6_addr));
}
}
#ifdef HAVE_SIN6_SCOPE_ID
sizeof(struct in6_addr)) == 0))
else
dst_in6->sin6_scope_id = 0;
}
#endif
}
/*
* Similar to inet_pton(), str can be an IPv4 or IPv6 address, but an IPv6
* address is returned in addr.
*/
{
/* Try v6 first */
/* If that fails, try v4 and map it */
}
else
return 0;
}
return 1;
}
/*
* Similar to inet_ntop(), except when addr is an IPv4-mapped IPv6 address
* returns a printable IPv4 address (not an IPv4-mapped IPv6 address).
*/
{
const char *result;
else
}
else
return result;
}
#endif /* INET6 */