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

Richard Sharpe realrichardsharpe at gmail.com
Fri Apr 22 01:56:50 UTC 2016


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:

@@ -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
(何以解憂?唯有杜康。--曹操)



More information about the samba-technical mailing list