diff options
-rw-r--r-- | gps2udp.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -138,6 +138,7 @@ static int open_udp(char **hostport) { char *hostname = NULL; char *portname = NULL; + char *endptr = '\0'; int portnum; struct hostent *hp; @@ -151,8 +152,9 @@ static int open_udp(char **hostport) return (-1); } - portnum = atoi(portname); - if (errno != 0) { + errno = 0; + portnum = strtol(portname, &endptr, 10); + if (0 == portnum || '\0' != *endptr || 0 != errno) { (void)fprintf(stderr, "gps2udp: syntax is [-u hostname:port] [%s] is not a valid port number\n",portname); return (-1); } |