]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
support hostnames for node names
authorAndrew Tridgell <tridge@samba.org>
Tue, 20 Feb 2007 02:22:18 +0000 (13:22 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 20 Feb 2007 02:22:18 +0000 (13:22 +1100)
(This used to be ctdb commit 5c45b51ec42cdbadce7870b47b765a79d8d41b8b)

ctdb/tcp/tcp_connect.c

index e828bb7cbba2bb6a546465311eccce927213ce19..0f7d617084c4c33f5c5f137a01ccff7b5eb3e175 100644 (file)
@@ -69,6 +69,22 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
        }
 }
 
+
+static int ctdb_tcp_get_address(struct ctdb_context *ctdb,
+                               const char *address, struct in_addr *addr)
+{
+       if (inet_pton(AF_INET, address, addr) <= 0) {
+               struct hostent *he = gethostbyname(address);
+               if (he == NULL || he->h_length > sizeof(*addr)) {
+                       ctdb_set_error(ctdb, "invalid nework address '%s'\n", 
+                                      address);
+                       return -1;
+               }
+               memcpy(addr, he->h_addr, he->h_length);
+       }
+       return 0;
+}
+
 /*
   called when we should try and establish a tcp connection to a node
 */
@@ -85,7 +101,9 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
 
        set_nonblocking(tnode->fd);
 
-       inet_pton(AF_INET, node->address.address, &sock_out.sin_addr);
+       if (ctdb_tcp_get_address(ctdb, node->address.address, &sock_out.sin_addr) != 0) {
+               return;
+       }
        sock_out.sin_port = htons(node->address.port);
        sock_out.sin_family = PF_INET;
        
@@ -159,7 +177,9 @@ int ctdb_tcp_listen(struct ctdb_context *ctdb)
 
         sock.sin_port = htons(ctdb->address.port);
         sock.sin_family = PF_INET;
-       inet_pton(AF_INET, ctdb->address.address, &sock.sin_addr);
+       if (ctdb_tcp_get_address(ctdb, ctdb->address.address, &sock.sin_addr) != 0) {
+               return -1;
+       }
 
         ctcp->listen_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
         if (ctcp->listen_fd == -1) {