restructured

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3219 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1997-08-28 01:28:07 +00:00
parent 0becc7408b
commit e2c0e660f2

View File

@@ -98,6 +98,7 @@ find_all_addresses (krb5_addresses *res, int loop)
struct ifconf ifconf; struct ifconf ifconf;
int num, j; int num, j;
char *p; char *p;
size_t sz;
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) if (fd < 0)
@@ -117,7 +118,9 @@ find_all_addresses (krb5_addresses *res, int loop)
j = 0; j = 0;
ifreq.ifr_name[0] = '\0'; ifreq.ifr_name[0] = '\0';
for (p = ifconf.ifc_buf; p < ifconf.ifc_buf + ifconf.ifc_len;) { for (p = ifconf.ifc_buf;
p < ifconf.ifc_buf + ifconf.ifc_len;
p += sz) {
struct ifreq *ifr = (struct ifreq *)p; struct ifreq *ifr = (struct ifreq *)p;
/* This is somewhat kludgy, but it seems to work. */ /* This is somewhat kludgy, but it seems to work. */
@@ -127,19 +130,30 @@ find_all_addresses (krb5_addresses *res, int loop)
if(ifr->ifr_addr.sa_len) if(ifr->ifr_addr.sa_len)
sz = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len; sz = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
#endif #endif
if(strncmp(ifreq.ifr_name, ifr->ifr_name, sizeof(ifr->ifr_name)) if(strncmp(ifreq.ifr_name,
&& (loop || strncmp (ifr->ifr_name, "lo", 2))) { ifr->ifr_name,
sizeof(ifr->ifr_name)) == 0)
continue;
if(ioctl(fd, SIOCGIFFLAGS, ifr) < 0) { if(ioctl(fd, SIOCGIFFLAGS, ifr) < 0) {
close (fd); close (fd);
free (res->val); free (res->val);
return errno; return errno;
} }
if (ifr->ifr_flags & IFF_UP) {
if(ioctl(fd, SIOCGIFADDR, ifr) < 0) { if(!(ifr->ifr_flags & IFF_UP)
close (fd); || (loop && ifr->ifr_flags & IFF_LOOPBACK))
free (res->val); continue;
return errno;
} /*
* Get the address of the interface. If this fails, it's
* usually because this interface is up, but has no address
* configured. There might be some fatal errors for which
* we should bail out, but now we prefer ignoring them.
*/
if(ioctl(fd, SIOCGIFADDR, ifr) < 0)
continue;
switch (ifr->ifr_addr.sa_family) { switch (ifr->ifr_addr.sa_family) {
#ifdef AF_INET #ifdef AF_INET
case AF_INET: { case AF_INET: {
@@ -148,9 +162,7 @@ find_all_addresses (krb5_addresses *res, int loop)
res->val[j].addr_type = AF_INET; res->val[j].addr_type = AF_INET;
/* This is somewhat XXX */ /* This is somewhat XXX */
sin = (struct sockaddr_in*)&ifr->ifr_addr; sin = (struct sockaddr_in*)&ifr->ifr_addr;
memcpy(addr, memcpy(addr, &sin->sin_addr, 4);
&sin->sin_addr,
4);
err = krb5_data_copy(&res->val[j].address, err = krb5_data_copy(&res->val[j].address,
addr, 4); addr, 4);
if (err) { if (err) {
@@ -185,11 +197,8 @@ find_all_addresses (krb5_addresses *res, int loop)
default: default:
break; break;
} }
}
ifreq = *ifr; ifreq = *ifr;
} }
p = p + sz;
}
close (fd); close (fd);
if (j != num) { if (j != num) {
void *tmp; void *tmp;