Specifying routing settings to a specific socket connection using Symbian C++
In a controlled network environment you may often find yourself having to set specific routing options to your socket connection. This tip details how this can be done with Symbian sockets.
Specific settings can be set through the TSoInetRouteInfo type, which encapsulates a set of routing-specific variables into one package (i.e., gateway, subnet mask, etc). The object must then be packaged in to a TPckgBuf type object so it can be passed to the SetOpt() function.
You also need to use the INET_ADDR macro that can be found in the in_sock.h header. This macro forms a 32-bit integer from a normal dotted-decimal IP address.
// Connect to the socket server
// Open a channel<br>RSocket sock;
// Packaging the variable and setting the values
info().iMetric = 0;<br>// KSolInetRtCtrl indicates we are manually making
// changes to the routing table, that way SetOpt()
// accepts the info parameter.
TInt ret = sock.SetOpt(KSoInetAddRoute,
if(ret == KerrNone)
// Start using the socket
S60 3rd Edition
This solution applies to S60 3rd Edition as well. However, note that the application requires NetworkControl capability when using RSocket::SetOpt() with KSoInetAddRoute option.