version 1.69, 2008/06/13 01:38:23 |
version 1.70, 2009/01/22 10:02:34 |
|
|
|
|
/* |
/* |
* Convert ASCII string to TCP/IP port number. |
* Convert ASCII string to TCP/IP port number. |
* Port must be >0 and <=65535. |
* Port must be >=0 and <=65535. |
* Return 0 if invalid. |
* Return -1 if invalid. |
*/ |
*/ |
int |
int |
a2port(const char *s) |
a2port(const char *s) |
{ |
{ |
long port; |
long long port; |
char *endp; |
const char *errstr; |
|
|
errno = 0; |
port = strtonum(s, 0, 65535, &errstr); |
port = strtol(s, &endp, 0); |
if (errstr != NULL) |
if (s == endp || *endp != '\0' || |
return -1; |
(errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) || |
return (int)port; |
port <= 0 || port > 65535) |
|
return 0; |
|
|
|
return port; |
|
} |
} |
|
|
int |
int |