There is a bunch of duplicated code in lib/addns/dnssock.c ...

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Apr 22 12:42:20 UTC 2016


On Thu, Apr 21, 2016 at 06:56:50PM -0700, Richard Sharpe wrote:
> Hi folks,
> 
> The duplicated code is in dns_tcp_open and dns_udp_open and it is
> almost completely duplicated.
> 
> Here is a diff of the important parts of the code:

Would it be possible to send this as git-format-patch? It looks
correct, but git makes review a bit easier.

Thanks,

Volker

> 
> @@ -1,12 +1,12 @@
>   memset(&hints, 0, sizeof(struct addrinfo));
>   hints.ai_family = AF_UNSPEC;
> - hints.ai_socktype = SOCK_STREAM;
> + hints.ai_socktype = SOCK_DGRAM;
>   hints.ai_flags = 0;
> - hints.ai_protocol = IPPROTO_TCP;
> + hints.ai_protocol = IPPROTO_UDP;
> 
>   ret = getaddrinfo(nameserver, service, &hints, &ai_result);
>   if (ret != 0) {
> - DEBUG(1,("dns_tcp_open: getaddrinfo: %s\n", gai_strerror(ret)));
> + DEBUG(1,("dns_ucp_open:getaddrinfo: %s\n", gai_strerror(ret)));
>   TALLOC_FREE(conn);
>   return ERROR_DNS_INVALID_NAME_SERVER;
>   }
> @@ -18,9 +18,7 @@
>   if (conn->s == -1) {
>   continue;
>   }
> - do {
> - ret = connect(conn->s, rp->ai_addr, rp->ai_addrlen);
> - } while ((ret == -1) && (errno == EINTR));
> + ret = connect(conn->s, rp->ai_addr, rp->ai_addrlen);
>   if (ret != -1) {
>   /* Successful connect */
>   break;
> 
> What is interesting is that dns_udp_open does not protect against
> EINTR even though it is a possibility.
> 
> The duplicate code could be turned into a helper function. Is it worth it?
> 
> -- 
> Regards,
> Richard Sharpe
> (何以解憂?唯有杜康。--曹操)
> 

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de



More information about the samba-technical mailing list