diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-09-10 14:27:29 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2007-09-10 14:27:29 +1000 |
commit | f3ae1cdb0262bacada40329d3a7c8f64411fc06a (patch) | |
tree | 60b2dddad9c6209b5651d574c8e60713981438e5 /ctdb/common/system_linux.c | |
parent | 70ec39b1b13b76c470e4394be760178b35ea94e0 (diff) | |
download | samba-f3ae1cdb0262bacada40329d3a7c8f64411fc06a.tar.gz samba-f3ae1cdb0262bacada40329d3a7c8f64411fc06a.tar.xz samba-f3ae1cdb0262bacada40329d3a7c8f64411fc06a.zip |
- use struct sockaddr_in more consistently instead of string addresses
- allow for public_address lines with a defaulting interface
(This used to be ctdb commit 29cb760f76e639a0f2ce1d553645a9dc26ee09e5)
Diffstat (limited to 'ctdb/common/system_linux.c')
-rw-r--r-- | ctdb/common/system_linux.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index fc94bd14ee..82a6575bab 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -246,9 +246,8 @@ int ctdb_sys_send_tcp(int s, ifname, if non-NULL, will return the name of the interface this ip is tied to */ -bool ctdb_sys_have_ip(const char *ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname) +bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname) { - struct sockaddr_in sin; struct ifreq *ifr = NULL; struct ifconf ifc; int s, i, num_ifs; @@ -261,14 +260,12 @@ bool ctdb_sys_have_ip(const char *ip, bool *is_loopback, TALLOC_CTX *mem_ctx, ch *ifname = NULL; } - sin.sin_port = 0; - inet_aton(ip, &sin.sin_addr); - sin.sin_family = AF_INET; + ip.sin_port = 0; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { return false; } - ret = bind(s, (struct sockaddr *)&sin, sizeof(sin)); + ret = bind(s, (struct sockaddr *)&ip, sizeof(ip)); if (ret) { goto finished; } @@ -305,7 +302,7 @@ bool ctdb_sys_have_ip(const char *ip, bool *is_loopback, TALLOC_CTX *mem_ctx, ch } /* this is not the interface you are looking for */ - if(strcmp(inet_ntoa(sa->sin_addr), ip)){ + if (!ctdb_same_ip(sa, &ip)) { continue; } @@ -320,7 +317,7 @@ bool ctdb_sys_have_ip(const char *ip, bool *is_loopback, TALLOC_CTX *mem_ctx, ch } /* was this ip tied to a loopback interface ? */ - if(ifr[i].ifr_flags & IFF_LOOPBACK) { + if (ifr[i].ifr_flags & IFF_LOOPBACK) { if (is_loopback != NULL) { *is_loopback = true; } |