bb_INET_default[] is really just a const "default",

nothing INET-specific
This commit is contained in:
Denis Vlasenko 2006-11-21 20:34:21 +00:00
parent 5096246ffb
commit 7ca3921e5e
7 changed files with 29 additions and 29 deletions

View File

@ -14,16 +14,12 @@
#include <sys/socket.h> #include <sys/socket.h>
#include "platform.h" #include "platform.h"
extern const char bb_INET_default[]; /* = "default" */
/* hostfirst!=0 If we expect this to be a hostname, /* hostfirst!=0 If we expect this to be a hostname,
try hostname database first try hostname database first
*/ */
extern int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst); extern int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst);
/* numeric: & 0x8000: "default" instead of "*",
/* numeric: & 0x8000: default instead of *,
* & 0x4000: host instead of net, * & 0x4000: host instead of net,
* & 0x0fff: don't resolve * & 0x0fff: don't resolve
*/ */

View File

@ -604,6 +604,8 @@ extern const char bb_msg_invalid_arg[];
extern const char bb_msg_standard_input[]; extern const char bb_msg_standard_input[];
extern const char bb_msg_standard_output[]; extern const char bb_msg_standard_output[];
extern const char bb_str_default[];
extern const char bb_path_mtab_file[]; extern const char bb_path_mtab_file[];
extern const char bb_path_nologin_file[]; extern const char bb_path_nologin_file[];
extern const char bb_path_passwd_file[]; extern const char bb_path_passwd_file[];

View File

@ -12,8 +12,6 @@
#include "libbb.h" #include "libbb.h"
#include "inet_common.h" #include "inet_common.h"
const char bb_INET_default[] = "default";
int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst) int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
{ {
struct hostent *hp; struct hostent *hp;
@ -24,9 +22,9 @@ int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
s_in->sin_port = 0; s_in->sin_port = 0;
/* Default is special, meaning 0.0.0.0. */ /* Default is special, meaning 0.0.0.0. */
if (!strcmp(name, bb_INET_default)) { if (!strcmp(name, bb_str_default)) {
s_in->sin_addr.s_addr = INADDR_ANY; s_in->sin_addr.s_addr = INADDR_ANY;
return (1); return 1;
} }
/* Look to see if it's a dotted quad. */ /* Look to see if it's a dotted quad. */
if (inet_aton(name, &s_in->sin_addr)) { if (inet_aton(name, &s_in->sin_addr)) {
@ -102,7 +100,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
s_in->sin_family); s_in->sin_family);
#endif #endif
errno = EAFNOSUPPORT; errno = EAFNOSUPPORT;
return (-1); return -1;
} }
ad = (unsigned long) s_in->sin_addr.s_addr; ad = (unsigned long) s_in->sin_addr.s_addr;
#ifdef DEBUG #ifdef DEBUG
@ -111,15 +109,15 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
if (ad == INADDR_ANY) { if (ad == INADDR_ANY) {
if ((numeric & 0x0FFF) == 0) { if ((numeric & 0x0FFF) == 0) {
if (numeric & 0x8000) if (numeric & 0x8000)
safe_strncpy(name, bb_INET_default, len); safe_strncpy(name, bb_str_default, len);
else else
safe_strncpy(name, "*", len); safe_strncpy(name, "*", len);
return (0); return 0;
} }
} }
if (numeric & 0x0FFF) { if (numeric & 0x0FFF) {
safe_strncpy(name, inet_ntoa(s_in->sin_addr), len); safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
return (0); return 0;
} }
if ((ad & (~netmask)) != 0 || (numeric & 0x4000)) if ((ad & (~netmask)) != 0 || (numeric & 0x4000))
@ -132,7 +130,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
bb_error_msg("rresolve: found %s %08lx in cache", bb_error_msg("rresolve: found %s %08lx in cache",
(host ? "host" : "net"), ad); (host ? "host" : "net"), ad);
#endif #endif
return (0); return 0;
} }
pn = pn->next; pn = pn->next;
} }
@ -167,7 +165,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
pn->name = xstrdup(name); pn->name = xstrdup(name);
INET_nn = pn; INET_nn = pn;
return (0); return 0;
} }
#ifdef CONFIG_FEATURE_IPV6 #ifdef CONFIG_FEATURE_IPV6
@ -179,7 +177,8 @@ int INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
memset(&req, '\0', sizeof req); memset(&req, '\0', sizeof req);
req.ai_family = AF_INET6; req.ai_family = AF_INET6;
if ((s = getaddrinfo(name, NULL, &req, &ai))) { s = getaddrinfo(name, NULL, &req, &ai);
if (s) {
bb_error_msg("getaddrinfo: %s: %d", name, s); bb_error_msg("getaddrinfo: %s: %d", name, s);
return -1; return -1;
} }
@ -187,7 +186,7 @@ int INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
freeaddrinfo(ai); freeaddrinfo(ai);
return (0); return 0;
} }
#ifndef IN6_IS_ADDR_UNSPECIFIED #ifndef IN6_IS_ADDR_UNSPECIFIED
@ -205,23 +204,24 @@ int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6,
/* Grmpf. -FvK */ /* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) { if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG #ifdef DEBUG
bb_error_msg(_("rresolve: unsupport address family %d!"), bb_error_msg("rresolve: unsupport address family %d!",
sin6->sin6_family); sin6->sin6_family);
#endif #endif
errno = EAFNOSUPPORT; errno = EAFNOSUPPORT;
return (-1); return -1;
} }
if (numeric & 0x7FFF) { if (numeric & 0x7FFF) {
inet_ntop(AF_INET6, &sin6->sin6_addr, name, len); inet_ntop(AF_INET6, &sin6->sin6_addr, name, len);
return (0); return 0;
} }
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000) { if (numeric & 0x8000) {
strcpy(name, "default"); strcpy(name, bb_str_default);
} else { } else {
strcpy(name, "*"); name[0] = '*';
name[1] = '\0';
} }
return (0); return 0;
} }
s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), name, len, NULL, 0, 0); s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), name, len, NULL, 0, 0);
@ -229,7 +229,7 @@ int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6,
bb_error_msg("getnameinfo failed"); bb_error_msg("getnameinfo failed");
return -1; return -1;
} }
return (0); return 0;
} }
#endif /* CONFIG_FEATURE_IPV6 */ #endif /* CONFIG_FEATURE_IPV6 */

