- if (fd == ads->udpsocket) {
- for (;;) {
- udpaddrlen= sizeof(udpaddr);
- r= recvfrom(ads->udpsocket,udpbuf,sizeof(udpbuf),0,
- (struct sockaddr*)&udpaddr,&udpaddrlen);
- if (r<0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) { r= 0; goto xit; }
- if (errno == EINTR) continue;
- if (errno_resources(errno)) { r= errno; goto xit; }
- adns__warn(ads,-1,0,"datagram receive error: %s",strerror(errno));
- r= 0; goto xit;
- }
- if (udpaddrlen != sizeof(udpaddr)) {
- adns__diag(ads,-1,0,"datagram received with wrong address length %d"
- " (expected %lu)", udpaddrlen,
- (unsigned long)sizeof(udpaddr));
- continue;
- }
- if (udpaddr.sin_family != AF_INET) {
- adns__diag(ads,-1,0,"datagram received with wrong protocol family"
- " %u (expected %u)",udpaddr.sin_family,AF_INET);
- continue;
- }
- if (ntohs(udpaddr.sin_port) != DNS_PORT) {
- adns__diag(ads,-1,0,"datagram received from wrong port %u (expected %u)",
- ntohs(udpaddr.sin_port),DNS_PORT);
- continue;
- }
- for (serv= 0;
- serv < ads->nservers &&
- ads->servers[serv].addr.s_addr != udpaddr.sin_addr.s_addr;
- serv++);
- if (serv >= ads->nservers) {
- adns__warn(ads,-1,0,"datagram received from unknown nameserver %s",
- inet_ntoa(udpaddr.sin_addr));
- continue;
+ for (i=0; i<ads->nudp; i++) {
+ udp= &ads->udpsocket[i];
+ if (fd == udp->fd) {
+ for (;;) {
+ udpaddrlen= sizeof(udpaddr);
+ r= recvfrom(fd,udpbuf,sizeof(udpbuf),0, &udpaddr.sa,&udpaddrlen);
+ if (r<0) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) { r= 0; goto xit; }
+ if (errno == EINTR) continue;
+ if (errno_resources(errno)) { r= errno; goto xit; }
+ adns__warn(ads,-1,0,"datagram receive error: %s",strerror(errno));
+ r= 0; goto xit;
+ }
+ for (serv= 0;
+ serv < ads->nservers &&
+ !adns__sockaddr_equal_p(&udpaddr.sa,
+ &ads->servers[serv].addr.sa);
+ serv++);
+ if (serv >= ads->nservers) {
+ adns__warn(ads,-1,0,"datagram received from unknown nameserver %s",
+ adns__sockaddr_ntoa(&udpaddr.sa, addrbuf));
+ continue;
+ }
+ adns__procdgram(ads,udpbuf,r,serv,0,*now);