build: Remove all references to libuuid
[sfrench/samba-autobuild/.git] / lib / addns / dnssock.c
index 7c8bd418e5765e5dc97ccd3e85a1c0dfb8aca1f9..9e769097ba961543e92ce9ec886ed378344fb0ee 100644 (file)
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "replace.h"
 #include "dns.h"
 #include <sys/time.h>
 #include <unistd.h>
 #include "dns.h"
 #include <sys/time.h>
 #include <unistd.h>
+#include "system/select.h"
 
 static int destroy_dns_connection(struct dns_connection *conn)
 {
 
 static int destroy_dns_connection(struct dns_connection *conn)
 {
@@ -103,7 +105,7 @@ static DNS_ERROR dns_udp_open( const char *nameserver,
                }
                memcpy( &ulAddress, pHost->h_addr, pHost->h_length );
        }
                }
                memcpy( &ulAddress, pHost->h_addr, pHost->h_length );
        }
-       
+
        /* Create a socket for sending data */
 
        conn->s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
        /* Create a socket for sending data */
 
        conn->s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
@@ -143,7 +145,7 @@ DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
        case DNS_UDP:
                return dns_udp_open( nameserver, mem_ctx, conn );
        }
        case DNS_UDP:
                return dns_udp_open( nameserver, mem_ctx, conn );
        }
-       
+
        return ERROR_DNS_INVALID_PARAMETER;
 }
 
        return ERROR_DNS_INVALID_PARAMETER;
 }
 
@@ -212,21 +214,17 @@ DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf)
 static DNS_ERROR read_all(int fd, uint8 *data, size_t len)
 {
        size_t total = 0;
 static DNS_ERROR read_all(int fd, uint8 *data, size_t len)
 {
        size_t total = 0;
-       fd_set rfds;
-       struct timeval tv;
 
        while (total < len) {
 
        while (total < len) {
+               struct pollfd pfd;
                ssize_t ret;
                int fd_ready;
                ssize_t ret;
                int fd_ready;
-               
-               FD_ZERO( &rfds );
-               FD_SET( fd, &rfds );
-
-               /* 10 second timeout */
-               tv.tv_sec = 10;
-               tv.tv_usec = 0;
-               
-               fd_ready = select( fd+1, &rfds, NULL, NULL, &tv );
+
+               ZERO_STRUCT(pfd);
+               pfd.fd = fd;
+               pfd.events = POLLIN|POLLHUP;
+
+               fd_ready = poll(&pfd, 1, 10000);
                if ( fd_ready == 0 ) {
                        /* read timeout */
                        return ERROR_DNS_SOCKET_ERROR;
                if ( fd_ready == 0 ) {
                        /* read timeout */
                        return ERROR_DNS_SOCKET_ERROR;
@@ -252,7 +250,7 @@ static DNS_ERROR dns_receive_tcp(TALLOC_CTX *mem_ctx,
        DNS_ERROR err;
        uint16 len;
 
        DNS_ERROR err;
        uint16 len;
 
-       if (!(buf = TALLOC_ZERO_P(mem_ctx, struct dns_buffer))) {
+       if (!(buf = talloc_zero(mem_ctx, struct dns_buffer))) {
                return ERROR_DNS_NO_MEMORY;
        }
 
                return ERROR_DNS_NO_MEMORY;
        }
 
@@ -264,7 +262,7 @@ static DNS_ERROR dns_receive_tcp(TALLOC_CTX *mem_ctx,
        buf->size = ntohs(len);
 
        if (buf->size) {
        buf->size = ntohs(len);
 
        if (buf->size) {
-               if (!(buf->data = TALLOC_ARRAY(buf, uint8, buf->size))) {
+               if (!(buf->data = talloc_array(buf, uint8, buf->size))) {
                        TALLOC_FREE(buf);
                        return ERROR_DNS_NO_MEMORY;
                }
                        TALLOC_FREE(buf);
                        return ERROR_DNS_NO_MEMORY;
                }
@@ -289,7 +287,7 @@ static DNS_ERROR dns_receive_udp(TALLOC_CTX *mem_ctx,
        struct dns_buffer *buf;
        ssize_t received;
 
        struct dns_buffer *buf;
        ssize_t received;
 
-       if (!(buf = TALLOC_ZERO_P(mem_ctx, struct dns_buffer))) {
+       if (!(buf = talloc_zero(mem_ctx, struct dns_buffer))) {
                return ERROR_DNS_NO_MEMORY;
        }
 
                return ERROR_DNS_NO_MEMORY;
        }
 
@@ -297,7 +295,7 @@ static DNS_ERROR dns_receive_udp(TALLOC_CTX *mem_ctx,
         * UDP based DNS can only be 512 bytes
         */
 
         * UDP based DNS can only be 512 bytes
         */
 
-       if (!(buf->data = TALLOC_ARRAY(buf, uint8, 512))) {
+       if (!(buf->data = talloc_array(buf, uint8, 512))) {
                TALLOC_FREE(buf);
                return ERROR_DNS_NO_MEMORY;
        }
                TALLOC_FREE(buf);
                return ERROR_DNS_NO_MEMORY;
        }
@@ -342,7 +340,7 @@ DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
        struct dns_buffer *buf = NULL;
        DNS_ERROR err;
 
        struct dns_buffer *buf = NULL;
        DNS_ERROR err;
 
-       err = dns_marshall_request(conn, req, &buf);
+       err = dns_marshall_request(mem_ctx, req, &buf);
        if (!ERR_DNS_IS_OK(err)) goto error;
 
        err = dns_send(conn, buf);
        if (!ERR_DNS_IS_OK(err)) goto error;
 
        err = dns_send(conn, buf);