summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gps2udp.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/gps2udp.c b/gps2udp.c
index 8549a129..bcc5a743 100644
--- a/gps2udp.c
+++ b/gps2udp.c
@@ -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);
}