aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-14 20:17:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-14 20:17:17 +0200
commit7d7c7bb2205b92359ac88f3469d3af672e2be929 (patch)
tree08697e12780088c05dd7eb995797912704b4f853
parent2ed74e25d354e6958dc86a21aa32c2dacb809bf0 (diff)
downloadbusybox-w32-7d7c7bb2205b92359ac88f3469d3af672e2be929.tar.gz
busybox-w32-7d7c7bb2205b92359ac88f3469d3af672e2be929.tar.bz2
busybox-w32-7d7c7bb2205b92359ac88f3469d3af672e2be929.zip
libbb: hide getnetbyaddr() inside "#if ENABLE_FEATURE_ETC_NETWORKS" block
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/inet_common.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index 5b4a4a10b..04259f47b 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -11,6 +11,12 @@
11#include "libbb.h" 11#include "libbb.h"
12#include "inet_common.h" 12#include "inet_common.h"
13 13
14#if 0
15# define dbg(...) bb_error_msg(__VA_ARGS__)
16#else
17# define dbg(...) ((void)0)
18#endif
19
14int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst) 20int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
15{ 21{
16 struct hostent *hp; 22 struct hostent *hp;
@@ -33,9 +39,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
33 } 39 }
34 /* If we expect this to be a hostname, try hostname database first */ 40 /* If we expect this to be a hostname, try hostname database first */
35 if (hostfirst) { 41 if (hostfirst) {
36#ifdef DEBUG 42 dbg("gethostbyname(%s)", name);
37 bb_error_msg("gethostbyname(%s)", name);
38#endif
39 hp = gethostbyname(name); 43 hp = gethostbyname(name);
40 if (hp) { 44 if (hp) {
41 memcpy(&s_in->sin_addr, hp->h_addr_list[0], 45 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
45 } 49 }
46#if ENABLE_FEATURE_ETC_NETWORKS 50#if ENABLE_FEATURE_ETC_NETWORKS
47 /* Try the NETWORKS database to see if this is a known network. */ 51 /* Try the NETWORKS database to see if this is a known network. */
48#ifdef DEBUG 52 dbg("getnetbyname(%s)", name);
49 bb_error_msg("getnetbyname(%s)", name);
50#endif
51 np = getnetbyname(name); 53 np = getnetbyname(name);
52 if (np) { 54 if (np) {
53 s_in->sin_addr.s_addr = htonl(np->n_net); 55 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
61#ifdef DEBUG 63#ifdef DEBUG
62 res_init(); 64 res_init();
63 _res.options |= RES_DEBUG; 65 _res.options |= RES_DEBUG;
64 bb_error_msg("gethostbyname(%s)", name);
65#endif 66#endif
67 dbg("gethostbyname(%s)", name);
66 hp = gethostbyname(name); 68 hp = gethostbyname(name);
67 if (!hp) { 69 if (!hp) {
68 return -1; 70 return -1;
@@ -93,17 +95,12 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
93 smallint is_host; 95 smallint is_host;
94 96
95 if (s_in->sin_family != AF_INET) { 97 if (s_in->sin_family != AF_INET) {
96#ifdef DEBUG 98 dbg("rresolve: unsupported address family %d!", s_in->sin_family);
97 bb_error_msg("rresolve: unsupported address family %d!",
98 s_in->sin_family);
99#endif
100 errno = EAFNOSUPPORT; 99 errno = EAFNOSUPPORT;
101 return NULL; 100 return NULL;
102 } 101 }
103 nip = s_in->sin_addr.s_addr; 102 nip = s_in->sin_addr.s_addr;
104#ifdef DEBUG 103 dbg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
105 bb_error_msg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
106#endif
107 if (numeric & 0x0FFF) 104 if (numeric & 0x0FFF)
108 return xmalloc_sockaddr2dotted_noport((void*)s_in); 105 return xmalloc_sockaddr2dotted_noport((void*)s_in);
109 if (nip == INADDR_ANY) { 106 if (nip == INADDR_ANY) {
@@ -117,10 +114,8 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
117 pn = cache; 114 pn = cache;
118 while (pn) { 115 while (pn) {
119 if (pn->nip == nip && pn->is_host == is_host) { 116 if (pn->nip == nip && pn->is_host == is_host) {
120#ifdef DEBUG 117 dbg("rresolve: found %s %08x in cache",
121 bb_error_msg("rresolve: found %s %08x in cache",
122 (is_host ? "host" : "net"), (unsigned)nip); 118 (is_host ? "host" : "net"), (unsigned)nip);
123#endif
124 return xstrdup(pn->name); 119 return xstrdup(pn->name);
125 } 120 }
126 pn = pn->next; 121 pn = pn->next;
@@ -128,19 +123,18 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
128 123
129 name = NULL; 124 name = NULL;
130 if (is_host) { 125 if (is_host) {
131#ifdef DEBUG 126 dbg("sockaddr2host_noport(%08x)", (unsigned)nip);
132 bb_error_msg("sockaddr2host_noport(%08x)", (unsigned)nip);
133#endif
134 name = xmalloc_sockaddr2host_noport((void*)s_in); 127 name = xmalloc_sockaddr2host_noport((void*)s_in);
135 } else if (ENABLE_FEATURE_ETC_NETWORKS) { 128 }
129#if ENABLE_FEATURE_ETC_NETWORKS
130 else {
136 struct netent *np; 131 struct netent *np;
137#ifdef DEBUG 132 dbg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
138 bb_error_msg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
139#endif
140 np = getnetbyaddr(ntohl(nip), AF_INET); 133 np = getnetbyaddr(ntohl(nip), AF_INET);
141 if (np) 134 if (np)
142 name = xstrdup(np->n_name); 135 name = xstrdup(np->n_name);
143 } 136 }
137#endif
144 if (!name) 138 if (!name)
145 name = xmalloc_sockaddr2dotted_noport((void*)s_in); 139 name = xmalloc_sockaddr2dotted_noport((void*)s_in);
146 140
@@ -183,10 +177,8 @@ int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
183char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) 177char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
184{ 178{
185 if (sin6->sin6_family != AF_INET6) { 179 if (sin6->sin6_family != AF_INET6) {
186#ifdef DEBUG 180 dbg("rresolve: unsupported address family %d!",
187 bb_error_msg("rresolve: unsupported address family %d!",
188 sin6->sin6_family); 181 sin6->sin6_family);
189#endif
190 errno = EAFNOSUPPORT; 182 errno = EAFNOSUPPORT;
191 return NULL; 183 return NULL;
192 } 184 }