--- from_local.c.orig	2006-03-14 10:03:44.000000000 +0800
+++ from_local.c	2006-03-14 10:07:08.000000000 +0800
@@ -107,7 +107,7 @@
     struct ifreq *ifr;
     struct ifreq *the_end;
     int     sock;
-    char    buf[BUFSIZ];
+    char    *buf=NULL;
 
     /*
      * Get list of network interfaces. We use a huge buffer to allow for the
@@ -118,13 +118,27 @@
 	perror("socket");
 	return (0);
     }
-    ifc.ifc_len = sizeof(buf);
-    ifc.ifc_buf = buf;
-    if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) {
-	perror("SIOCGIFCONF");
-	(void) close(sock);
-	return (0);
-    }
+
+    num_local=0;
+    do {
+	num_local++;
+	buf=realloc(buf,num_local * BUFSIZ);
+	if(buf == NULL) {
+	    perror("portmap: out of memory");
+	    (void) close(sock);
+	    num_local=0;
+	    return (0);
+	}
+	ifc.ifc_len = (num_local * BUFSIZ);
+	ifc.ifc_buf = buf;
+	if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) {
+	    perror("SIOCGIFCONF");
+	    (void) close(sock);
+	    free(buf);
+	    num_local=0;
+	    return (0);
+	}
+    } while (ifc.ifc_len > ((num_local * BUFSIZ)-sizeof(struct ifreq)));
     /* Get IP address of each active IP network interface. */
 
     the_end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -153,6 +167,7 @@
 #endif
     }
     (void) close(sock);
+    free(buf);
     return (num_local);
 }
 
