Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to use Network Address and Port Translation (NAPT)

Network Address and Port Translation, if available, is loaded on request by an application. To load NAPT it is necessary to open a socket on it like this:

#include<interface.h>
RSocketServ  server;
RSocket  socket;
server.Connect();
socket.Open( server , _L("napt");

Note: the application opening this socket must have the appropriate Network Control capability.

Once NAPT is activated, it is necessary to set the details of the address mapping using the TInterfaceLockInfo class

class TInterfaceLockInfo
{
    // IAP of the public interface.
    TUint32 iPublicIap;

    //IAP of the private interface.
    TUint32 iPrivateIap;

    //Private interface IP 
    TInetAddr iPrivateIp;

    //Public interface IP
    TInetAddr iPublicIp;

 //netmask length needed to translated. Netmask will be 8 for class A. 16 for class B and 24 for class C.
 //This is specifically for NAPT.
    TUint iNetmaskLength;
    };

iPublicIAP IAP number of global interface for this device, i.e. IAP of interface acting as gateway to external world.

iPrivateIAP IAP number of private interface, i.e. IAP of interface acting as gateway for clients.

iPrivateIP IP of private Interface.

iPublicIP IP of public Interface.

iNetmaskLength netmask length to be translated. Netmask will be 8 for class A. 16 for class B and 24 for class C. Netmask will be for the iPrivateIP.

So the code would look something like this:

#include<interface.h>
RSocketServ  server;
RSocket socket;
server.Connect();
socket.Open( server , _L("napt");

//Package Class
 TPckgBuf <TInterfaceLockInfo> info;    
info().iPublic_Iap  = iNaptPublicIap;  
info().iPrivate_Iap = iNaptPrivateIap;  
TInetAddr::Cast (info().iPrivateIp).SetV4MappedAddress(iPrivateIp.Address()) ; 
TInetAddr::Cast (info().iPublicIp).SetV4MappedAddress(iPublicIP.iAddress.Address()) ;
Info().iNetMaskLength = //according to the configuration you are using. 
socket.SetOpt ( KSoNaptSetup ,KSolNapt, info);

Keeping the Global Interface up

The IP stack does not keep the interface up for forwarding flows. After the global timer has expired the interface is dropped. Clients need to keep interface up by setting an option on the connection.

RConnection conn;
//clients must be starting or attaching a connection.
conn.SetOpt(KCOLProvider, KConnDisableTimers, ETrue);

However if you wish to use a timer, then you can enable it using this code fragment:

conn.SetOpt(KCOLProvider, KConnDisableTimers, EFalse);

NAPT Timer Settings

The NAPT Timer settings can be configured in napt.ini (which can be found in c\private\101f7989\esock), but the default values are shown below. All values are in seconds.

napt_table_scan_interval= 60
napt_udp_idle_timeout= 60
napt_icmp_idle_timeout= 60
napt_tcp_idle_timeout= 100
napt_tcp_close_timeout= 240
napt_tcp_open_timeout= 30