View File

@ -28,6 +28,8 @@ const char bb_msg_invalid_arg[] = "invalid argument '%s' to '%s'";
const char bb_msg_standard_input[] = "standard input"; const char bb_msg_standard_input[] = "standard input";
const char bb_msg_standard_output[] = "standard output"; const char bb_msg_standard_output[] = "standard output";
const char bb_str_default[] = "default";
const char bb_path_passwd_file[] = "/etc/passwd"; const char bb_path_passwd_file[] = "/etc/passwd";
const char bb_path_shadow_file[] = "/etc/shadow"; const char bb_path_shadow_file[] = "/etc/shadow";
const char bb_path_group_file[] = "/etc/group"; const char bb_path_group_file[] = "/etc/group";

View File

@ -394,7 +394,7 @@ int ifconfig_main(int argc, char **argv)
sai.sin_family = AF_INET; sai.sin_family = AF_INET;
sai.sin_port = 0; sai.sin_port = 0;
if (!strcmp(host, bb_INET_default)) { if (!strcmp(host, bb_str_default)) {
/* Default is special, meaning 0.0.0.0. */ /* Default is special, meaning 0.0.0.0. */
sai.sin_addr.s_addr = INADDR_ANY; sai.sin_addr.s_addr = INADDR_ANY;
#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS

View File

@ -125,7 +125,7 @@ int get_addr_1(inet_prefix * addr, char *name, int family)
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
if (strcmp(name, bb_INET_default) == 0 || if (strcmp(name, bb_str_default) == 0 ||
strcmp(name, "all") == 0 || strcmp(name, "any") == 0) { strcmp(name, "all") == 0 || strcmp(name, "any") == 0) {
addr->family = family; addr->family = family;
addr->bytelen = (family == AF_INET6 ? 16 : 4); addr->bytelen = (family == AF_INET6 ? 16 : 4);
@ -169,7 +169,7 @@ int get_prefix_1(inet_prefix * dst, char *arg, int family)
memset(dst, 0, sizeof(*dst)); memset(dst, 0, sizeof(*dst));
if (strcmp(arg, bb_INET_default) == 0 || strcmp(arg, "any") == 0) { if (strcmp(arg, bb_str_default) == 0 || strcmp(arg, "any") == 0) {
dst->family = family; dst->family = family;
dst->bytelen = 0; dst->bytelen = 0;
dst->bitlen = 0; dst->bitlen = 0;

View File

@ -186,7 +186,7 @@ static void INET_setroute(int action, char **args)
#endif #endif
} else { } else {
/* Default netmask. */ /* Default netmask. */
netmask = bb_INET_default; netmask = bb_str_default;
} }
/* Prefer hostname lookup is -host flag (xflag==1) was given. */ /* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst, isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
@ -346,7 +346,7 @@ static void INET6_setroute(int action, char **args)
/* We know args isn't NULL from the check in route_main. */ /* We know args isn't NULL from the check in route_main. */
const char *target = *args++; const char *target = *args++;
if (strcmp(target, bb_INET_default) == 0) { if (strcmp(target, bb_str_default) == 0) {
prefix_len = 0; prefix_len = 0;
memset(&sa6, 0, sizeof(sa6)); memset(&sa6, 0, sizeof(sa6));
} else { } else {