uri_portnum — obtain a URI's port number
URI parsing library (liburi, -luri)
#include <liburi.h>
int uri_portnum(
URI *uri);
The uri_portnum returns the port number from a URI.
uriThe source URI to retrieve the port number from.
If the URI has a port number, its value will be returned. The port number can be any integer which is greater than or equal to zero.
If an error occurs, uri_portnum returns
-1, and sets errno
accordingly.
If the URI does not have a port number, uri_portnum
returns 0. To distinguish between an absent port
number and a port number being specified as 0, call
and check the return value of
uri_port(3).
URI *uri;
int r;
uri = uri_create_str("http://example.com:21/", NULL);
r = uri_portnum(uri);
/* assuming no errors have occurred, r will be 21 */
printf("r=%d\n", r);