- port = strtol (argv[++i], NULL, 0);
- if (port == 0) { err = errno; }
+ errno = 0; /* ensure this starts off as 0 */
+ tmp = strtol (argv[++i], NULL, 0);
+ if (errno)
+ err = errno;
+ else if ((tmp <= 0) || (tmp > 65535))
+ err = ERANGE;
+ else
+ port = (int) tmp;