libbb: hide getnetbyaddr() inside "#if ENABLE_FEATURE_ETC_NETWORKS" block
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2ed74e25d3
commit
7d7c7bb220
@ -11,6 +11,12 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include "inet_common.h"
|
#include "inet_common.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
# define dbg(...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
|
int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
|
||||||
{
|
{
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
@ -33,9 +39,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
|
|||||||
}
|
}
|
||||||
/* If we expect this to be a hostname, try hostname database first */
|
/* If we expect this to be a hostname, try hostname database first */
|
||||||
if (hostfirst) {
|
if (hostfirst) {
|
||||||
#ifdef DEBUG
|
dbg("gethostbyname(%s)", name);
|
||||||
bb_error_msg("gethostbyname(%s)", name);
|
|
||||||
#endif
|
|
||||||
hp = gethostbyname(name);
|
hp = gethostbyname(name);
|
||||||
if (hp) {
|
if (hp) {
|
||||||
memcpy(&s_in->sin_addr, hp->h_addr_list[0],
|
memcpy(&s_in->sin_addr, hp->h_addr_list[0],
|
||||||
@ -45,9 +49,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
|
|||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_ETC_NETWORKS
|
#if ENABLE_FEATURE_ETC_NETWORKS
|
||||||
/* Try the NETWORKS database to see if this is a known network. */
|
/* Try the NETWORKS database to see if this is a known network. */
|
||||||
#ifdef DEBUG
|
dbg("getnetbyname(%s)", name);
|
||||||
bb_error_msg("getnetbyname(%s)", name);
|
|
||||||
#endif
|
|
||||||
np = getnetbyname(name);
|
np = getnetbyname(name);
|
||||||
if (np) {
|
if (np) {
|
||||||
s_in->sin_addr.s_addr = htonl(np->n_net);
|
s_in->sin_addr.s_addr = htonl(np->n_net);
|
||||||
@ -61,8 +63,8 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
res_init();
|
res_init();
|
||||||
_res.options |= RES_DEBUG;
|
_res.options |= RES_DEBUG;
|
||||||
bb_error_msg("gethostbyname(%s)", name);
|
|
||||||
#endif
|
#endif
|
||||||
|
dbg("gethostbyname(%s)", name);
|
||||||
hp = gethostbyname(name);
|
hp = gethostbyname(name);
|
||||||
if (!hp) {
|
if (!hp) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -93,17 +95,12 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
|
|||||||
smallint is_host;
|
smallint is_host;
|
||||||
|
|
||||||
if (s_in->sin_family != AF_INET) {
|
if (s_in->sin_family != AF_INET) {
|
||||||
#ifdef DEBUG
|
dbg("rresolve: unsupported address family %d!", s_in->sin_family);
|
||||||
bb_error_msg("rresolve: unsupported address family %d!",
|
|
||||||
s_in->sin_family);
|
|
||||||
#endif
|
|
||||||
errno = EAFNOSUPPORT;
|
errno = EAFNOSUPPORT;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
nip = s_in->sin_addr.s_addr;
|
nip = s_in->sin_addr.s_addr;
|
||||||
#ifdef DEBUG
|
dbg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
|
||||||
bb_error_msg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
|
|
||||||
#endif
|
|
||||||
if (numeric & 0x0FFF)
|
if (numeric & 0x0FFF)
|
||||||
return xmalloc_sockaddr2dotted_noport((void*)s_in);
|
return xmalloc_sockaddr2dotted_noport((void*)s_in);
|
||||||
if (nip == INADDR_ANY) {
|
if (nip == INADDR_ANY) {
|
||||||
@ -117,10 +114,8 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
|
|||||||
pn = cache;
|
pn = cache;
|
||||||
while (pn) {
|
while (pn) {
|
||||||
if (pn->nip == nip && pn->is_host == is_host) {
|
if (pn->nip == nip && pn->is_host == is_host) {
|
||||||
#ifdef DEBUG
|
dbg("rresolve: found %s %08x in cache",
|
||||||
bb_error_msg("rresolve: found %s %08x in cache",
|
|
||||||
(is_host ? "host" : "net"), (unsigned)nip);
|
(is_host ? "host" : "net"), (unsigned)nip);
|
||||||
#endif
|
|
||||||
return xstrdup(pn->name);
|
return xstrdup(pn->name);
|
||||||
}
|
}
|
||||||
pn = pn->next;
|
pn = pn->next;
|
||||||
@ -128,19 +123,18 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
|
|||||||
|
|
||||||
name = NULL;
|
name = NULL;
|
||||||
if (is_host) {
|
if (is_host) {
|
||||||
#ifdef DEBUG
|
dbg("sockaddr2host_noport(%08x)", (unsigned)nip);
|
||||||
bb_error_msg("sockaddr2host_noport(%08x)", (unsigned)nip);
|
|
||||||
#endif
|
|
||||||
name = xmalloc_sockaddr2host_noport((void*)s_in);
|
name = xmalloc_sockaddr2host_noport((void*)s_in);
|
||||||
} else if (ENABLE_FEATURE_ETC_NETWORKS) {
|
}
|
||||||
|
#if ENABLE_FEATURE_ETC_NETWORKS
|
||||||
|
else {
|
||||||
struct netent *np;
|
struct netent *np;
|
||||||
#ifdef DEBUG
|
dbg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
|
||||||
bb_error_msg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
|
|
||||||
#endif
|
|
||||||
np = getnetbyaddr(ntohl(nip), AF_INET);
|
np = getnetbyaddr(ntohl(nip), AF_INET);
|
||||||
if (np)
|
if (np)
|
||||||
name = xstrdup(np->n_name);
|
name = xstrdup(np->n_name);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (!name)
|
if (!name)
|
||||||
name = xmalloc_sockaddr2dotted_noport((void*)s_in);
|
name = xmalloc_sockaddr2dotted_noport((void*)s_in);
|
||||||
|
|
||||||
@ -183,10 +177,8 @@ int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
|
|||||||
char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
|
char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
|
||||||
{
|
{
|
||||||
if (sin6->sin6_family != AF_INET6) {
|
if (sin6->sin6_family != AF_INET6) {
|
||||||
#ifdef DEBUG
|
dbg("rresolve: unsupported address family %d!",
|
||||||
bb_error_msg("rresolve: unsupported address family %d!",
|
|
||||||
sin6->sin6_family);
|
sin6->sin6_family);
|
||||||
#endif
|
|
||||||
errno = EAFNOSUPPORT;
|
errno = EAFNOSUPPORT;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user