Rev 61: support hostnames for node names in
http://samba.org/~tridge/ctdb
tridge at samba.org
tridge at samba.org
Tue Feb 20 02:22:18 GMT 2007
------------------------------------------------------------
revno: 61
revision-id: tridge at samba.org-20070220022218-j14ntnf27hhsxn8h
parent: tridge at samba.org-20070216034827-uoannnycm4q1aojr
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Tue 2007-02-20 13:22:18 +1100
message:
support hostnames for node names
modified:
tcp/tcp_connect.c tcp_connect.c-20061128004937-x70q1cu5xzg5g2tm-1
=== modified file 'tcp/tcp_connect.c'
--- a/tcp/tcp_connect.c 2007-01-23 00:38:45 +0000
+++ b/tcp/tcp_connect.c 2007-02-20 02:22:18 +0000
@@ -69,6 +69,22 @@
}
}
+
+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 @@
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 @@
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) {
More information about the samba-cvs
mailing list