You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
strtonum isn't available on <Darwin-11
|
|
|
|
|
|
|
|
however, it is in the header files on systems like 10.15 with an
|
|
|
|
availability clause, so don't define strtonum static such that it
|
|
|
|
matches the prototype from stdlib.h
|
|
|
|
|
|
|
|
diff --git a/netcat.c b/netcat.c
|
|
|
|
index a0fb51b..bbb5dd1 100644
|
|
|
|
--- a/netcat.c
|
|
|
|
+++ b/netcat.c
|
|
|
|
@@ -240,6 +243,43 @@ static int connect_with_timeout(int fd, const struct sockaddr *sa,
|
|
|
|
|
|
|
|
static void quit();
|
|
|
|
|
|
|
|
+static char* strtonumerrs[] = {
|
|
|
|
+ "too large",
|
|
|
|
+ "too small",
|
|
|
|
+ "invalid"
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+long long
|
|
|
|
+strtonum(
|
|
|
|
+ const char *nptr,
|
|
|
|
+ long long minval,
|
|
|
|
+ long long maxval,
|
|
|
|
+ const char **errstr)
|
|
|
|
+{
|
|
|
|
+ long long val;
|
|
|
|
+
|
|
|
|
+ while (*nptr != '\0' && isspace(*nptr))
|
|
|
|
+ nptr++;
|
|
|
|
+ if (*nptr == '\0') {
|
|
|
|
+ if (errstr != NULL)
|
|
|
|
+ *errstr = strtonumerrs[2];
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ val = atoll(nptr);
|
|
|
|
+ if (val < minval) {
|
|
|
|
+ if (errstr != NULL)
|
|
|
|
+ *errstr = strtonumerrs[1];
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ if (val > maxval) {
|
|
|
|
+ if (errstr != NULL)
|
|
|
|
+ *errstr = strtonumerrs[0];
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ *errstr = NULL;
|
|
|
|
+ return val;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|