From 50b91cb7edefec46a3450ace1ca973d74e3cb48e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT service" Date: Sun, 22 Feb 2009 23:13:03 +0100 Subject: [PATCH] portmap: specify port via cmdline --- portmap.8 | 4 ++++ portmap.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/portmap.8 b/portmap.8 index 10ddc61..0e842d7 100644 --- a/portmap.8 +++ b/portmap.8 @@ -162,6 +162,10 @@ bind .Nm portmap to the loop-back address 127.0.0.1. This is a shorthand for specifying 127.0.0.1 with -i. +.It Fl p Ar port +bind +.Nm portmap +to a non-standard port .El This diff --git a/portmap.c b/portmap.c index 40440d9..7719349 100644 --- a/portmap.c +++ b/portmap.c @@ -143,6 +143,7 @@ static int on = 1; #endif #endif +int daemon_port = PMAPPORT; int daemon_uid = DAEMON_UID; int daemon_gid = DAEMON_GID; const char* mapping_file = PORTMAP_MAPPING_FILE; @@ -185,6 +186,7 @@ static void usage(char *progname) fprintf(stderr, "-l same as -i 127.0.0.1\n"); fprintf(stderr, "-u run as this uid (default: %d)\n", DAEMON_UID); fprintf(stderr, "-g run as this gid (default: %d)\n", DAEMON_GID); + fprintf(stderr, "-p run on nonstandard port (default: %d)\n", daemon_port); fprintf(stderr, "-U suid/sgid to this user\n"); fprintf(stderr, "-m specify the mapping file name " "(default: "PORTMAP_MAPPING_FILE")\n"); @@ -205,7 +207,7 @@ main(int argc, char **argv) int foreground = 0; int have_uid = 0; - while ((c = getopt(argc, argv, "hVdfFlt:vi:u:U:g:m:")) != EOF) { + while ((c = getopt(argc, argv, "hVdfFlt:vi:u:U:g:m:p:")) != EOF) { switch (c) { case 'V': @@ -269,6 +271,9 @@ main(int argc, char **argv) case 'i': have_bindaddr = inet_aton(optarg, &bindaddr); break; + case 'p': + daemon_port = atoi(optarg); + break; case 'h': default: usage(argv[0]); @@ -309,7 +314,7 @@ main(int argc, char **argv) memset((char *) &addr, 0, sizeof(addr)); addr.sin_addr.s_addr = 0; addr.sin_family = AF_INET; - addr.sin_port = htons(PMAPPORT); + addr.sin_port = htons(daemon_port); if (have_bindaddr) memcpy(&addr.sin_addr, &bindaddr, sizeof(bindaddr)); @@ -330,7 +335,7 @@ main(int argc, char **argv) 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; + pml->pml_map.pm_port = daemon_port; pmaplist = pml; if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { @@ -356,7 +361,7 @@ main(int argc, char **argv) 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_map.pm_port = daemon_port; pml->pml_next = pmaplist; pmaplist = pml; @@ -876,7 +881,7 @@ static void load_table(void) &fpml.pml.pml_map.pm_prot, &fpml.pml.pml_map.pm_port, &fpml.priv) == 5) { - if (fpml.pml.pml_map.pm_port == PMAPPORT) + if (fpml.pml.pml_map.pm_port == daemon_port) continue; fpmlp = malloc(sizeof(struct flagged_pml)); if (!fpmlp) -- 2.39.5