On Thu, Aug 23, 2007 at 05:59:26PM -0600, Sean McCreary wrote: >I wanted portmap to support a list of interface addresses rather than >just one, so I made some small changes. I have attached a diff
>--- portmap.c.5-26 2007-08-22 13:30:13.000000000 -0600
>+++ portmap.c 2007-08-22 15:36:59.000000000 -0600
>@@ -129,6 +129,10 @@
> void reap();
> static void callit();
> struct pmaplist *pmaplist;
>+struct addrlist {
>+ struct in_addr sin_addr;
>+ struct addrlist *next;
>+};
> int debugging = 0;
> int foreground = 0;
>
>@@ -164,9 +168,9 @@
> struct sockaddr_in addr;
> int len = sizeof(struct sockaddr_in);
> register struct pmaplist *pml;
>+ struct addrlist *alist = NULL;
>+ struct addrlist *newaddr = NULL;
> char *chroot_path = NULL;
>- struct in_addr bindaddr;
>- int have_bindaddr = 0;
>
> while ((c = getopt(argc, argv, "dft:vi:")) != EOF) {
> switch (c) {
>@@ -183,10 +187,16 @@
> verboselog = 1;
> break;
> case 'i':
>- have_bindaddr = inet_aton(optarg, &bindaddr);
>+ newaddr = (struct addrlist
>*)malloc((u_int)sizeof(struct addrlist));
>+ newaddr->next = alist;
>+ if (inet_aton(optarg, &(newaddr->sin_addr))) {
>+ alist = newaddr;
>+ } else {
>+ free(newaddr);
>+ }
> break;
> default:
>- (void) fprintf(stderr, "usage: %s [-dfv] [-t dir] [-i
>address]\n", argv[0]);
>+ (void) fprintf(stderr, "usage: %s [-dfv] [-t dir] [-i
>address] [-i address] [...]\n", argv[0]);
> (void) fprintf(stderr, "-d: debugging mode\n");
> (void) fprintf(stderr, "-f: don't daemonize, log to
> standard error\n");
> (void) fprintf(stderr, "-t dir: chroot into dir\n");
>@@ -210,97 +220,110 @@
> 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);
>+ if (! alist) { /* Add INADDR_ANY to list of addresses */
>+ newaddr = (struct addrlist *)malloc((u_int)sizeof(struct
>addrlist));
>+ newaddr->sin_addr.s_addr = INADDR_ANY;
>+ newaddr->next = alist;
>+ alist = newaddr;
> }
>+
>+ while ( alist ) { /* Loop over all addresses */
>+
>+ 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);
>+ 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));
>+ memset((char *) &addr, 0, sizeof(addr));
>+ memcpy(&addr.sin_addr, &(alist->sin_addr), sizeof(struct
>in_addr));
>+ addr.sin_family = AF_INET;
>+ addr.sin_port = htons(PMAPPORT);
>
>- if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>- syslog(LOG_ERR, "cannot bind udp: %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 (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>+ syslog(LOG_ERR, "cannot bind udp: %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);
>- }
>+ 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);
>- }
>- /* 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;
>+ 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;
>
> #ifdef LOOPBACK_SETUNSET
>- if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
>- syslog(LOG_ERR, "cannot create udp socket: %m");
>- exit(1);
>- }
>- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
>-
>- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
>- if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>- syslog(LOG_ERR, "cannot bind udp: %m");
>- exit(1);
>- }
>-
>- if ((ludpxprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
>- syslog(LOG_ERR, "couldn't do udp_create");
>- exit(1);
>- }
>- if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
>- syslog(LOG_ERR, "cannot create tcp socket: %m");
>- exit(1);
>- }
>- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
>- if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>- syslog(LOG_ERR, "cannot bind tcp: %m");
>- exit(1);
>- }
>- if ((ltcpxprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
>- == (SVCXPRT *)NULL) {
>- syslog(LOG_ERR, "couldn't do tcp_create");
>- exit(1);
>- }
>+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
>+ syslog(LOG_ERR, "cannot create udp socket: %m");
>+ exit(1);
>+ }
>+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
>+
>+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
>+ if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>+ syslog(LOG_ERR, "cannot bind udp: %m");
>+ exit(1);
>+ }
>+
>+ if ((ludpxprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
>+ syslog(LOG_ERR, "couldn't do udp_create");
>+ exit(1);
>+ }
>+ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
>+ syslog(LOG_ERR, "cannot create tcp socket: %m");
>+ exit(1);
>+ }
>+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
>+ if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
>+ syslog(LOG_ERR, "cannot bind tcp: %m");
>+ exit(1);
>+ }
>+ if ((ltcpxprt = svctcp_create(sock, RPCSMALLMSGSIZE,
>RPCSMALLMSGSIZE))
>+ == (SVCXPRT *)NULL) {
>+ syslog(LOG_ERR, "couldn't do tcp_create");
>+ exit(1);
>+ }
> #endif
>
>+ /* clean up */
>+ newaddr = alist;
>+ alist = alist->next;
>+ free(newaddr);
>+ } /* end while */
>+
> (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
>
> /* additional initializations */
Thank you.
Best Regards,
Aníbal Monsalve Salazar
--
http://v7w.com/anibal
signature.asc
Description: Digital signature

