summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-29 18:53:24 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-29 18:53:24 +0000
commitd422819a886769c2894bc215462b41c8a8e1aad5 (patch)
treea0e56e25598e5a71cbcd6b46e7b9ae4344bb8797
parent51529c3607a02a62468ccee8783cb2c5d7e65486 (diff)
prefer non-loopback addresses
-rw-r--r--lib/libc/rpc/get_myaddress.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c
index b0ac7da5ac6..48041537f6b 100644
--- a/lib/libc/rpc/get_myaddress.c
+++ b/lib/libc/rpc/get_myaddress.c
@@ -54,6 +54,9 @@ static char *rcsid = "$NetBSD: get_myaddress.c,v 1.3 1996/01/04 20:05:04 pk Exp
/*
* don't use gethostbyname, which would invoke yellow pages
+ *
+ * Avoid loopback interfaces. We return information from a loopback
+ * interface only if there are no other possible interfaces.
*/
int
get_myaddress(addr)
@@ -64,6 +67,7 @@ get_myaddress(addr)
struct ifconf ifc;
struct ifreq ifreq, *ifr;
int len, slop;
+ int loopback = 0, gotit = 0;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
return (-1);
@@ -74,6 +78,7 @@ get_myaddress(addr)
(void) close(s);
return (-1);
}
+again:
ifr = ifc.ifc_req;
for (len = ifc.ifc_len; len; len -= sizeof ifreq) {
ifreq = *ifr;
@@ -82,9 +87,11 @@ get_myaddress(addr)
return (-1);
}
if ((ifreq.ifr_flags & IFF_UP) &&
- ifr->ifr_addr.sa_family == AF_INET) {
+ ifr->ifr_addr.sa_family == AF_INET &&
+ (loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK))) {
*addr = *((struct sockaddr_in *)&ifr->ifr_addr);
addr->sin_port = htons(PMAPPORT);
+ gotit = 1;
break;
}
/*
@@ -97,6 +104,10 @@ get_myaddress(addr)
}
ifr++;
}
+ if (gotit == 0 && loopback == 0) {
+ loopback = 1;
+ goto again;
+ }
(void) close(s);
return (0);
}