Name

uri_portnum — obtain a URI's port number

Library

URI parsing library (liburi, -luri)

Synopsis

#include <liburi.h>

int uri_portnum( URI *uri);

Description

The uri_portnum returns the port number from a URI.

Parameters

uri

The source URI to retrieve the port number from.

Return value

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).

Example

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);
	

See also

liburi(3), uri_port(3).