version 1.152, 2016/05/28 20:14:58 |
version 1.153, 2016/06/02 04:26:32 |
|
|
} |
} |
} |
} |
|
|
|
|
|
int |
|
strtoport(char *portstr, int udp) |
|
{ |
|
struct servent *entry; |
|
const char *errstr; |
|
char *proto; |
|
int port = -1; |
|
|
|
proto = udp ? "udp" : "tcp"; |
|
|
|
port = strtonum(portstr, 1, PORT_MAX, &errstr); |
|
if (errstr == NULL) |
|
return port; |
|
if (errno != EINVAL) |
|
errx(1, "port number %s: %s", errstr, portstr); |
|
if ((entry = getservbyname(portstr, proto)) == NULL) |
|
errx(1, "service \"%s\" unknown", portstr); |
|
return ntohs(entry->s_port); |
|
} |
|
|
/* |
/* |
* build_ports() |
* build_ports() |
* Build an array of ports in portlist[], listing each port |
* Build an array of ports in portlist[], listing each port |
|
|
void |
void |
build_ports(char *p) |
build_ports(char *p) |
{ |
{ |
const char *errstr; |
|
char *n; |
char *n; |
int hi, lo, cp; |
int hi, lo, cp; |
int x = 0; |
int x = 0; |
|
|
n++; |
n++; |
|
|
/* Make sure the ports are in order: lowest->highest. */ |
/* Make sure the ports are in order: lowest->highest. */ |
hi = strtonum(n, 1, PORT_MAX, &errstr); |
hi = strtoport(n, uflag); |
if (errstr) |
lo = strtoport(p, uflag); |
errx(1, "port number %s: %s", errstr, n); |
|
lo = strtonum(p, 1, PORT_MAX, &errstr); |
|
if (errstr) |
|
errx(1, "port number %s: %s", errstr, p); |
|
|
|
if (lo > hi) { |
if (lo > hi) { |
cp = hi; |
cp = hi; |
hi = lo; |
hi = lo; |
|
|
} |
} |
} |
} |
} else { |
} else { |
hi = strtonum(p, 1, PORT_MAX, &errstr); |
char *tmp; |
if (errstr) |
|
errx(1, "port number %s: %s", errstr, p); |
hi = strtoport(p, uflag); |
portlist[0] = strdup(p); |
if (asprintf(&tmp, "%d", hi) != -1) |
if (portlist[0] == NULL) |
portlist[0] = tmp; |
|
else |
err(1, NULL); |
err(1, NULL); |
} |
} |
} |
} |