tags 280537 patch
thanks

Hi!

Here's a patch for multiple interfaces (separated by :).

-- 
Robert Millan

My spam trap is [EMAIL PROTECTED]  Note: this address is only intended for
spam harvesters.  Writing to it will get you added to my black list.
diff -ur portmap-5.old/portmap.c portmap-5/portmap.c
--- portmap-5.old/portmap.c	2006-12-16 12:26:26.000000000 +0100
+++ portmap-5/portmap.c	2006-12-16 12:27:08.000000000 +0100
@@ -80,13 +80,16 @@
  * Mountain View, California  94043
  */
 
-#if defined(__GLIBC__)
 #define _BSD_SOURCE 1	/* for daemon(3) */
+#define _GNU_SOURCE 1	/* for strdupa */
 #include <rpc/xdr.h>
-#endif /* __GLIBC__ */
 #include <rpc/rpc.h>
 #include <rpc/pmap_prot.h>
 #include <stdio.h>
+#include <string.h>	/* strdupa */
+#ifndef strdupa
+#define strdupa strdup
+#endif
 #include <syslog.h>
 #include <netdb.h>
 #include <sys/socket.h>
@@ -165,8 +168,8 @@
 	int len = sizeof(struct sockaddr_in);
 	register struct pmaplist *pml;
 	char *chroot_path = NULL;
-	struct in_addr bindaddr;
-	int have_bindaddr = 0;
+	char *bindaddr = "0.0.0.0";
+	char *token;
 
 	while ((c = getopt(argc, argv, "dft:vi:")) != EOF) {
 		switch (c) {
@@ -183,7 +186,7 @@
 			verboselog = 1;
 			break;
 		case 'i':
-			have_bindaddr = inet_aton(optarg, &bindaddr);
+			bindaddr = strdupa (optarg);
 			break;
 		default:
 			(void) fprintf(stderr, "usage: %s [-dfv] [-t dir] [-i address]\n", argv[0]);
@@ -191,7 +194,7 @@
 			(void) fprintf(stderr, "-f: don't daemonize, log to standard error\n");
 			(void) fprintf(stderr, "-t dir: chroot into dir\n");
 			(void) fprintf(stderr, "-v: verbose logging\n");
-			(void) fprintf(stderr, "-i address: bind to address\n");
+			(void) fprintf(stderr, "-i address: bind to address (separated by :)\n");
 			exit(1);
 		}
 	}
@@ -210,63 +213,67 @@
 		foreground ? LOG_PID | LOG_NDELAY | LOG_PERROR : LOG_PID | LOG_NDELAY);
 #endif
 
-	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-		syslog(LOG_ERR, "cannot create udp socket: %m");
-		exit(1);
-	}
-#ifdef LOOPBACK_SETUNSET
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
-#endif
-
 	memset((char *) &addr, 0, sizeof(addr));
 	addr.sin_addr.s_addr = 0;
 	addr.sin_family = AF_INET;
 	addr.sin_port = htons(PMAPPORT);
-	if (have_bindaddr)
-		memcpy(&addr.sin_addr, &bindaddr, sizeof(bindaddr));
 
-	if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
-		syslog(LOG_ERR, "cannot bind udp: %m");
-		exit(1);
-	}
+	token = strtok(bindaddr, ":");
+	while (token != NULL) {
+		inet_aton(token, &addr.sin_addr);
 
-	if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
-		syslog(LOG_ERR, "couldn't do udp_create");
-		exit(1);
-	}
-	/* make an entry for ourself */
-	pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
-	pml->pml_next = 0;
-	pml->pml_map.pm_prog = PMAPPROG;
-	pml->pml_map.pm_vers = PMAPVERS;
-	pml->pml_map.pm_prot = IPPROTO_UDP;
-	pml->pml_map.pm_port = PMAPPORT;
-	pmaplist = pml;
+		if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+			syslog(LOG_ERR, "cannot create udp socket: %m");
+			exit(1);
+		}
+#ifdef LOOPBACK_SETUNSET
+		setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
+#endif
+		if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
+			syslog(LOG_ERR, "cannot bind udp: %m");
+			exit(1);
+		}
 
-	if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
-		syslog(LOG_ERR, "cannot create tcp socket: %m");
-		exit(1);
-	}
+		if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
+			syslog(LOG_ERR, "couldn't do udp_create");
+			exit(1);
+		}
+		/* make an entry for ourself */
+		pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
+		pml->pml_next = 0;
+		pml->pml_map.pm_prog = PMAPPROG;
+		pml->pml_map.pm_vers = PMAPVERS;
+		pml->pml_map.pm_prot = IPPROTO_UDP;
+		pml->pml_map.pm_port = PMAPPORT;
+		pmaplist = pml;
+
+		if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+			syslog(LOG_ERR, "cannot create tcp socket: %m");
+			exit(1);
+		}
 #ifdef LOOPBACK_SETUNSET
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
+		setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
 #endif
-	if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
-		syslog(LOG_ERR, "cannot bind tcp: %m");
-		exit(1);
-	}
-	if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
-	    == (SVCXPRT *)NULL) {
-		syslog(LOG_ERR, "couldn't do tcp_create");
-		exit(1);
+		if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
+			syslog(LOG_ERR, "cannot bind tcp: %m");
+			exit(1);
+		}
+		if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
+		    == (SVCXPRT *)NULL) {
+			syslog(LOG_ERR, "couldn't do tcp_create");
+			exit(1);
+		}
+		/* make an entry for ourself */
+		pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
+		pml->pml_map.pm_prog = PMAPPROG;
+		pml->pml_map.pm_vers = PMAPVERS;
+		pml->pml_map.pm_prot = IPPROTO_TCP;
+		pml->pml_map.pm_port = PMAPPORT;
+		pml->pml_next = pmaplist;
+		pmaplist = pml;
+
+		token = strtok (NULL, ":");
 	}
-	/* make an entry for ourself */
-	pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
-	pml->pml_map.pm_prog = PMAPPROG;
-	pml->pml_map.pm_vers = PMAPVERS;
-	pml->pml_map.pm_prot = IPPROTO_TCP;
-	pml->pml_map.pm_port = PMAPPORT;
-	pml->pml_next = pmaplist;
-	pmaplist = pml;
 
 #ifdef LOOPBACK_SETUNSET
 	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {

Reply via email to