#include <sys/socket.h>
#include "platform.h"
-
-extern const char bb_INET_default[]; /* = "default" */
-
/* hostfirst!=0 If we expect this to be a hostname,
try hostname database first
*/
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,
* & 0x0fff: don't resolve
*/
#include "libbb.h"
#include "inet_common.h"
-const char bb_INET_default[] = "default";
-
int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
{
struct hostent *hp;
s_in->sin_port = 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;
- return (1);
+ return 1;
}
/* Look to see if it's a dotted quad. */
if (inet_aton(name, &s_in->sin_addr)) {
s_in->sin_family);
#endif
errno = EAFNOSUPPORT;
- return (-1);
+ return -1;
}
ad = (unsigned long) s_in->sin_addr.s_addr;
#ifdef DEBUG
if (ad == INADDR_ANY) {
if ((numeric & 0x0FFF) == 0) {
if (numeric & 0x8000)
- safe_strncpy(name, bb_INET_default, len);
+ safe_strncpy(name, bb_str_default, len);
else
safe_strncpy(name, "*", len);
- return (0);
+ return 0;
}
}
if (numeric & 0x0FFF) {
safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
- return (0);
+ return 0;
}
if ((ad & (~netmask)) != 0 || (numeric & 0x4000))
bb_error_msg("rresolve: found %s %08lx in cache",
(host ? "host" : "net"), ad);
#endif
- return (0);
+ return 0;
}
pn = pn->next;
}
pn->name = xstrdup(name);
INET_nn = pn;
- return (0);
+ return 0;
}
#ifdef CONFIG_FEATURE_IPV6
memset(&req, '\0', sizeof req);
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);
return -1;
}
freeaddrinfo(ai);
- return (0);
+ return 0;
}
#ifndef IN6_IS_ADDR_UNSPECIFIED
/* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
- bb_error_msg(_("rresolve: unsupport address family %d!"),
+ bb_error_msg("rresolve: unsupport address family %d!",
sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;
- return (-1);
+ return -1;
}
if (numeric & 0x7FFF) {
inet_ntop(AF_INET6, &sin6->sin6_addr, name, len);
- return (0);
+ return 0;
}
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000) {
- strcpy(name, "default");
+ strcpy(name, bb_str_default);
} 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);
bb_error_msg("getnameinfo failed");
return -1;
}
- return (0);
+ return 0;
}
#endif /* CONFIG_FEATURE_IPV6 */
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) {
addr->family = family;
addr->bytelen = (family == AF_INET6 ? 16 : 4);
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->bytelen = 0;
dst->bitlen = 0;
#endif
} else {
/* Default netmask. */
- netmask = bb_INET_default;
+ netmask = bb_str_default;
}
/* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
/* We know args isn't NULL from the check in route_main. */
const char *target = *args++;
- if (strcmp(target, bb_INET_default) == 0) {
+ if (strcmp(target, bb_str_default) == 0) {
prefix_len = 0;
memset(&sa6, 0, sizeof(sa6));
} else {