aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/arping.c2
-rw-r--r--networking/ftpd.c8
-rw-r--r--networking/httpd.c4
-rw-r--r--networking/nbd-client.c2
-rw-r--r--networking/nc_bloaty.c4
-rw-r--r--networking/ntpd.c6
-rw-r--r--networking/ping.c16
-rw-r--r--networking/telnet.c2
-rw-r--r--networking/telnetd.c2
-rw-r--r--networking/traceroute.c41
-rw-r--r--networking/udhcp/dhcpc.c4
11 files changed, 39 insertions, 52 deletions
diff --git a/networking/arping.c b/networking/arping.c
index 9ac4a7cee..ce7fa299c 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -357,7 +357,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv)
saddr.sin_port = htons(1025);
saddr.sin_addr = dst;
- if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1)
+ if (setsockopt_SOL_SOCKET_1(probe_fd, SO_DONTROUTE) != 0)
bb_perror_msg("setsockopt(%s)", "SO_DONTROUTE");
xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
getsockname(probe_fd, (struct sockaddr *) &saddr, &alen);
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 2351d6dd3..7735b7233 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -377,7 +377,7 @@ ftpdataio_get_pasv_fd(void)
return remote_fd;
}
- setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(remote_fd);
return remote_fd;
}
@@ -1186,11 +1186,11 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
, SIG_IGN);
/* Set up options on the command socket (do we need these all? why?) */
- setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
- setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_1(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY);
+ setsockopt_keepalive(STDIN_FILENO);
/* Telnet protocol over command link may send "urgent" data,
* we prefer it to be received in the "normal" data stream: */
- setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
+ setsockopt_1(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE);
WRITE_OK(FTP_GREET);
signal(SIGALRM, timeout_handler);
diff --git a/networking/httpd.c b/networking/httpd.c
index 7a9065fcc..feaaa94d5 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2352,7 +2352,7 @@ static void mini_httpd(int server_socket)
continue;
/* set the KEEPALIVE option to cull dead connections */
- setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(n);
if (fork() == 0) {
/* child */
@@ -2395,7 +2395,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
continue;
/* set the KEEPALIVE option to cull dead connections */
- setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(n);
if (vfork() == 0) {
/* child */
diff --git a/networking/nbd-client.c b/networking/nbd-client.c
index cadda5261..a601430b6 100644
--- a/networking/nbd-client.c
+++ b/networking/nbd-client.c
@@ -83,7 +83,7 @@ int nbdclient_main(int argc, char **argv)
// Find and connect to server
sock = create_and_connect_stream_or_die(host, xatou16(port));
- setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
+ setsockopt_1(sock, IPPROTO_TCP, TCP_NODELAY);
// Log on to the server
xread(sock, &nbd_header, 8+8+8+4 + 124);
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index b28d05f51..471ae1a12 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -863,8 +863,8 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
xbind(netfd, &ouraddr->u.sa, ouraddr->len);
}
#if 0
- setsockopt(netfd, SOL_SOCKET, SO_RCVBUF, &o_rcvbuf, sizeof o_rcvbuf);
- setsockopt(netfd, SOL_SOCKET, SO_SNDBUF, &o_sndbuf, sizeof o_sndbuf);
+ setsockopt_SOL_SOCKET_int(netfd, SO_RCVBUF, o_rcvbuf);
+ setsockopt_SOL_SOCKET_int(netfd, SO_SNDBUF, o_sndbuf);
#endif
#ifdef BLOAT
diff --git a/networking/ntpd.c b/networking/ntpd.c
index b5120a70d..9732c9b1a 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -405,8 +405,6 @@ struct globals {
};
#define G (*ptr_to_globals)
-static const int const_IPTOS_LOWDELAY = IPTOS_LOWDELAY;
-
#define VERB1 if (MAX_VERBOSE && G.verbose)
#define VERB2 if (MAX_VERBOSE >= 2 && G.verbose >= 2)
@@ -837,7 +835,7 @@ send_query_to_peer(peer_t *p)
#if ENABLE_FEATURE_IPV6
if (family == AF_INET)
#endif
- setsockopt(fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY));
+ setsockopt_int(fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
free(local_lsa);
}
@@ -2186,7 +2184,7 @@ static NOINLINE void ntp_init(char **argv)
xfunc_die();
}
socket_want_pktinfo(G_listen_fd);
- setsockopt(G_listen_fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY));
+ setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
}
#endif
if (!(opts & OPT_n)) {
diff --git a/networking/ping.c b/networking/ping.c
index 20489a070..e1f9ebc3a 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -247,7 +247,7 @@ static void ping6(len_and_sockaddr *lsa)
pkt->icmp6_type = ICMP6_ECHO_REQUEST;
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
- setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
+ setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
xsendto(pingsock, G.packet, DEFDATALEN + sizeof(struct icmp6_hdr), &lsa->u.sa, lsa->len);
@@ -700,12 +700,12 @@ static void ping4(len_and_sockaddr *lsa)
/* set recv buf (needed if we can get lots of responses: flood ping,
* broadcast ping etc) */
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
- setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
+ setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);
if (opt_ttl != 0) {
- setsockopt(pingsock, IPPROTO_IP, IP_TTL, &opt_ttl, sizeof(opt_ttl));
+ setsockopt_int(pingsock, IPPROTO_IP, IP_TTL, opt_ttl);
/* above doesnt affect packets sent to bcast IP, so... */
- setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_TTL, &opt_ttl, sizeof(opt_ttl));
+ setsockopt_int(pingsock, IPPROTO_IP, IP_MULTICAST_TTL, opt_ttl);
}
signal(SIGINT, print_stats_and_exit);
@@ -766,15 +766,15 @@ static void ping6(len_and_sockaddr *lsa)
/* set recv buf (needed if we can get lots of responses: flood ping,
* broadcast ping etc) */
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
- setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
+ setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
- if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2)
+ if (sockopt != 2)
BUG_bad_offsetof_icmp6_cksum();
- setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
+ setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
/* request ttl info to be returned in ancillary data */
- setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1));
+ setsockopt_1(pingsock, SOL_IPV6, IPV6_HOPLIMIT);
if (if_index)
pingaddr.sin6.sin6_scope_id = if_index;
diff --git a/networking/telnet.c b/networking/telnet.c
index a25579773..3bb6fb1ba 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -623,7 +623,7 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(create_and_connect_stream_or_die(host, port), netfd);
- setsockopt(netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(netfd);
signal(SIGINT, record_signo);
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 6aee95871..25d05fe7a 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -265,7 +265,7 @@ make_new_session(
close_on_exec_on(fd);
/* SO_KEEPALIVE by popular demand */
- setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(sock);
#if ENABLE_FEATURE_TELNETD_STANDALONE
ts->sockfd_read = sock;
ndelay_on(sock);
diff --git a/networking/traceroute.c b/networking/traceroute.c
index e41d89e9f..642110c54 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -473,8 +473,8 @@ send_probe(int seq, int ttl)
#if ENABLE_TRACEROUTE6
if (dest_lsa->u.sa.sa_family == AF_INET6) {
- res = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
- if (res < 0)
+ res = setsockopt_int(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl);
+ if (res != 0)
bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl);
out = outip;
len = packlen;
@@ -482,8 +482,8 @@ send_probe(int seq, int ttl)
#endif
{
#if defined IP_TTL
- res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
- if (res < 0)
+ res = setsockopt_int(sndsock, IPPROTO_IP, IP_TTL, ttl);
+ if (res != 0)
bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl);
#endif
out = outicmp;
@@ -902,13 +902,10 @@ common_traceroute_main(int op, char **argv)
if (af == AF_INET6) {
xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock);
# ifdef IPV6_RECVPKTINFO
- setsockopt(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO,
- &const_int_1, sizeof(const_int_1));
- setsockopt(rcvsock, SOL_IPV6, IPV6_2292PKTINFO,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO);
+ setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO);
# else
- setsockopt(rcvsock, SOL_IPV6, IPV6_PKTINFO,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO);
# endif
} else
#endif
@@ -918,17 +915,14 @@ common_traceroute_main(int op, char **argv)
#if TRACEROUTE_SO_DEBUG
if (op & OPT_DEBUG)
- setsockopt(rcvsock, SOL_SOCKET, SO_DEBUG,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_SOL_SOCKET_1(rcvsock, SO_DEBUG);
#endif
if (op & OPT_BYPASS_ROUTE)
- setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_SOL_SOCKET_1(rcvsock, SO_DONTROUTE);
#if ENABLE_TRACEROUTE6
if (af == AF_INET6) {
- static const int two = 2;
- if (setsockopt(rcvsock, SOL_RAW, IPV6_CHECKSUM, &two, sizeof(two)) < 0)
+ if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0)
bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM");
xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock);
} else
@@ -966,28 +960,25 @@ common_traceroute_main(int op, char **argv)
}
#ifdef SO_SNDBUF
- if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) {
- bb_perror_msg_and_die("SO_SNDBUF");
+ if (setsockopt_SOL_SOCKET_int(sndsock, SO_SNDBUF, packlen) != 0) {
+ bb_perror_msg_and_die("setsockopt(%s)", "SO_SNDBUF");
}
#endif
#ifdef IP_TOS
- if ((op & OPT_TOS) && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
+ if ((op & OPT_TOS) && setsockopt_int(sndsock, IPPROTO_IP, IP_TOS, tos) != 0) {
bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos);
}
#endif
#ifdef IP_DONTFRAG
if (op & OPT_DONT_FRAGMNT)
- setsockopt(sndsock, IPPROTO_IP, IP_DONTFRAG,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_1(sndsock, IPPROTO_IP, IP_DONTFRAG);
#endif
#if TRACEROUTE_SO_DEBUG
if (op & OPT_DEBUG)
- setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_SOL_SOCKET_1(sndsock, SO_DEBUG);
#endif
if (op & OPT_BYPASS_ROUTE)
- setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
- &const_int_1, sizeof(const_int_1));
+ setsockopt_SOL_SOCKET_1(sndsock, SO_DONTROUTE);
outip = xzalloc(packlen);
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 811a1a1ee..11f7b2d49 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1043,9 +1043,7 @@ static int udhcp_raw_socket(int ifindex)
}
#endif
- if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA,
- &const_int_1, sizeof(int)) < 0
- ) {
+ if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
if (errno != ENOPROTOOPT)
log1("Can't set PACKET_AUXDATA on raw socket");
}