summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-06-02 03:46:39 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-06-02 03:46:39 +0000
commit3da9f8a917f2bac8580f70b409b5e43008289866 (patch)
tree007bb04ab4e0e6c8dcff5369bbcf755e36f03b27 /usr.bin
parentffc9d7efd7866d411a0ec1c06b9b192f06dab326 (diff)
strtoul() -> strtonum(). Also change iflag to unsigned int, since
sleep takes an unsigned integer. OK moritz@, jaredy@, and dhill@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/nc/netcat.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index bea1b79ba5e..20571aab68d 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.87 2006/02/01 21:33:14 otto Exp $ */
+/* $OpenBSD: netcat.c,v 1.88 2006/06/02 03:46:38 ray Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@@ -65,7 +65,7 @@
/* Command Line Options */
int dflag; /* detached, no stdin */
-int iflag; /* Interval Flag */
+unsigned int iflag; /* Interval Flag */
int jflag; /* use jumbo frames if we can */
int kflag; /* More than one connect */
int lflag; /* Bind to local port */
@@ -106,13 +106,13 @@ int
main(int argc, char *argv[])
{
int ch, s, ret, socksv;
- char *host, *uport, *endp;
+ char *host, *uport;
struct addrinfo hints;
struct servent *sv;
socklen_t len;
struct sockaddr_storage cliaddr;
char *proxy;
- const char *proxyhost = "", *proxyport = NULL;
+ const char *errstr, *proxyhost = "", *proxyport = NULL;
struct addrinfo proxyhints;
ret = 1;
@@ -120,7 +120,6 @@ main(int argc, char *argv[])
socksv = 5;
host = NULL;
uport = NULL;
- endp = NULL;
sv = NULL;
while ((ch = getopt(argc, argv,
@@ -152,9 +151,9 @@ main(int argc, char *argv[])
help();
break;
case 'i':
- iflag = (int)strtoul(optarg, &endp, 10);
- if (iflag < 0 || *endp != '\0')
- errx(1, "interval cannot be negative");
+ iflag = strtonum(optarg, 0, UINT_MAX, &errstr);
+ if (errstr)
+ errx(1, "interval %s: %s", errstr, optarg);
break;
case 'j':
jflag = 1;
@@ -190,11 +189,9 @@ main(int argc, char *argv[])
vflag = 1;
break;
case 'w':
- timeout = (int)strtoul(optarg, &endp, 10);
- if (timeout < 0 || *endp != '\0')
- errx(1, "timeout cannot be negative");
- if (timeout >= (INT_MAX / 1000))
- errx(1, "timeout too large");
+ timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
+ if (errstr)
+ errx(1, "timeout %s: %s", errstr, optarg);
timeout *= 1000;
break;
case 'x':
@@ -681,7 +678,8 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
void
build_ports(char *p)
{
- char *n, *endp;
+ const char *errstr;
+ char *n;
int hi, lo, cp;
int x = 0;
@@ -693,12 +691,12 @@ build_ports(char *p)
n++;
/* Make sure the ports are in order: lowest->highest. */
- hi = (int)strtoul(n, &endp, 10);
- if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
- errx(1, "port range not valid");
- lo = (int)strtoul(p, &endp, 10);
- if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
- errx(1, "port range not valid");
+ hi = strtonum(n, 1, PORT_MAX, &errstr);
+ if (errstr)
+ 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) {
cp = hi;
@@ -728,9 +726,9 @@ build_ports(char *p)
}
}
} else {
- hi = (int)strtoul(p, &endp, 10);
- if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
- errx(1, "port range not valid");
+ hi = strtonum(p, 1, PORT_MAX, &errstr);
+ if (errstr)
+ errx(1, "port number %s: %s", errstr, p);
portlist[0] = calloc(1, PORT_MAX_LEN);
if (portlist[0] == NULL)
err(1, NULL);