diff options
author | Olaf Kirch <okir@suse.de> | 2008-09-16 10:08:35 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2008-09-16 10:08:35 -0400 |
commit | 3e4c74ab527375f37b6633f528e7eab0c363967b (patch) | |
tree | b961f34190b0ac959b22bf61384aa711b1604880 /src/pmap_svc.c | |
parent | 3942a3b4dcd451a2c41ad95a45f3f1462cb3f133 (diff) | |
download | rpcbind-3e4c74ab527375f37b6633f528e7eab0c363967b.tar.gz |
Introduce helpers for ipprot/netid mapping
There's a couple of places in the portmap emulation code
where we translate between ip protocol numbers and netids.
Encapsulate these in two helper functions:
extern char *pmap_ipprot2netid(int);
extern int pmap_netid2ipprot(const char *);
Signed-off-by: okir@suse.de
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'src/pmap_svc.c')
-rw-r--r-- | src/pmap_svc.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/pmap_svc.c b/src/pmap_svc.c index 99ce508..02a57d2 100644 --- a/src/pmap_svc.c +++ b/src/pmap_svc.c @@ -211,11 +211,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long if (op == PMAPPROC_SET) { char buf[32]; - if (reg.pm_prot == IPPROTO_UDP) { - rpcbreg.r_netid = udptrans; - } else if (reg.pm_prot == IPPROTO_TCP) { - rpcbreg.r_netid = tcptrans; - } else { + rpcbreg.r_netid = pmap_ipprot2netid(reg.pm_prot); + if (rpcbreg.r_netid == NULL) { ans = FALSE; goto done_change; } @@ -289,7 +286,8 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) svc_getrpccaller(xprt)); fprintf(stderr, "PMAP_GETPORT req for (%lu, %lu, %s) from %s :", reg.pm_prog, reg.pm_vers, - reg.pm_prot == IPPROTO_UDP ? "udp" : "tcp", uaddr); + pmap_ipprot2netid(reg.pm_prot)?: "<invalid>", + uaddr); free(uaddr); } #endif @@ -299,12 +297,13 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) char *pt1, *pt2; char *netid; + netid = pmap_ipprot2netid(reg.pm_prot); + if (netid == NULL) + goto sendreply; if (reg.pm_prot == IPPROTO_UDP) { ua = udp_uaddr; - netid = udptrans; } else { ua = tcp_uaddr; /* To get the len */ - netid = tcptrans; } if (ua == NULL) { goto sendreply; @@ -341,7 +340,7 @@ sendreply: fprintf(stderr, "port = %d\n", port); #endif rpcbs_getaddr(RPCBVERS_2_STAT, reg.pm_prog, reg.pm_vers, - reg.pm_prot == IPPROTO_UDP ? udptrans : tcptrans, + pmap_ipprot2netid(reg.pm_prot) ?: "<unknown>", port ? udptrans : ""); return (TRUE); @@ -372,4 +371,24 @@ pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) return (TRUE); } +int pmap_netid2ipprot(const char *netid) +{ + if (!netid) + return 0; + if (strcmp(netid, tcptrans) == 0) + return IPPROTO_TCP; + if (strcmp(netid, udptrans) == 0) + return IPPROTO_UDP; + return 0; +} + +char *pmap_ipprot2netid(unsigned long proto) +{ + if (proto == IPPROTO_UDP) + return udptrans; + if (proto == IPPROTO_TCP) + return tcptrans; + return NULL; +} + #endif /* PORTMAP */ |