diff options
author | Ronnie Sahlberg <sahlberg@ronnie> | 2007-09-13 14:28:18 +1000 |
---|---|---|
committer | Ronnie Sahlberg <sahlberg@ronnie> | 2007-09-13 14:28:18 +1000 |
commit | ab1c8c074e851d99f4391490bd2dff5b8883b5ae (patch) | |
tree | 5113b21b7c5e2e356b9a63c077a1424fc0694eda /ctdb/common/system_linux.c | |
parent | 536d3934529c9b3e576fc79b861e2d680af64884 (diff) | |
parent | 9d50595b8a786c87436e2d09c2513a993f0f5d36 (diff) | |
download | samba-ab1c8c074e851d99f4391490bd2dff5b8883b5ae.tar.gz samba-ab1c8c074e851d99f4391490bd2dff5b8883b5ae.tar.xz samba-ab1c8c074e851d99f4391490bd2dff5b8883b5ae.zip |
merge from tridge
(This used to be ctdb commit eda3caa77be352967a41ff9bddda5296c94797a9)
Diffstat (limited to 'ctdb/common/system_linux.c')
-rw-r--r-- | ctdb/common/system_linux.c | 83 |
1 files changed, 2 insertions, 81 deletions
diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index 82a6575bab..bd44bd75b4 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -241,100 +241,21 @@ int ctdb_sys_send_tcp(int s, we try to bind to it, and if that fails then we don't have that IP on an interface - if is_loopback is specified it will also return whether the ip address - is attached to the loopback interface or not ifname, if non-NULL, will return the name of the interface this ip is tied to */ -bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname) +bool ctdb_sys_have_ip(struct sockaddr_in ip) { - struct ifreq *ifr = NULL; - struct ifconf ifc; - int s, i, num_ifs; + int s; int ret; - if (is_loopback) { - *is_loopback = false; - } - if (*ifname) { - *ifname = NULL; - } - ip.sin_port = 0; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { return false; } ret = bind(s, (struct sockaddr *)&ip, sizeof(ip)); - if (ret) { - goto finished; - } - - - /* find out how much space we need to store the interface details */ - ifc.ifc_len = 0; - ifc.ifc_req = NULL; - ret = ioctl(s, SIOCGIFCONF, &ifc); - if (ret) { - DEBUG(0,(__location__ " ioctl to read interface list failed\n")); - goto finished; - } - - ifr = talloc_size(mem_ctx, ifc.ifc_len); - - /* get a list of all interface names and addresses */ - ifc.ifc_req = ifr; - ret = ioctl(s, SIOCGIFCONF, &ifc); - if (ret) { - DEBUG(0,(__location__ " ioctl to read interface list failed\n")); - goto finished; - } - /* loop over all interfaces and search for the one matching ip */ - num_ifs = ifc.ifc_len/sizeof(struct ifreq); - for (i=0; i<num_ifs;i++) { - struct sockaddr_in *sa; - - /* we only care bout ipv4 addresses */ - sa = (struct sockaddr_in *)&ifr[i].ifr_addr; - if (sa->sin_family != AF_INET) { - continue; - } - - /* this is not the interface you are looking for */ - if (!ctdb_same_ip(sa, &ip)) { - continue; - } - - /* this is the ifr entry for this interface/address - read the interface flags so we can tell if it is - loopback or not - */ - ret = ioctl(s, SIOCGIFFLAGS, &ifr[i]); - if (ret) { - DEBUG(0,(__location__ " failed to read interface flags for interface %s\n", ifr[i].ifr_name)); - goto finished; - } - - /* was this ip tied to a loopback interface ? */ - if (ifr[i].ifr_flags & IFF_LOOPBACK) { - if (is_loopback != NULL) { - *is_loopback = true; - } - } - - if (ifname) { - *ifname = talloc_asprintf(mem_ctx, "%s", ifr[i].ifr_name); - } - - /* if we got this far, we have found our interface so we can - exit the loop. - */ - break; - } - -finished: - talloc_free(ifr); close(s); return ret == 0; } |