Logo Search packages:      
Sourcecode: libupnp4 version File versions  Download package

EXPORT_SPEC int UpnpInit2 ( const char *  IfName,
unsigned short  DestPort 
)

Initializes the Linux SDK for UPnP Devices.

This function must be called before any other API function can be called. It should be called only once. Subsequent calls to this API return a UPNP_E_INIT error code.

Optionally, the application can specify an interface name (in the case of a multi-homed configuration) and a port number to use for all UPnP operations. Since a port number can be used only by one process, multiple processes using the SDK must specify different port numbers.

If unspecified, the SDK will use the first suitable interface and an arbitrary port.

This call is synchronous.

Returns:
An integer representing one of the following:
  • UPNP_E_SUCCESS: The operation completed successfully.
  • UPNP_E_OUTOF_MEMORY: Insufficient resources exist to initialize the SDK.
  • UPNP_E_INIT: The SDK is already initialized.
  • UPNP_E_INIT_FAILED: The SDK initialization failed for an unknown reason.
  • UPNP_E_SOCKET_BIND: An error occurred binding a socket.
  • UPNP_E_LISTEN: An error occurred listening to a socket.
  • UPNP_E_OUTOF_SOCKET: An error ocurred creating a socket.
  • UPNP_E_INTERNAL_ERROR: An internal error ocurred.
  • UPNP_E_INVALID_INTERFACE: IfName is invalid or does not have a valid IPv4 or IPv6 addresss configured.
Parameters:
IfName  The interface name to use by the UPnP SDK operations. Examples: "eth0", "xl0", "Local Area Connection", NULL to use the first suitable interface.
DestPort  Local Port to listen for incoming connections. NULL will pick an arbitrary free port.

Definition at line 255 of file upnpapi.c.

References gSDKInitMutex, UPNP_E_INIT, UPNP_E_SUCCESS, UpnpGetIfInfo(), UpnpInitPreamble(), UpnpInitStartServers(), UpnpPrintf(), and UpnpSdkInit.

{
      int retVal;

      ithread_mutex_lock( &gSDKInitMutex );

      // Check if we're already initialized.
      if( UpnpSdkInit == 1 ) {
            ithread_mutex_unlock( &gSDKInitMutex );
            return UPNP_E_INIT;
      }

      // Perform initialization preamble.
      retVal = UpnpInitPreamble();
      if( retVal != UPNP_E_SUCCESS ) {
            ithread_mutex_unlock( &gSDKInitMutex );
            return retVal;
      }

      UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
            "UpnpInit2 with IfName=%s, DestPort=%d.\n", 
            IfName ? IfName : "", DestPort );

      // Retrieve interface information (Addresses, index, etc).
      retVal = UpnpGetIfInfo( IfName );
      if( retVal != UPNP_E_SUCCESS ) {
            ithread_mutex_unlock( &gSDKInitMutex );
            return retVal;
      }

      // Set the UpnpSdkInit flag to 1 to indicate we're sucessfully initialized.
      UpnpSdkInit = 1;

      // Finish initializing the SDK.
      retVal = UpnpInitStartServers( DestPort );
      if( retVal != UPNP_E_SUCCESS ) {
            UpnpSdkInit = 0;
            ithread_mutex_unlock( &gSDKInitMutex );
            return retVal;
      }

      ithread_mutex_unlock( &gSDKInitMutex );

      return UPNP_E_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index