aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-08-24 19:48:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-08-24 20:00:17 +0200
commitc52cbea2bba6582b44facb424a15dc544b54fb28 (patch)
treeb048b3f7832621a16ed9ba2441756e2fc69ee316
parent2db782bc7be70c34a756e2bc6d4a53e8f47bab20 (diff)
downloadbusybox-w32-c52cbea2bba6582b44facb424a15dc544b54fb28.tar.gz
busybox-w32-c52cbea2bba6582b44facb424a15dc544b54fb28.tar.bz2
busybox-w32-c52cbea2bba6582b44facb424a15dc544b54fb28.zip
libbb: add setsockopt_foo helpers
function old new delta setsockopt_int - 23 +23 do_load 918 934 +16 setsockopt_SOL_SOCKET_int - 14 +14 setsockopt_keepalive - 10 +10 setsockopt_SOL_SOCKET_1 - 10 +10 buffer_fill_and_print 169 178 +9 setsockopt_1 - 8 +8 nfsmount 3560 3566 +6 redirect 1277 1282 +5 tcpudpsvd_main 1782 1786 +4 d6_send_kernel_packet 272 275 +3 i2cget_main 380 382 +2 ed_main 2544 2545 +1 scan_recursive 380 378 -2 nbdclient_main 492 490 -2 hash_find 235 233 -2 cmdputs 334 332 -2 parse_command 1443 1440 -3 static.two 4 - -4 ntpd_main 1039 1035 -4 const_int_1 4 - -4 const_IPTOS_LOWDELAY 4 - -4 RCVBUF 4 - -4 ntp_init 474 469 -5 change_listen_mode 316 310 -6 uevent_main 416 409 -7 arping_main 1697 1690 -7 telnet_main 1612 1603 -9 socket_want_pktinfo 42 33 -9 setsockopt_reuseaddr 21 10 -11 setsockopt_broadcast 21 10 -11 httpd_main 772 757 -15 get_remote_transfer_fd 109 94 -15 make_new_session 503 487 -16 ftpd_main 2177 2160 -17 read_bunzip 1896 1866 -30 common_traceroute_main 4099 4058 -41 common_ping_main 1836 1783 -53 ------------------------------------------------------------------------------ (add/remove: 5/4 grow/shrink: 8/21 up/down: 111/-283) Total: -172 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h8
-rw-r--r--libbb/messages.c2
-rw-r--r--libbb/udp_io.c4
-rw-r--r--libbb/xconnect.c25
-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
-rw-r--r--util-linux/uevent.c6
16 files changed, 75 insertions, 61 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 136d4fd87..2e20706e7 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -561,6 +561,11 @@ void xlisten(int s, int backlog) FAST_FUNC;
561void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; 561void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC;
562ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 562ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
563 socklen_t tolen) FAST_FUNC; 563 socklen_t tolen) FAST_FUNC;
564
565int setsockopt_int(int fd, int level, int optname, int optval) FAST_FUNC;
566int setsockopt_1(int fd, int level, int optname) FAST_FUNC;
567int setsockopt_SOL_SOCKET_int(int fd, int optname, int optval) FAST_FUNC;
568int setsockopt_SOL_SOCKET_1(int fd, int optname) FAST_FUNC;
564/* SO_REUSEADDR allows a server to rebind to an address that is already 569/* SO_REUSEADDR allows a server to rebind to an address that is already
565 * "in use" by old connections to e.g. previous server instance which is 570 * "in use" by old connections to e.g. previous server instance which is
566 * killed or crashed. Without it bind will fail until all such connections 571 * killed or crashed. Without it bind will fail until all such connections
@@ -568,6 +573,7 @@ ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
568 * regardless of SO_REUSEADDR (unlike some other flavors of Unix). 573 * regardless of SO_REUSEADDR (unlike some other flavors of Unix).
569 * Turn it on before you call bind(). */ 574 * Turn it on before you call bind(). */
570void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */ 575void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */
576int setsockopt_keepalive(int fd) FAST_FUNC;
571int setsockopt_broadcast(int fd) FAST_FUNC; 577int setsockopt_broadcast(int fd) FAST_FUNC;
572int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC; 578int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC;
573/* NB: returns port in host byte order */ 579/* NB: returns port in host byte order */
@@ -1807,7 +1813,7 @@ extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr
1807#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) 1813#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
1808 1814
1809extern const int const_int_0; 1815extern const int const_int_0;
1810extern const int const_int_1; 1816//extern const int const_int_1;
1811 1817
1812 1818
1813/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */ 1819/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
diff --git a/libbb/messages.c b/libbb/messages.c
index fad82c9da..c1b7ba252 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -43,7 +43,7 @@ const char bb_PATH_root_path[] ALIGN1 =
43 "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH; 43 "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH;
44 44
45 45
46const int const_int_1 = 1; 46//const int const_int_1 = 1;
47/* explicitly = 0, otherwise gcc may make it a common variable 47/* explicitly = 0, otherwise gcc may make it a common variable
48 * and it will end up in bss */ 48 * and it will end up in bss */
49const int const_int_0 = 0; 49const int const_int_0 = 0;
diff --git a/libbb/udp_io.c b/libbb/udp_io.c
index 7985a9723..a32af9bd2 100644
--- a/libbb/udp_io.c
+++ b/libbb/udp_io.c
@@ -16,10 +16,10 @@ void FAST_FUNC
16socket_want_pktinfo(int fd UNUSED_PARAM) 16socket_want_pktinfo(int fd UNUSED_PARAM)
17{ 17{
18#ifdef IP_PKTINFO 18#ifdef IP_PKTINFO
19 setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &const_int_1, sizeof(int)); 19 setsockopt_1(fd, IPPROTO_IP, IP_PKTINFO);
20#endif 20#endif
21#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO) 21#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
22 setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &const_int_1, sizeof(int)); 22 setsockopt_1(fd, IPPROTO_IPV6, IPV6_PKTINFO);
23#endif 23#endif
24} 24}
25 25
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 2a96e03dc..6e78e6363 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -14,13 +14,34 @@
14#include <sys/un.h> 14#include <sys/un.h>
15#include "libbb.h" 15#include "libbb.h"
16 16
17int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval)
18{
19 return setsockopt(fd, level, optname, &optval, sizeof(int));
20}
21int FAST_FUNC setsockopt_1(int fd, int level, int optname)
22{
23 return setsockopt_int(fd, level, optname, 1);
24}
25int FAST_FUNC setsockopt_SOL_SOCKET_int(int fd, int optname, int optval)
26{
27 return setsockopt_int(fd, SOL_SOCKET, optname, optval);
28}
29int FAST_FUNC setsockopt_SOL_SOCKET_1(int fd, int optname)
30{
31 return setsockopt_SOL_SOCKET_int(fd, optname, 1);
32}
33
17void FAST_FUNC setsockopt_reuseaddr(int fd) 34void FAST_FUNC setsockopt_reuseaddr(int fd)
18{ 35{
19 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); 36 setsockopt_SOL_SOCKET_1(fd, SO_REUSEADDR);
20} 37}
21int FAST_FUNC setsockopt_broadcast(int fd) 38int FAST_FUNC setsockopt_broadcast(int fd)
22{ 39{
23 return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); 40 return setsockopt_SOL_SOCKET_1(fd, SO_BROADCAST);
41}
42int FAST_FUNC setsockopt_keepalive(int fd)
43{
44 return setsockopt_SOL_SOCKET_1(fd, SO_KEEPALIVE);
24} 45}
25 46
26#ifdef SO_BINDTODEVICE 47#ifdef SO_BINDTODEVICE
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)
357 saddr.sin_port = htons(1025); 357 saddr.sin_port = htons(1025);
358 saddr.sin_addr = dst; 358 saddr.sin_addr = dst;
359 359
360 if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1) 360 if (setsockopt_SOL_SOCKET_1(probe_fd, SO_DONTROUTE) != 0)
361 bb_perror_msg("setsockopt(%s)", "SO_DONTROUTE"); 361 bb_perror_msg("setsockopt(%s)", "SO_DONTROUTE");
362 xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); 362 xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
363 getsockname(probe_fd, (struct sockaddr *) &saddr, &alen); 363 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)
377 return remote_fd; 377 return remote_fd;
378 } 378 }
379 379
380 setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 380 setsockopt_keepalive(remote_fd);
381 return remote_fd; 381 return remote_fd;
382} 382}
383 383
@@ -1186,11 +1186,11 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1186 , SIG_IGN); 1186 , SIG_IGN);
1187 1187
1188 /* Set up options on the command socket (do we need these all? why?) */ 1188 /* Set up options on the command socket (do we need these all? why?) */
1189 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1)); 1189 setsockopt_1(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY);
1190 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 1190 setsockopt_keepalive(STDIN_FILENO);
1191 /* Telnet protocol over command link may send "urgent" data, 1191 /* Telnet protocol over command link may send "urgent" data,
1192 * we prefer it to be received in the "normal" data stream: */ 1192 * we prefer it to be received in the "normal" data stream: */
1193 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1)); 1193 setsockopt_1(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE);
1194 1194
1195 WRITE_OK(FTP_GREET); 1195 WRITE_OK(FTP_GREET);
1196 signal(SIGALRM, timeout_handler); 1196 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)
2352 continue; 2352 continue;
2353 2353
2354 /* set the KEEPALIVE option to cull dead connections */ 2354 /* set the KEEPALIVE option to cull dead connections */
2355 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 2355 setsockopt_keepalive(n);
2356 2356
2357 if (fork() == 0) { 2357 if (fork() == 0) {
2358 /* child */ 2358 /* child */
@@ -2395,7 +2395,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2395 continue; 2395 continue;
2396 2396
2397 /* set the KEEPALIVE option to cull dead connections */ 2397 /* set the KEEPALIVE option to cull dead connections */
2398 setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 2398 setsockopt_keepalive(n);
2399 2399
2400 if (vfork() == 0) { 2400 if (vfork() == 0) {
2401 /* child */ 2401 /* 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)
83 83
84 // Find and connect to server 84 // Find and connect to server
85 sock = create_and_connect_stream_or_die(host, xatou16(port)); 85 sock = create_and_connect_stream_or_die(host, xatou16(port));
86 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1)); 86 setsockopt_1(sock, IPPROTO_TCP, TCP_NODELAY);
87 87
88 // Log on to the server 88 // Log on to the server
89 xread(sock, &nbd_header, 8+8+8+4 + 124); 89 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)
863 xbind(netfd, &ouraddr->u.sa, ouraddr->len); 863 xbind(netfd, &ouraddr->u.sa, ouraddr->len);
864 } 864 }
865#if 0 865#if 0
866 setsockopt(netfd, SOL_SOCKET, SO_RCVBUF, &o_rcvbuf, sizeof o_rcvbuf); 866 setsockopt_SOL_SOCKET_int(netfd, SO_RCVBUF, o_rcvbuf);
867 setsockopt(netfd, SOL_SOCKET, SO_SNDBUF, &o_sndbuf, sizeof o_sndbuf); 867 setsockopt_SOL_SOCKET_int(netfd, SO_SNDBUF, o_sndbuf);
868#endif 868#endif
869 869
870#ifdef BLOAT 870#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 {
405}; 405};
406#define G (*ptr_to_globals) 406#define G (*ptr_to_globals)
407 407
408static const int const_IPTOS_LOWDELAY = IPTOS_LOWDELAY;
409
410 408
411#define VERB1 if (MAX_VERBOSE && G.verbose) 409#define VERB1 if (MAX_VERBOSE && G.verbose)
412#define VERB2 if (MAX_VERBOSE >= 2 && G.verbose >= 2) 410#define VERB2 if (MAX_VERBOSE >= 2 && G.verbose >= 2)
@@ -837,7 +835,7 @@ send_query_to_peer(peer_t *p)
837#if ENABLE_FEATURE_IPV6 835#if ENABLE_FEATURE_IPV6
838 if (family == AF_INET) 836 if (family == AF_INET)
839#endif 837#endif
840 setsockopt(fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY)); 838 setsockopt_int(fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
841 free(local_lsa); 839 free(local_lsa);
842 } 840 }
843 841
@@ -2186,7 +2184,7 @@ static NOINLINE void ntp_init(char **argv)
2186 xfunc_die(); 2184 xfunc_die();
2187 } 2185 }
2188 socket_want_pktinfo(G_listen_fd); 2186 socket_want_pktinfo(G_listen_fd);
2189 setsockopt(G_listen_fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY)); 2187 setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
2190 } 2188 }
2191#endif 2189#endif
2192 if (!(opts & OPT_n)) { 2190 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)
247 pkt->icmp6_type = ICMP6_ECHO_REQUEST; 247 pkt->icmp6_type = ICMP6_ECHO_REQUEST;
248 248
249 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); 249 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
250 setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); 250 setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
251 251
252 xsendto(pingsock, G.packet, DEFDATALEN + sizeof(struct icmp6_hdr), &lsa->u.sa, lsa->len); 252 xsendto(pingsock, G.packet, DEFDATALEN + sizeof(struct icmp6_hdr), &lsa->u.sa, lsa->len);
253 253
@@ -700,12 +700,12 @@ static void ping4(len_and_sockaddr *lsa)
700 /* set recv buf (needed if we can get lots of responses: flood ping, 700 /* set recv buf (needed if we can get lots of responses: flood ping,
701 * broadcast ping etc) */ 701 * broadcast ping etc) */
702 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */ 702 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
703 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); 703 setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);
704 704
705 if (opt_ttl != 0) { 705 if (opt_ttl != 0) {
706 setsockopt(pingsock, IPPROTO_IP, IP_TTL, &opt_ttl, sizeof(opt_ttl)); 706 setsockopt_int(pingsock, IPPROTO_IP, IP_TTL, opt_ttl);
707 /* above doesnt affect packets sent to bcast IP, so... */ 707 /* above doesnt affect packets sent to bcast IP, so... */
708 setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_TTL, &opt_ttl, sizeof(opt_ttl)); 708 setsockopt_int(pingsock, IPPROTO_IP, IP_MULTICAST_TTL, opt_ttl);
709 } 709 }
710 710
711 signal(SIGINT, print_stats_and_exit); 711 signal(SIGINT, print_stats_and_exit);
@@ -766,15 +766,15 @@ static void ping6(len_and_sockaddr *lsa)
766 /* set recv buf (needed if we can get lots of responses: flood ping, 766 /* set recv buf (needed if we can get lots of responses: flood ping,
767 * broadcast ping etc) */ 767 * broadcast ping etc) */
768 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */ 768 sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
769 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); 769 setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);
770 770
771 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); 771 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
772 if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2) 772 if (sockopt != 2)
773 BUG_bad_offsetof_icmp6_cksum(); 773 BUG_bad_offsetof_icmp6_cksum();
774 setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); 774 setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
775 775
776 /* request ttl info to be returned in ancillary data */ 776 /* request ttl info to be returned in ancillary data */
777 setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1)); 777 setsockopt_1(pingsock, SOL_IPV6, IPV6_HOPLIMIT);
778 778
779 if (if_index) 779 if (if_index)
780 pingaddr.sin6.sin6_scope_id = if_index; 780 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)
623 623
624 xmove_fd(create_and_connect_stream_or_die(host, port), netfd); 624 xmove_fd(create_and_connect_stream_or_die(host, port), netfd);
625 625
626 setsockopt(netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 626 setsockopt_keepalive(netfd);
627 627
628 signal(SIGINT, record_signo); 628 signal(SIGINT, record_signo);
629 629
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(
265 close_on_exec_on(fd); 265 close_on_exec_on(fd);
266 266
267 /* SO_KEEPALIVE by popular demand */ 267 /* SO_KEEPALIVE by popular demand */
268 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); 268 setsockopt_keepalive(sock);
269#if ENABLE_FEATURE_TELNETD_STANDALONE 269#if ENABLE_FEATURE_TELNETD_STANDALONE
270 ts->sockfd_read = sock; 270 ts->sockfd_read = sock;
271 ndelay_on(sock); 271 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)
473 473
474#if ENABLE_TRACEROUTE6 474#if ENABLE_TRACEROUTE6
475 if (dest_lsa->u.sa.sa_family == AF_INET6) { 475 if (dest_lsa->u.sa.sa_family == AF_INET6) {
476 res = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)); 476 res = setsockopt_int(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl);
477 if (res < 0) 477 if (res != 0)
478 bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl); 478 bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl);
479 out = outip; 479 out = outip;
480 len = packlen; 480 len = packlen;
@@ -482,8 +482,8 @@ send_probe(int seq, int ttl)
482#endif 482#endif
483 { 483 {
484#if defined IP_TTL 484#if defined IP_TTL
485 res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); 485 res = setsockopt_int(sndsock, IPPROTO_IP, IP_TTL, ttl);
486 if (res < 0) 486 if (res != 0)
487 bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl); 487 bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl);
488#endif 488#endif
489 out = outicmp; 489 out = outicmp;
@@ -902,13 +902,10 @@ common_traceroute_main(int op, char **argv)
902 if (af == AF_INET6) { 902 if (af == AF_INET6) {
903 xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock); 903 xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock);
904# ifdef IPV6_RECVPKTINFO 904# ifdef IPV6_RECVPKTINFO
905 setsockopt(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO, 905 setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO);
906 &const_int_1, sizeof(const_int_1)); 906 setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO);
907 setsockopt(rcvsock, SOL_IPV6, IPV6_2292PKTINFO,
908 &const_int_1, sizeof(const_int_1));
909# else 907# else
910 setsockopt(rcvsock, SOL_IPV6, IPV6_PKTINFO, 908 setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO);
911 &const_int_1, sizeof(const_int_1));
912# endif 909# endif
913 } else 910 } else
914#endif 911#endif
@@ -918,17 +915,14 @@ common_traceroute_main(int op, char **argv)
918 915
919#if TRACEROUTE_SO_DEBUG 916#if TRACEROUTE_SO_DEBUG
920 if (op & OPT_DEBUG) 917 if (op & OPT_DEBUG)
921 setsockopt(rcvsock, SOL_SOCKET, SO_DEBUG, 918 setsockopt_SOL_SOCKET_1(rcvsock, SO_DEBUG);
922 &const_int_1, sizeof(const_int_1));
923#endif 919#endif
924 if (op & OPT_BYPASS_ROUTE) 920 if (op & OPT_BYPASS_ROUTE)
925 setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE, 921 setsockopt_SOL_SOCKET_1(rcvsock, SO_DONTROUTE);
926 &const_int_1, sizeof(const_int_1));
927 922
928#if ENABLE_TRACEROUTE6 923#if ENABLE_TRACEROUTE6
929 if (af == AF_INET6) { 924 if (af == AF_INET6) {
930 static const int two = 2; 925 if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0)
931 if (setsockopt(rcvsock, SOL_RAW, IPV6_CHECKSUM, &two, sizeof(two)) < 0)
932 bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM"); 926 bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM");
933 xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock); 927 xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock);
934 } else 928 } else
@@ -966,28 +960,25 @@ common_traceroute_main(int op, char **argv)
966 } 960 }
967 961
968#ifdef SO_SNDBUF 962#ifdef SO_SNDBUF
969 if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) { 963 if (setsockopt_SOL_SOCKET_int(sndsock, SO_SNDBUF, packlen) != 0) {
970 bb_perror_msg_and_die("SO_SNDBUF"); 964 bb_perror_msg_and_die("setsockopt(%s)", "SO_SNDBUF");
971 } 965 }
972#endif 966#endif
973#ifdef IP_TOS 967#ifdef IP_TOS
974 if ((op & OPT_TOS) && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) { 968 if ((op & OPT_TOS) && setsockopt_int(sndsock, IPPROTO_IP, IP_TOS, tos) != 0) {
975 bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos); 969 bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos);
976 } 970 }
977#endif 971#endif
978#ifdef IP_DONTFRAG 972#ifdef IP_DONTFRAG
979 if (op & OPT_DONT_FRAGMNT) 973 if (op & OPT_DONT_FRAGMNT)
980 setsockopt(sndsock, IPPROTO_IP, IP_DONTFRAG, 974 setsockopt_1(sndsock, IPPROTO_IP, IP_DONTFRAG);
981 &const_int_1, sizeof(const_int_1));
982#endif 975#endif
983#if TRACEROUTE_SO_DEBUG 976#if TRACEROUTE_SO_DEBUG
984 if (op & OPT_DEBUG) 977 if (op & OPT_DEBUG)
985 setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, 978 setsockopt_SOL_SOCKET_1(sndsock, SO_DEBUG);
986 &const_int_1, sizeof(const_int_1));
987#endif 979#endif
988 if (op & OPT_BYPASS_ROUTE) 980 if (op & OPT_BYPASS_ROUTE)
989 setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, 981 setsockopt_SOL_SOCKET_1(sndsock, SO_DONTROUTE);
990 &const_int_1, sizeof(const_int_1));
991 982
992 outip = xzalloc(packlen); 983 outip = xzalloc(packlen);
993 984
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)
1043 } 1043 }
1044#endif 1044#endif
1045 1045
1046 if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, 1046 if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
1047 &const_int_1, sizeof(int)) < 0
1048 ) {
1049 if (errno != ENOPROTOOPT) 1047 if (errno != ENOPROTOOPT)
1050 log1("Can't set PACKET_AUXDATA on raw socket"); 1048 log1("Can't set PACKET_AUXDATA on raw socket");
1051 } 1049 }
diff --git a/util-linux/uevent.c b/util-linux/uevent.c
index fb98b4845..514a9e934 100644
--- a/util-linux/uevent.c
+++ b/util-linux/uevent.c
@@ -37,7 +37,7 @@ enum {
37#ifndef SO_RCVBUFFORCE 37#ifndef SO_RCVBUFFORCE
38#define SO_RCVBUFFORCE 33 38#define SO_RCVBUFFORCE 33
39#endif 39#endif
40static const int RCVBUF = 2 * 1024 * 1024; 40enum { RCVBUF = 2 * 1024 * 1024 };
41 41
42int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 42int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
43int uevent_main(int argc UNUSED_PARAM, char **argv) 43int uevent_main(int argc UNUSED_PARAM, char **argv)
@@ -63,8 +63,8 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
63 // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' 63 // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
64 // 64 //
65 // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl 65 // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl
66 setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &RCVBUF, sizeof(RCVBUF)); 66 setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, RCVBUF);
67 setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &RCVBUF, sizeof(RCVBUF)); 67 setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, RCVBUF);
68 if (0) { 68 if (0) {
69 int z; 69 int z;
70 socklen_t zl = sizeof(z); 70 socklen_t zl = sizeof(z);