void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC;
ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
socklen_t tolen) FAST_FUNC;
+
+int setsockopt_int(int fd, int level, int optname, int optval) FAST_FUNC;
+int setsockopt_1(int fd, int level, int optname) FAST_FUNC;
+int setsockopt_SOL_SOCKET_int(int fd, int optname, int optval) FAST_FUNC;
+int setsockopt_SOL_SOCKET_1(int fd, int optname) FAST_FUNC;
/* SO_REUSEADDR allows a server to rebind to an address that is already
* "in use" by old connections to e.g. previous server instance which is
* killed or crashed. Without it bind will fail until all such connections
* regardless of SO_REUSEADDR (unlike some other flavors of Unix).
* Turn it on before you call bind(). */
void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */
+int setsockopt_keepalive(int fd) FAST_FUNC;
int setsockopt_broadcast(int fd) FAST_FUNC;
int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC;
/* NB: returns port in host byte order */
#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
extern const int const_int_0;
-extern const int const_int_1;
+//extern const int const_int_1;
/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
"PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH;
-const int const_int_1 = 1;
+//const int const_int_1 = 1;
/* explicitly = 0, otherwise gcc may make it a common variable
* and it will end up in bss */
const int const_int_0 = 0;
socket_want_pktinfo(int fd UNUSED_PARAM)
{
#ifdef IP_PKTINFO
- setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &const_int_1, sizeof(int));
+ setsockopt_1(fd, IPPROTO_IP, IP_PKTINFO);
#endif
#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
- setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &const_int_1, sizeof(int));
+ setsockopt_1(fd, IPPROTO_IPV6, IPV6_PKTINFO);
#endif
}
#include <sys/un.h>
#include "libbb.h"
+int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval)
+{
+ return setsockopt(fd, level, optname, &optval, sizeof(int));
+}
+int FAST_FUNC setsockopt_1(int fd, int level, int optname)
+{
+ return setsockopt_int(fd, level, optname, 1);
+}
+int FAST_FUNC setsockopt_SOL_SOCKET_int(int fd, int optname, int optval)
+{
+ return setsockopt_int(fd, SOL_SOCKET, optname, optval);
+}
+int FAST_FUNC setsockopt_SOL_SOCKET_1(int fd, int optname)
+{
+ return setsockopt_SOL_SOCKET_int(fd, optname, 1);
+}
+
void FAST_FUNC setsockopt_reuseaddr(int fd)
{
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1));
+ setsockopt_SOL_SOCKET_1(fd, SO_REUSEADDR);
}
int FAST_FUNC setsockopt_broadcast(int fd)
{
- return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1));
+ return setsockopt_SOL_SOCKET_1(fd, SO_BROADCAST);
+}
+int FAST_FUNC setsockopt_keepalive(int fd)
+{
+ return setsockopt_SOL_SOCKET_1(fd, SO_KEEPALIVE);
}
#ifdef SO_BINDTODEVICE
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);
return remote_fd;
}
- setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
+ setsockopt_keepalive(remote_fd);
return remote_fd;
}
, 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);
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 */
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 */
// 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);
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
};
#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)
#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);
}
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)) {
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);
/* 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);
/* 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;
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);
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);
#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;
#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;
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
#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
}
#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);
}
#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");
}
#ifndef SO_RCVBUFFORCE
#define SO_RCVBUFFORCE 33
#endif
-static const int RCVBUF = 2 * 1024 * 1024;
+enum { RCVBUF = 2 * 1024 * 1024 };
int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uevent_main(int argc UNUSED_PARAM, char **argv)
// find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
//
// SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &RCVBUF, sizeof(RCVBUF));
- setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &RCVBUF, sizeof(RCVBUF));
+ setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, RCVBUF);
+ setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, RCVBUF);
if (0) {
int z;
socklen_t zl = sizeof(z);