Make this into a function by itself and adjust its arguments so that
when we support multiple sockets (for multiple addresses so that we
can have multiple AFs) we can just call it for each one.
No functional change.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
-static void udp_phase_hook(void *sst, uint32_t new_phase)
+static void udp_make_socket(struct udp *st, struct udp *us)
- struct udp *st=sst;
- union iaddr addr;
-
- st->fd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (st->fd<0) {
+ const union iaddr *addr=&us->addr;
+ us->fd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (us->fd<0) {
fatal_perror("udp (%s:%d): socket",st->loc.file,st->loc.line);
}
fatal_perror("udp (%s:%d): socket",st->loc.file,st->loc.line);
}
- if (fcntl(st->fd, F_SETFL, fcntl(st->fd, F_GETFL)|O_NONBLOCK)==-1) {
+ if (fcntl(us->fd, F_SETFL, fcntl(us->fd, F_GETFL)|O_NONBLOCK)==-1) {
fatal_perror("udp (%s:%d): fcntl(set O_NONBLOCK)",
st->loc.file,st->loc.line);
}
fatal_perror("udp (%s:%d): fcntl(set O_NONBLOCK)",
st->loc.file,st->loc.line);
}
if (st->authbind) {
pid_t c;
int status;
if (st->authbind) {
pid_t c;
int status;
}
if (c==0) {
char *argv[4], addrstr[9], portstr[5];
}
if (c==0) {
char *argv[4], addrstr[9], portstr[5];
- switch (addr.sa.sa_family) {
+ switch (addr->sa.sa_family) {
- sprintf(addrstr,"%08lX",(long)addr.sin.sin_addr.s_addr);
- sprintf(portstr,"%04X",addr.sin.sin_port);
+ sprintf(addrstr,"%08lX",(long)addr->sin.sin_addr.s_addr);
+ sprintf(portstr,"%04X",addr->sin.sin_port);
break;
default:
fatal("udp (%s:%d): unsupported address family for authbind",
break;
default:
fatal("udp (%s:%d): unsupported address family for authbind",
argv[1]=addrstr;
argv[2]=portstr;
argv[3]=NULL;
argv[1]=addrstr;
argv[2]=portstr;
argv[3]=NULL;
execvp(st->authbind,argv);
_exit(255);
}
execvp(st->authbind,argv);
_exit(255);
}
st->loc.line, WEXITSTATUS(status));
}
} else {
st->loc.line, WEXITSTATUS(status));
}
} else {
- if (bind(st->fd, (struct sockaddr *)&addr, sizeof(addr))!=0) {
+ if (bind(us->fd, &addr->sa, iaddr_socklen(addr))!=0) {
fatal_perror("udp (%s:%d): bind",st->loc.file,st->loc.line);
}
}
fatal_perror("udp (%s:%d): bind",st->loc.file,st->loc.line);
}
}
+static void udp_phase_hook(void *sst, uint32_t new_phase)
+{
+ struct udp *st=sst;
+ udp_make_socket(st,st);
register_for_poll(st,udp_beforepoll,udp_afterpoll,1,"udp");
}
register_for_poll(st,udp_beforepoll,udp_afterpoll,1,"udp");
}