diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-17 05:03:31 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-17 05:03:31 +0000 |
commit | 036dbaa082f1974246d1d7d21a8e163559642485 (patch) | |
tree | 2488441544ab16f8e08d0955d323019e96ed3d4f /libbb/xconnect.c | |
parent | b03be7f5677b86acfe2f64b5a57e1f361e257f6c (diff) | |
download | busybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.tar.gz busybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.tar.bz2 busybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.zip |
Modify bb_lookup_port to allow the protocol to be specified, allowing
/etc/services support for inetd, netcat and tftp.
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r-- | libbb/xconnect.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 29b984720..2443bb299 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -23,7 +23,7 @@ | |||
23 | * If "port" is a name it is looked up in /etc/services, if it isnt found return | 23 | * If "port" is a name it is looked up in /etc/services, if it isnt found return |
24 | * default_port | 24 | * default_port |
25 | */ | 25 | */ |
26 | unsigned short bb_lookup_port(const char *port, unsigned short default_port) | 26 | unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port) |
27 | { | 27 | { |
28 | unsigned short port_nr = htons(default_port); | 28 | unsigned short port_nr = htons(default_port); |
29 | if (port) { | 29 | if (port) { |
@@ -37,7 +37,7 @@ unsigned short bb_lookup_port(const char *port, unsigned short default_port) | |||
37 | errno = 0; | 37 | errno = 0; |
38 | port_long = strtol(port, &endptr, 10); | 38 | port_long = strtol(port, &endptr, 10); |
39 | if (errno != 0 || *endptr!='\0' || endptr==port || port_long < 0 || port_long > 65535) { | 39 | if (errno != 0 || *endptr!='\0' || endptr==port || port_long < 0 || port_long > 65535) { |
40 | struct servent *tserv = getservbyname(port, "tcp"); | 40 | struct servent *tserv = getservbyname(port, protocol); |
41 | if (tserv) { | 41 | if (tserv) { |
42 | port_nr = tserv->s_port; | 42 | port_nr = tserv->s_port; |
43 | } | 43 | } |