-
- st=safe_malloc(sizeof(*st),"udp_apply(st)");
- st->loc=loc;
- st->cl.description="udp";
- st->cl.type=CL_COMM;
- st->cl.apply=NULL;
- st->cl.interface=&st->ops;
- st->ops.st=st;
- st->ops.request_notify=request_notify;
- st->ops.release_notify=release_notify;
- st->ops.sendmsg=udp_sendmsg;
- st->ops.addr_to_string=addr_to_string;
- st->port=0;
- st->use_proxy=False;
-
- i=list_elem(args,0);
- if (!i || i->type!=t_dict) {
- cfgfatal(st->loc,"udp","first argument must be a dictionary\n");
+ int i;
+
+ COMM_APPLY(st,&st->uc.cc,udp_,"udp",loc);
+ COMM_APPLY_STANDARD(st,&st->uc.cc,"udp",args);
+ UDP_APPLY_STANDARD(st,&st->uc,"udp");
+
+ struct udpcommon *uc=&st->uc;
+ struct udpsocks *socks=&st->socks;
+ struct commcommon *cc=&uc->cc;
+
+ union iaddr defaultaddrs[] = {
+#ifdef CONFIG_IPV6
+ { .sin6 = { .sin6_family=AF_INET6,
+ .sin6_port=htons(uc->port),
+ .sin6_addr=IN6ADDR_ANY_INIT } },
+#endif
+ { .sin = { .sin_family=AF_INET,
+ .sin_port=htons(uc->port),
+ .sin_addr= { .s_addr=INADDR_ANY } } }
+ };
+
+ caddrl=dict_lookup(d,"address");
+ socks->n_socks=caddrl ? list_length(caddrl) : (int)ARRAY_SIZE(defaultaddrs);
+ if (socks->n_socks<=0 || socks->n_socks>UDP_MAX_SOCKETS)
+ cfgfatal(cc->loc,"udp","`address' must be 1..%d addresses",
+ UDP_MAX_SOCKETS);
+
+ for (i=0; i<socks->n_socks; i++) {
+ struct udpsock *us=&socks->socks[i];
+ if (!list_length(caddrl)) {
+ us->addr=defaultaddrs[i];
+ } else {
+ string_item_to_iaddr(list_elem(caddrl,i),uc->port,&us->addr,"udp");
+ }
+ us->fd=-1;