aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/brctl.c2
-rw-r--r--networking/httpd.c15
-rw-r--r--networking/inetd.c2
-rw-r--r--networking/libiproute/ipaddress.c14
-rw-r--r--networking/libiproute/iprule.c7
-rw-r--r--networking/nslookup.c30
-rw-r--r--networking/ntpd.c11
-rw-r--r--networking/ping.c38
-rw-r--r--networking/tls_fe.c28
-rw-r--r--networking/traceroute.c15
-rw-r--r--networking/udhcp/Config.src8
-rw-r--r--networking/udhcp/d6_dhcpc.c4
-rw-r--r--networking/udhcp/dhcpc.c4
-rw-r--r--networking/udhcp/dumpleases.c2
14 files changed, 125 insertions, 55 deletions
diff --git a/networking/brctl.c b/networking/brctl.c
index f057f9b60..e1f3e6445 100644
--- a/networking/brctl.c
+++ b/networking/brctl.c
@@ -156,7 +156,7 @@ static int show_bridge(const char *name, int need_hdr)
else
if (LONE_CHAR(filedata, '1'))
strcpy(filedata, "yes");
- fputs(filedata, stdout);
+ fputs_stdout(filedata);
/* sfx points past "BR/bridge/", turn it into "BR/brif": */
sfx[-4] = 'f'; sfx[-3] = '\0';
diff --git a/networking/httpd.c b/networking/httpd.c
index 4346141ee..e6757d943 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -298,6 +298,11 @@
# include <sys/sendfile.h>
#endif
+/* see sys/netinet6/in6.h */
+#if defined(__FreeBSD__)
+# define s6_addr32 __u6_addr.__u6_addr32
+#endif
+
#define DEBUG 0
#define IOBUF_SIZE 8192
@@ -1871,7 +1876,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what)
send_headers(HTTP_OK);
#if ENABLE_FEATURE_USE_SENDFILE
{
- off_t offset = range_start;
+ off_t offset = (range_start < 0) ? 0 : range_start;
while (1) {
/* sz is rounded down to 64k */
ssize_t sz = MAXINT(ssize_t) - 0xffff;
@@ -2486,8 +2491,8 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
if (STRNCASECMP(iobuf, "Range:") == 0) {
/* We know only bytes=NNN-[MMM] */
char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
- if (is_prefixed_with(s, "bytes=")) {
- s += sizeof("bytes=")-1;
+ s = is_prefixed_with(s, "bytes=");
+ if (s) {
range_start = BB_STRTOOFF(s, &s, 10);
if (s[0] != '-' || range_start < 0) {
range_start = -1;
@@ -2783,12 +2788,12 @@ int httpd_main(int argc UNUSED_PARAM, char **argv)
, &verbose
);
if (opt & OPT_DECODE_URL) {
- fputs(percent_decode_in_place(url_for_decode, /*strict:*/ 0), stdout);
+ fputs_stdout(percent_decode_in_place(url_for_decode, /*strict:*/ 0));
return 0;
}
#if ENABLE_FEATURE_HTTPD_ENCODE_URL_STR
if (opt & OPT_ENCODE_URL) {
- fputs(encodeString(url_for_encode), stdout);
+ fputs_stdout(encodeString(url_for_encode));
return 0;
}
#endif
diff --git a/networking/inetd.c b/networking/inetd.c
index 9f5a436d6..febfb7b73 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1701,7 +1701,7 @@ static uint32_t machtime(void)
{
struct timeval tv;
- gettimeofday(&tv, NULL);
+ xgettimeofday(&tv);
return htonl((uint32_t)(tv.tv_sec + 2208988800U));
}
/* ARGSUSED */
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index dfd84c000..17a838411 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -192,20 +192,20 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1));
if (tb[IFLA_ADDRESS]) {
- fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
+ fputs_stdout(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
RTA_PAYLOAD(tb[IFLA_ADDRESS]),
ifi->ifi_type,
- b1, sizeof(b1)), stdout);
+ b1, sizeof(b1)));
}
if (tb[IFLA_BROADCAST]) {
if (ifi->ifi_flags & IFF_POINTOPOINT)
printf(" peer ");
else
printf(" brd ");
- fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
+ fputs_stdout(ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
RTA_PAYLOAD(tb[IFLA_BROADCAST]),
ifi->ifi_type,
- b1, sizeof(b1)), stdout);
+ b1, sizeof(b1)));
}
}
bb_putchar('\n');
@@ -307,9 +307,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
printf(" family %d ", ifa->ifa_family);
if (rta_tb[IFA_LOCAL]) {
- fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])),
- stdout
- );
+ fputs_stdout(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])));
if (rta_tb[IFA_ADDRESS] == NULL
|| memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0
@@ -363,7 +361,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
if (ifa_flags)
printf("flags %02x ", ifa_flags);
if (rta_tb[IFA_LABEL])
- fputs((char*)RTA_DATA(rta_tb[IFA_LABEL]), stdout);
+ fputs_stdout((char*)RTA_DATA(rta_tb[IFA_LABEL]));
if (rta_tb[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
char buf[128];
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 50acfe4e7..a23a00d87 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -88,10 +88,9 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
r->rtm_src_len
);
} else {
- fputs(format_host(r->rtm_family,
+ fputs_stdout(format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC])),
- stdout
+ RTA_DATA(tb[RTA_SRC]))
);
}
} else if (r->rtm_src_len) {
@@ -178,7 +177,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
} else
printf("masquerade");
} else if (r->rtm_type != RTN_UNICAST)
- fputs(rtnl_rtntype_n2a(r->rtm_type), stdout);
+ fputs_stdout(rtnl_rtntype_n2a(r->rtm_type));
bb_putchar('\n');
/*fflush_all();*/
diff --git a/networking/nslookup.c b/networking/nslookup.c
index dda22de0e..c43ad46f3 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -349,6 +349,8 @@ static int parse_reply(const unsigned char *msg, size_t len)
header = (HEADER *)msg;
if (!header->aa)
printf("Non-authoritative answer:\n");
+ else if (option_mask32 & OPT_debug)
+ printf("Non-authoritative answer:\n" + 4);
if (ns_initparse(msg, len, &handle) != 0) {
//printf("Unable to parse reply: %s\n", strerror(errno));
@@ -381,7 +383,7 @@ static int parse_reply(const unsigned char *msg, size_t len)
return -1;
}
inet_ntop(AF_INET6, ns_rr_rdata(rr), astr, sizeof(astr));
- /* bind-utils-9.11.3 uses the same format for A and AAAA answers */
+ /* bind-utils 9.11.3 uses the same format for A and AAAA answers */
printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
break;
#endif
@@ -580,7 +582,7 @@ static int send_queries(struct ns *ns)
printf("Address:\t%s\n\n",
auto_string(xmalloc_sockaddr2dotted(&ns->lsa->u.sa))
);
- /* In "Address", bind-utils-9.11.3 show port after a hash: "1.2.3.4#53" */
+ /* In "Address", bind-utils 9.11.3 show port after a hash: "1.2.3.4#53" */
/* Should we do the same? */
}
@@ -640,12 +642,26 @@ static int send_queries(struct ns *ns)
printf("*** Can't find %s: Parse error\n", G.query[qn].name);
G.exitcode = EXIT_FAILURE;
break;
-
- case 0:
- printf("*** Can't find %s: No answer\n", G.query[qn].name);
- break;
+ /* bind-utils 9.11.25 just says nothing in this case */
+ //case 0:
+ // break;
}
}
+/* NB: in case of authoritative, empty answer (NODATA), IOW: one with
+ * ns_msg_count() == 0, bind-utils 9.11.25 shows no trace of this answer
+ * (unless -debug, where it says:
+ * ------------
+ * QUESTIONS:
+ * host.com, type = AAAA, class = IN
+ * ANSWERS:
+ * AUTHORITY RECORDS:
+ * ADDITIONAL RECORDS:
+ * ------------
+ * ). Due to printing of below '\n', we do show an additional empty line.
+ * This is better than not showing any indication of this reply at all,
+ * yet maintains "compatibility". I wonder whether it's better to break compat
+ * and emit something more meaningful, e.g. print "Empty answer (NODATA)"?
+ */
bb_putchar('\n');
n_replies++;
if (n_replies >= G.query_count)
@@ -697,7 +713,7 @@ static void parse_resolvconf(void)
{
FILE *resolv;
- resolv = fopen("/etc/resolv.conf", "r");
+ resolv = fopen_for_read("/etc/resolv.conf");
if (resolv) {
char line[512]; /* "search" is defined to be up to 256 chars */
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 5a540a391..1f17b08ef 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -113,6 +113,13 @@
# define IPTOS_DSCP_AF21 0x48
#endif
+#if defined(__FreeBSD__)
+/* see sys/timex.h */
+# define adjtimex ntp_adjtime
+# define ADJ_OFFSET MOD_OFFSET
+# define ADJ_STATUS MOD_STATUS
+# define ADJ_TIMECONST MOD_TIMECONST
+#endif
/* Verbosity control (max level of -dddd options accepted).
* max 6 is very talkative (and bloated). 3 is non-bloated,
@@ -560,7 +567,7 @@ static double
gettime1900d(void)
{
struct timeval tv;
- gettimeofday(&tv, NULL); /* never fails */
+ xgettimeofday(&tv);
G.cur_time = tv.tv_sec + (1.0e-6 * tv.tv_usec) + OFFSET_1900_1970;
return G.cur_time;
}
@@ -1144,7 +1151,7 @@ step_time(double offset)
char buf[sizeof("yyyy-mm-dd hh:mm:ss") + /*paranoia:*/ 4];
time_t tval;
- gettimeofday(&tvc, NULL); /* never fails */
+ xgettimeofday(&tvc);
dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
d_to_tv(dtime, &tvn);
xsettimeofday(&tvn);
diff --git a/networking/ping.c b/networking/ping.c
index c4a15e06e..86d8088de 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -122,6 +122,10 @@
//usage: "round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
#include <net/if.h>
+#if defined(__FreeBSD__)
+# include <netinet/in.h> /* struct ip and friends */
+# include <netinet/ip.h>
+#endif
#include <netinet/ip_icmp.h>
#include "libbb.h"
#include "common_bufsiz.h"
@@ -160,6 +164,40 @@
# endif
#endif
+#if defined(__FreeBSD__)
+/**
+ * On BSD the IPv4 struct is called struct ip and instead of iXX
+ * the members are called ip_XX. One could change this code to use
+ * struct ip but that would require to define _BSD_SOURCE and that
+ * might have other complications. Instead make sure struct iphdr
+ * is present on FreeBSD. The below is taken from GLIBC.
+ *
+ * The GNU C Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+struct iphdr {
+# if BYTE_ORDER == LITTLE_ENDIAN
+ unsigned int ihl:4;
+ unsigned int version:4;
+# elif BYTE_ORDER == BIG_ENDIAN
+ unsigned int version:4;
+ unsigned int ihl:4;
+# endif
+ uint8_t tos;
+ uint16_t tot_len;
+ uint16_t id;
+ uint16_t frag_off;
+ uint8_t ttl;
+ uint8_t protocol;
+ uint16_t check;
+ uint32_t saddr;
+ uint32_t daddr;
+ /*The options start here. */
+};
+#endif
+
enum {
DEFDATALEN = 56,
MAXIPLEN = 60,
diff --git a/networking/tls_fe.c b/networking/tls_fe.c
index 10971bbff..f810e112a 100644
--- a/networking/tls_fe.c
+++ b/networking/tls_fe.c
@@ -383,12 +383,10 @@ static void fe_inv__distinct(byte *r, const byte *x)
* to avoid copying temporaries.
*/
- /* 1 1 */
- fe_mul__distinct(s, x, x);
- fe_mul__distinct(r, s, x);
+ lm_copy(r, x);
- /* 1 x 248 */
- for (i = 0; i < 248; i++) {
+ /* 1, 1 x 249 */
+ for (i = 0; i < 249; i++) {
fe_mul__distinct(s, r, r);
fe_mul__distinct(r, s, x);
}
@@ -403,13 +401,11 @@ static void fe_inv__distinct(byte *r, const byte *x)
/* 0 */
fe_mul__distinct(r, s, s);
- /* 1 */
- fe_mul__distinct(s, r, r);
- fe_mul__distinct(r, s, x);
-
- /* 1 */
- fe_mul__distinct(s, r, r);
- fe_mul__distinct(r, s, x);
+ /* 1, 1 */
+ for (i = 0; i < 2; i++) {
+ fe_mul__distinct(s, r, r);
+ fe_mul__distinct(r, s, x);
+ }
}
#if 0 //UNUSED
@@ -435,12 +431,10 @@ static void exp2523(byte *r, const byte *x, byte *s)
* 111111... 01
*/
- /* 1 1 */
- fe_mul__distinct(r, x, x);
- fe_mul__distinct(s, r, x);
+ lm_copy(s, x);
- /* 1 x 248 */
- for (i = 0; i < 248; i++) {
+ /* 1, 1 x 249 */
+ for (i = 0; i < 249; i++) {
fe_mul__distinct(r, s, s);
fe_mul__distinct(s, r, x);
}
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 3f1a9ab46..057f8591a 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -505,7 +505,7 @@ send_probe(int seq, int ttl)
struct outdata6_t *pkt = (void *) outdata;
pkt->ident6 = ident;
pkt->seq6 = htonl(seq);
- /*gettimeofday(&pkt->tv, &tz);*/
+ /*xgettimeofday(&pkt->tv);*/
icp = outicmp6;
} else
#endif
@@ -716,8 +716,8 @@ packet4_ok(int read_len, int seq)
// Off: since we do not form the entire IP packet,
// but defer it to kernel, we can't set source port,
// and thus can't check it here in the reply
- /* && up->source == ident */
- && up->dest == htons(port + seq)
+ /* && up->uh_sport == ident */
+ && up->uh_dport == htons(port + seq)
) {
return (type == ICMP_TIMXCEED ? -1 : code + 1);
}
@@ -896,7 +896,7 @@ traceroute_init(int op, char **argv)
op |= getopt32(argv, "^"
OPT_STRING
- "\0" "-1:x-x" /* minimum 1 arg */
+ "\0" "-1" /* minimum 1 arg */
, &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str
, &source, &waittime_str, &pausemsecs_str, &first_ttl_str
);
@@ -985,8 +985,13 @@ traceroute_init(int op, char **argv)
snd = xsocket(AF_INET, SOCK_DGRAM, 0);
}
#if ENABLE_TRACEROUTE6
+# if defined(__FreeBSD__)
+# define SOL_V6_OPTION SOL_IPV6
+# else
+# define SOL_V6_OPTION SOL_RAW
+# endif
else {
- if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0)
+ if (setsockopt_int(rcvsock, SOL_V6_OPTION, IPV6_CHECKSUM, 2) != 0)
bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM");
if (op & OPT_USE_ICMP)
snd = xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src
index 7d04bb246..8c8c11c26 100644
--- a/networking/udhcp/Config.src
+++ b/networking/udhcp/Config.src
@@ -104,6 +104,14 @@ INSERT
comment "Common options for DHCP applets"
depends on UDHCPD || UDHCPC || UDHCPC6 || DHCPRELAY
+config UDHCPC_DEFAULT_INTERFACE
+ string "Default interface name"
+ default "eth0"
+ depends on UDHCPC || UDHCPC6
+ help
+ The interface that will be used if no other interface is
+ specified on the commandline.
+
config FEATURE_UDHCP_PORT
bool "Enable '-P port' option for udhcpd and udhcpc"
default n
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index d4d29dcbb..fbdaa99bd 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -1163,7 +1163,7 @@ static void client_background(void)
//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"odR] [-i IFACE] [-r IPv6] [-s PROG] [-p PIDFILE]\n"
//usage: " [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P PORT]")
//usage:#define udhcpc6_full_usage "\n"
-//usage: "\n -i IFACE Interface to use (default eth0)"
+//usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")"
//usage: "\n -p FILE Create pidfile"
//usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")"
//usage: "\n -B Request broadcast replies"
@@ -1231,7 +1231,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
/* Default options */
IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;)
- client_data.interface = "eth0";
+ client_data.interface = CONFIG_UDHCPC_DEFAULT_INTERFACE;
client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
client_data.sockfd = -1;
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 98720b45b..922c71ebd 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1196,7 +1196,7 @@ static void client_background(void)
//usage: " [-i IFACE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-s PROG] [-p PIDFILE]\n"
//usage: " [-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]..."
//usage:#define udhcpc_full_usage "\n"
-//usage: "\n -i IFACE Interface to use (default eth0)"
+//usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")"
//usage: IF_FEATURE_UDHCP_PORT(
//usage: "\n -P PORT Use PORT (default 68)"
//usage: )
@@ -1265,7 +1265,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* Default options */
IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
- client_data.interface = "eth0";
+ client_data.interface = CONFIG_UDHCPC_DEFAULT_INTERFACE;
client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
client_data.sockfd = -1;
str_V = "udhcp "BB_VER;
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 1e9405205..19606c58e 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -112,7 +112,7 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
} else { /* -a */
time_t t = expires_abs;
- fputs(ctime(&t), stdout);
+ fputs_stdout(ctime(&t));
}
}
/* close(fd); */