Group PJNATH_UPNP

group PJNATH_UPNP

A simple UPnP client implementation.

This is a simple implementation of UPnP client. Its main function is to request a port mapping from an Internet Gateway Device (IGD), which will redirect communication received on a specified external port to a local socket.

Functions

pj_status_t pj_upnp_init(const pj_upnp_init_param *param)

Initialize UPnP library and initiate the search for valid Internet Gateway Devices (IGD) in the network.

Parameters:

param – The UPnP initialization parameter.

Returns:

PJ_SUCCESS on success, or the appropriate error status.

pj_status_t pj_upnp_deinit(void)

Deinitialize UPnP library.

Returns:

PJ_SUCCESS on success, or the appropriate error status.

pj_status_t pj_upnp_add_port_mapping(unsigned sock_cnt, const pj_sock_t sock[], unsigned ext_port[], pj_sockaddr mapped_addr[])

This is the main function to request a port mapping. If successful, the Internet Gateway Device will redirect communication received on the specified external ports to the local sockets.

Parameters:
  • sock_cnt – Number of sockets in the socket array.

  • sock – Array of local UDP sockets that will be mapped.

  • ext_port – (Optional) Array of external port numbers. If NULL, the external port numbers requested will be identical to the sockets’ local port numbers.

  • mapped_addr – Array to receive the mapped public addresses and ports of the local UDP sockets, when the function returns PJ_SUCCESS.

Returns:

PJ_SUCCESS on success, or the appropriate error status.

pj_status_t pj_upnp_del_port_mapping(const pj_sockaddr *mapped_addr)

Send request to delete a port mapping.

Parameters:

mapped_addr – The public address and external port mapping to be deleted.

Returns:

PJ_SUCCESS on success, or the appropriate error status.

struct pj_upnp_init_param
#include <upnp.h>

This structre describes the parameter to initialize UPnP.

Public Members

pj_pool_factory *factory

The pool factory where memory will be allocated from.

const char *if_name

The interface name to use for all UPnP operations.

If NULL, the library will use the first suitable interface found.

unsigned port

The port number to use for all UPnP operations.

If 0, the library will pick an arbitrary free port.

int search_time

The time duration to search for IGD devices (in seconds).

If 0, the library will use PJ_UPNP_DEFAULT_SEARCH_TIME.

void (*upnp_cb)(pj_status_t status)

The callback to notify application when the initialization has completed.

Param status:

The initialization status.