summary refs log tree commit diff
path: root/sunrpc/get_myaddr.c
diff options
context:
space:
mode:
Diffstat (limited to 'sunrpc/get_myaddr.c')
-rw-r--r--sunrpc/get_myaddr.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/sunrpc/get_myaddr.c b/sunrpc/get_myaddr.c
index c0ff44efcf..d45cb6d908 100644
--- a/sunrpc/get_myaddr.c
+++ b/sunrpc/get_myaddr.c
@@ -38,6 +38,7 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
  * Copyright (C) 1984, Sun Microsystems, Inc.
  */
 
+#include <unistd.h>
 #include <rpc/types.h>
 #include <rpc/pmap_prot.h>
 #include <sys/socket.h>
@@ -53,40 +54,44 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
 /*
  * don't use gethostbyname, which would invoke yellow pages
  */
-get_myaddress(addr)
-	struct sockaddr_in *addr;
+void
+get_myaddress (struct sockaddr_in *addr)
 {
-	int s;
-	char buf[BUFSIZ];
-	struct ifconf ifc;
-	struct ifreq ifreq, *ifr;
-	int len;
+  int s;
+  char buf[BUFSIZ];
+  struct ifconf ifc;
+  struct ifreq ifreq, *ifr;
+  int len;
 
-	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-	    perror("get_myaddress: socket");
-	    exit(1);
+  if ((s = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
+    {
+      perror ("get_myaddress: socket");
+      exit (1);
+    }
+  ifc.ifc_len = sizeof (buf);
+  ifc.ifc_buf = buf;
+  if (ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
+    {
+      perror (_("get_myaddress: ioctl (get interface configuration)"));
+      exit (1);
+    }
+  ifr = ifc.ifc_req;
+  for (len = ifc.ifc_len; len; len -= sizeof ifreq)
+    {
+      ifreq = *ifr;
+      if (ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0)
+	{
+	  perror ("get_myaddress: ioctl");
+	  exit (1);
 	}
-	ifc.ifc_len = sizeof (buf);
-	ifc.ifc_buf = buf;
-	if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
-		perror(
-		   _("get_myaddress: ioctl (get interface configuration)"));
-		exit(1);
+      if ((ifreq.ifr_flags & IFF_UP) &&
+	  ifr->ifr_addr.sa_family == AF_INET)
+	{
+	  *addr = *((struct sockaddr_in *) &ifr->ifr_addr);
+	  addr->sin_port = htons (PMAPPORT);
+	  break;
 	}
-	ifr = ifc.ifc_req;
-	for (len = ifc.ifc_len; len; len -= sizeof ifreq) {
-		ifreq = *ifr;
-		if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
-			perror("get_myaddress: ioctl");
-			exit(1);
-		}
-		if ((ifreq.ifr_flags & IFF_UP) &&
-		    ifr->ifr_addr.sa_family == AF_INET) {
-			*addr = *((struct sockaddr_in *)&ifr->ifr_addr);
-			addr->sin_port = htons(PMAPPORT);
-			break;
-		}
-		ifr++;
-	}
-	(void) close(s);
+      ifr++;
+    }
+  (void) close (s);
 }