+static void udp_phase_hook(void *sst, uint32_t new_phase)
+{
+ struct udp *st=sst;
+ struct sockaddr_in addr;
+
+ st->fd=socket(AF_INET, SOCK_DGRAM, 0);
+ if (st->fd<0) {
+ 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) {
+ fatal_perror("udp (%s:%d): fcntl(set O_NONBLOCK)",
+ st->loc.file,st->loc.line);
+ }
+ if (fcntl(st->fd, F_SETFD, FD_CLOEXEC)==-1) {
+ fatal_perror("udp (%s:%d): fcntl(set FD_CLOEXEC)",
+ st->loc.file,st->loc.line);
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family=AF_INET;
+ addr.sin_port=htons(st->port);
+ if (bind(st->fd, (struct sockaddr *)&addr, sizeof(addr))!=0) {
+ fatal_perror("udp (%s:%d): bind",st->loc.file,st->loc.line);
+ }
+
+ register_for_poll(st,udp_beforepoll,udp_afterpoll,1,"udp");
+}
+