summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0bf142d)
Only it checks the address family first. This will be important because
IPv6 sockets /do/ need a little special initialization.
+static int initsock(int fd, int af)
+{
+ switch (af) {
+ case AF_INET: break;
+ default: abort();
+ }
+ return (0);
+}
+
static const char *addrstr(const addr *a)
{
static char buf[128];
static const char *addrstr(const addr *a)
{
static char buf[128];
if ((fd = socket(a->sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0 ||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) ||
if ((fd = socket(a->sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0 ||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) ||
+ initsock(fd, a->sa.sa_family) ||
bind(fd, &a->sa, addrsz(a)) ||
listen(fd, 1) || nonblockify(fd) || cloexec(fd))
die(1, "couldn't set up listening socket: %s", strerror(errno));
bind(fd, &a->sa, addrsz(a)) ||
listen(fd, 1) || nonblockify(fd) || cloexec(fd))
die(1, "couldn't set up listening socket: %s", strerror(errno));
for (ai = ailist; ai; ai = ai->ai_next) {
if ((fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
for (ai = ailist; ai; ai = ai->ai_next) {
if ((fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
+ !initsock(fd, ai->ai_family) &&
(!DA_LEN(&bindhosts) ||
!bind(fd, &bindaddr.sa, addrsz(&bindaddr))) &&
!connect(fd, ai->ai_addr, ai->ai_addrlen))
(!DA_LEN(&bindhosts) ||
!bind(fd, &bindaddr.sa, addrsz(&bindaddr))) &&
!connect(fd, ai->ai_addr, ai->ai_addrlen))
aihint.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
parseaddr(&aihint, argv[optind], 0, paf_parse, &ailist); ai = ailist;
if ((fd_udp = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP)) < 0 ||
aihint.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
parseaddr(&aihint, argv[optind], 0, paf_parse, &ailist); ai = ailist;
if ((fd_udp = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP)) < 0 ||
+ initsock(fd_udp, ai->ai_family) ||
nonblockify(fd_udp) || cloexec(fd_udp) ||
setsockopt(fd_udp, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) ||
setsockopt(fd_udp, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len)) ||
nonblockify(fd_udp) || cloexec(fd_udp) ||
setsockopt(fd_udp, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) ||
setsockopt(fd_udp, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len)) ||