genericopenlibs/openenvcore/backend/src/corebackend/usocket.cpp
changeset 0 e4d67989cc36
child 3 18f64da82512
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sys/types.h>
       
    20 #include <string.h>		// for memcpy
       
    21 #include <fcntl.h>		// for struct stat
       
    22 #include <sys/errno.h>		// for ENOTSOCK
       
    23 #include <sys/socket.h>
       
    24 #include <sys/ioctl.h>
       
    25 #include <sys/stat.h>
       
    26 #include <netinet/in.h>		// for htons
       
    27 #include <sys/sockio.h>
       
    28 #include <bt_sock.h>     // Symbian BT constantss needed for cooperation with Symbian sockets
       
    29 #include <arpa/inet.h>   
       
    30 #include <es_sock.h>
       
    31 #include <in_sock.h>
       
    32 #include <net/if.h>
       
    33 #include <commdb.h>
       
    34 #include <cdbcols.h>
       
    35 #include <commdbconnpref.h>
       
    36 #include <e32base.h>
       
    37 #include <e32err.h>
       
    38 #include <utf.h>
       
    39 #include <e32std.h>
       
    40 #include <net/route.h>
       
    41 #include <in_iface.h>
       
    42 #include "fdesc.h"
       
    43 #include "lposix.h"
       
    44 #include "sysif.h"
       
    45 
       
    46 // Support for struct sockaddr conversion
       
    47 TUSockAddr::TUSockAddr (TAny* aBuf) 
       
    48 : TSockAddr(), iError(0)
       
    49 		{
       
    50 		Prepare(aBuf);
       
    51 		}
       
    52 
       
    53 void TUSockAddr::Prepare (TAny* aBuf) 
       
    54 //
       
    55 // Prepare a TUSockAddr to receive an address (used in RecvFrom)
       
    56 // Setting the length to 0 indicates that we don't really want this address anyway.
       
    57 //
       
    58 	{
       
    59 	if (aBuf==0)
       
    60 		{
       
    61 		SetLength(0);
       
    62 		iError = EFAULT;
       
    63 		return;
       
    64 		}
       
    65 	}
       
    66 
       
    67 EXPORT_C TUSockAddr::TUSockAddr (const TAny* aBuf, TUint aLen) 
       
    68 : TSockAddr(), iError(0)
       
    69 		{
       
    70 		Set(aBuf,aLen);
       
    71 		}
       
    72 
       
    73 void TUSockAddr::Set (const TAny* aBuf, TUint aLen) 
       
    74 //
       
    75 // Construct an ESOCK TSockAddr from a struct sockaddr.
       
    76 // We have to deal with the network byte ordering of AF_INET addresses
       
    77 //
       
    78 	{
       
    79 	if (aBuf==0)
       
    80 		{
       
    81 		iError = EFAULT;
       
    82 		SetLength(0);
       
    83 		return;
       
    84 		}
       
    85 	
       
    86 	const TUint dataOffset = (TUint)&((struct sockaddr *)0)->sa_data[0];
       
    87 	// aLen should be atleast have minimum size.
       
    88 	if (aLen < dataOffset)
       
    89 		{
       
    90 		iError = EINVAL;
       
    91 		SetLength(0);
       
    92 		return;
       
    93 		}
       
    94 
       
    95 	const struct sockaddr* sp= (const struct sockaddr *)(aBuf);
       
    96 	TUint8 *from=(TUint8*)aBuf;	
       
    97 
       
    98 	if (sp->sa_family==AF_INET)
       
    99 		{		
       
   100 		// byte-swap sockaddr_in back into host ordering
       
   101 		TUint port=(from[2]<<8)+from[3];
       
   102 		from+=4;
       
   103 		TUint32 addr=(from[0]<<24)+(from[1]<<16)+(from[2]<<8)+from[3];
       
   104 		from+=4;
       
   105 		SetFamily(AF_INET);
       
   106 		SetPort(port);
       
   107 		*(TUint32*)UserPtr()=addr;
       
   108 		SetUserLen(4);
       
   109 		return;
       
   110 		}
       
   111 	else if (sp->sa_family == AF_INET6)
       
   112 		{
       
   113 		SetFamily(sp->sa_family);
       
   114 		SetPort(ByteOrder::Swap16(sp->sa_port));
       
   115 		from+=4;
       
   116 		// copy the rest of the data as given
       
   117 		TUint8 *to=UserPtr();
       
   118 		if (aLen<4)
       
   119 			aLen=4;
       
   120 		aLen-=4;	// skip fmaily and port
       
   121 		if (aLen>24)
       
   122 			aLen=24;
       
   123 		memcpy(to,from,aLen);
       
   124 		SetUserLen(aLen);    	
       
   125 		return;
       
   126 		}	
       
   127 	else if (sp->sa_family == KBTAddrFamily)
       
   128 		{
       
   129 		// Make a TBTSockAddr from a sockaddr_bt...
       
   130 		TBTSockAddr tmpAddr;
       
   131 
       
   132 		// Family is always Bluetooth:
       
   133 		tmpAddr.SetFamily(KBTAddrFamily);
       
   134 
       
   135 		// The port number has the correct byte order already, as the
       
   136 		// POSIX Bluetooth APIs assume litle-endian format:
       
   137 		tmpAddr.SetPort(sp->sa_port);
       
   138 
       
   139 		// For the address we need to reverse the byte ordering, as
       
   140 		// Symbian appears to index Bluetooth addresses in a
       
   141 		// big-endian manner:
       
   142 
       
   143 		const TInt KBTAddrLength = 6;  // Bytes in a Bluetooth address
       
   144 		const TInt KBTAddrOffset = 4;  // Offset of address in sockaddr_bt
       
   145 
       
   146 		TBTDevAddr devAddr;
       
   147 		const TInt KMinLength = KBTAddrLength + KBTAddrOffset;
       
   148 
       
   149 		if (aLen >= KMinLength)
       
   150 			{
       
   151 			for (TInt i=0; i<KBTAddrLength; ++i)
       
   152 				{
       
   153 				devAddr[i] = from[KMinLength - 1 - i];
       
   154 				}
       
   155 			}
       
   156 
       
   157 		tmpAddr.SetBTAddr(devAddr);
       
   158 
       
   159 		// Security settings:
       
   160 		TBTServiceSecurity sec;
       
   161 		sec.SetUid(TUid::Uid(0));
       
   162 		sec.SetAuthentication(EFalse);
       
   163 		sec.SetEncryption(EFalse);
       
   164 		sec.SetAuthorisation(EFalse);
       
   165 		sec.SetDenied(EFalse);
       
   166 		tmpAddr.SetSecurity(sec);
       
   167 
       
   168 		// Now we must copy the contents of the "tmpAddr" TBTSockAddr,
       
   169 		// but unfortunately there isn't an assignment operator for us
       
   170 		// to use. Still, we know it is a self-contained T class for
       
   171 		// which a direct shallow copy using memcopy() will be ok:
       
   172 		//
       
   173 		memcpy(this, &tmpAddr, sizeof(TBTSockAddr));
       
   174 
       
   175 		return;
       
   176 		}
       
   177 	else
       
   178 		{
       
   179 		// Not AF_INET or KBTAddrFamily:
       
   180 
       
   181 		// expand the family and port
       
   182 		SetFamily(sp->sa_family);
       
   183 		SetPort(sp->sa_port);
       
   184 		from+=4;
       
   185 		// copy the rest of the data as given
       
   186 		TUint8 *to=UserPtr();
       
   187 		if (aLen<4)
       
   188 			aLen=4;
       
   189 		aLen-=4;	// skip fmaily and port
       
   190 		if (aLen>24)
       
   191 			aLen=24;
       
   192 		memcpy(to,from,aLen);
       
   193 		SetUserLen(aLen);
       
   194 		}
       
   195 	}
       
   196 
       
   197 EXPORT_C void TUSockAddr::Get(TAny* addr, unsigned long* len)
       
   198 //
       
   199 // Extract a struct sockaddr from a TSockAddr
       
   200 //
       
   201 	{
       
   202 	if (addr==0)
       
   203 		{
       
   204 		iError = EFAULT;
       
   205 		SetLength(0);
       
   206 		return;
       
   207 		}
       
   208 	const TUint dataOffset = (TUint)&((struct sockaddr *)0)->sa_data[0];
       
   209 	// aLen should be atleast have minimum size.
       
   210 	if (*len < dataOffset)
       
   211 		{
       
   212 		iError = EINVAL;
       
   213 		SetLength(0);
       
   214 		return;
       
   215 		};
       
   216 
       
   217 	struct sockaddr* sp=(struct sockaddr*)addr;
       
   218 	TUint16 port=(TUint16)Port();
       
   219 
       
   220 	//The ipv4 address could be obtained either as
       
   221 	//plain 32 bit address or as ipv4 mapped ipv6 address
       
   222 	TInetAddr inetAddr(*this);
       
   223 	TBool isV4Mapped = (Family()==AF_INET6) && (inetAddr.IsV4Mapped() || inetAddr.IsV4Compat());
       
   224 	if (Family()==AF_INET || isV4Mapped)
       
   225 		{
       
   226 		sp->sa_family=AF_INET;
       
   227 		sp->sa_port= ByteOrder::Swap16(port);
       
   228 		TUint8* from=UserPtr();
       
   229 		TUint32 fromaddr;
       
   230 		//If the address is v4 mapped, we take the last 4 bytes from the 16 bytes long v6 structure. 
       
   231 		if(isV4Mapped)
       
   232 			fromaddr = (from[15]<<24)+(from[14]<<16)+(from[13]<<8)+from[12];
       
   233 		else
       
   234 			fromaddr = (from[0]<<24)+(from[1]<<16)+(from[2]<<8)+ from[3];
       
   235 		*(TUint32*)sp->sa_data=fromaddr;
       
   236 		*len=8;
       
   237 		return;
       
   238 		}
       
   239 	else if (Family()==AF_INET6)
       
   240 		{
       
   241 
       
   242 		sp->sa_family=(TUint16)Family();
       
   243 		sp->sa_port=ByteOrder::Swap16(port);
       
   244 		TUint ulen=GetUserLen();
       
   245 		if (ulen+4>(*len))
       
   246 			ulen=(*len)-4;
       
   247 		*len=ulen+4;
       
   248 		memcpy(sp->sa_data,UserPtr(),ulen);
       
   249 		sp->sa_len = ulen;
       
   250 		return;
       
   251 		}		
       
   252 	else if (Family()==KBTAddrFamily)
       
   253 		{
       
   254 		sp->sa_family=KBTAddrFamily;
       
   255 		sp->sa_port=port;
       
   256 
       
   257 		const TInt KBTAddrLength = 6;
       
   258 		if (GetUserLen() == KBTAddrLength)
       
   259 			{
       
   260 			for (TInt i=0; i<KBTAddrLength; ++i)
       
   261 				{
       
   262 				sp->sa_data[KBTAddrLength - 1 - i] = UserPtr()[i];
       
   263 				}
       
   264 			}
       
   265 		return;
       
   266 		}
       
   267 	else
       
   268 		{
       
   269 		// Not AF_INET or KBTAddrFamily:
       
   270 		sp->sa_family=(TUint16)Family();
       
   271 		sp->sa_port=port;
       
   272 		TUint ulen=GetUserLen();
       
   273 		if (ulen+4>(*len))
       
   274 			ulen=(*len)-4;
       
   275 		*len=ulen+4;
       
   276 		memcpy(sp->sa_data,UserPtr(),ulen);
       
   277 		}
       
   278 	}
       
   279 
       
   280 // The Socket descriptor class
       
   281 CSocketDesc::CSocketDesc()
       
   282 :iIoctlBuf(0,0),
       
   283 iSocketPtr(NULL),
       
   284 iConnPref(),
       
   285 iConnectionPtr(NULL),
       
   286 iSubConnectionPtr(NULL),
       
   287 iRConnectionIndex(-1),		
       
   288 iSockServPtr(NULL)
       
   289 		{
       
   290 
       
   291 		};
       
   292 
       
   293 
       
   294 TInt CSocketDesc::Socket(RSocketServ& aSs, int family, int style, int protocol)
       
   295 	{
       
   296 	if (protocol == 0)
       
   297 		{
       
   298 		if (family == AF_INET)
       
   299 			{
       
   300 			switch (style)
       
   301 				{
       
   302 				case SOCK_STREAM:
       
   303 					protocol = IPPROTO_TCP;
       
   304 					break;
       
   305 
       
   306 				case SOCK_DGRAM:
       
   307 					protocol = IPPROTO_UDP;
       
   308 					break;
       
   309 				}
       
   310 			}
       
   311 		else
       
   312 			{
       
   313 			protocol = KUndefinedProtocol;
       
   314 			}
       
   315 		}
       
   316 
       
   317 	iFcntlFlag = 0;
       
   318 	TInt err = CreateLock();
       
   319 	if (err)
       
   320 		{
       
   321 		return err;
       
   322 		}
       
   323 
       
   324 	if (family == AF_INET6)
       
   325 		{
       
   326 		err = iSocket.Open(aSs, KAfInet, style, protocol);
       
   327 		}
       
   328 	else
       
   329 		{
       
   330 		err = iSocket.Open(aSs, family, style, protocol);
       
   331 		}
       
   332 
       
   333 	if (err == KErrNone)
       
   334 		{
       
   335 		iStyle = style;
       
   336 		iSocket.Close(); // We will close now, to open later using connection preferences
       
   337 		iAddrFamily = family;
       
   338 		iProtocol = protocol; 
       
   339 		iSockServPtr = &aSs; // Saving the const session pointer for later use
       
   340 		}
       
   341 	return err;
       
   342 	}
       
   343 
       
   344 TInt CSocketDesc::FinalClose()
       
   345 	{
       
   346 	RHeap* oheap = User::SwitchHeap(Backend()->Heap());
       
   347 	if (iSocketPtr != NULL)
       
   348 		{
       
   349 		iSocketPtr = NULL;	
       
   350 		StopInterface(NULL); // Checks for RConnection as well as RSubConnection
       
   351 		}
       
   352 
       
   353 	CSockDescBase::FinalClose();
       
   354 	User::SwitchHeap(oheap);
       
   355 	return KErrNone;
       
   356 	}
       
   357 
       
   358 
       
   359 void CSocketDesc::Read (TDes8& aBuf, TRequestStatus& aStatus)
       
   360 	{
       
   361 	//Acquire the Lock before read and release it later
       
   362 	iReadLock.Wait();
       
   363 	if (iSocketPtr == NULL)
       
   364 		{
       
   365 		TInt ret = OpenUsingPreference();
       
   366 		if (ret != KErrNone)	// Error in open
       
   367 			{
       
   368 			Complete(aStatus,ret);
       
   369 			iReadLock.Signal();
       
   370 			return;
       
   371 			}
       
   372 		}
       
   373 	CSockDescBase::Read (aBuf,aStatus);
       
   374 	iReadLock.Signal();
       
   375 	}
       
   376 
       
   377 TInt CSocketDesc::ReadCompletion(TDes8& aBuf, TInt aStatus)
       
   378 	{
       
   379 	return CSockDescBase::ReadCompletion(aBuf, aStatus);
       
   380 	}
       
   381 
       
   382 void CSocketDesc::ReadCancel()
       
   383 	{
       
   384 	if (iSocketPtr != NULL)
       
   385 		{
       
   386 		CSockDescBase::ReadCancel();
       
   387 		}
       
   388 	}
       
   389 
       
   390 void CSocketDesc::Write (TDes8& aBuf, TRequestStatus& aStatus)
       
   391 	{
       
   392 	//Acquire the Lock before write and release it later
       
   393 	iWriteLock.Wait();	
       
   394 	if (iSocketPtr == NULL)
       
   395 		{
       
   396 		TInt ret = OpenUsingPreference();
       
   397 		if (ret != KErrNone)	// Error in open
       
   398 			{
       
   399 			Complete(aStatus,ret);
       
   400 			iWriteLock.Signal();
       
   401 			return;
       
   402 			}
       
   403 		}
       
   404 	CSockDescBase::Write(aBuf, aStatus);
       
   405 	iWriteLock.Signal();	
       
   406 	}
       
   407 
       
   408 void CSocketDesc::WriteCancel()
       
   409 	{
       
   410 	if (iSocketPtr != NULL)
       
   411 		{
       
   412 		CSockDescBase::WriteCancel();
       
   413 		}
       
   414 	}
       
   415 
       
   416 
       
   417 TInt CSocketDesc::Bind(const struct sockaddr* aAddr, unsigned long aSize)
       
   418 	{
       
   419 	TInt ret;
       
   420 	TUSockAddr addr(aAddr,aSize);
       
   421 
       
   422 	if (addr.iError != 0)
       
   423 		{
       
   424 		return addr.iError;
       
   425 		}
       
   426 
       
   427 	if (iSocketPtr == NULL)
       
   428 		{
       
   429 		ret = OpenUsingPreference();
       
   430 		if (ret != KErrNone)	// Error in open
       
   431 			{
       
   432 			return ret;
       
   433 			}
       
   434 		}
       
   435 	return iSocket.Bind(addr);
       
   436 	}
       
   437 
       
   438 TInt CSocketDesc::Listen(TUint qSize)
       
   439 	{
       
   440 	if (iStyle == SOCK_DGRAM) // Listen on UDP socket, crashing at RSocket::Listen().
       
   441 		{
       
   442 		return EOPNOTSUPP;
       
   443 		}
       
   444 	if (iSocketPtr == NULL)
       
   445 		{
       
   446 		TInt ret = OpenUsingPreference();
       
   447 		if (ret != KErrNone)	// Error in open
       
   448 			{
       
   449 			return ret;
       
   450 			}
       
   451 		}
       
   452 	return CSockDescBase::Listen(qSize);
       
   453 	}
       
   454 
       
   455 TInt CSocketDesc::SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize)
       
   456 	{
       
   457 	TInt ret;
       
   458 	if (iSocketPtr == NULL)
       
   459         {
       
   460             ret = OpenUsingPreference();
       
   461             if (ret != KErrNone)    // Error in open
       
   462                 {
       
   463                 return ret;
       
   464                 }
       
   465         }
       
   466 	
       
   467 	if ( anAddr == 0 ) // if the sockaddr passed is NULL return EFAULT.
       
   468         {
       
   469             return EFAULT;
       
   470         }
       
   471 
       
   472    
       
   473     struct sockaddr temp;
       
   474     unsigned long len = sizeof( temp );
       
   475     
       
   476 	TUSockAddr nSockAddr(&temp, len );
       
   477 
       
   478 	ret = CSockDescBase::SockName(anEnd,nSockAddr);
       
   479 	if(ret == KErrNone )
       
   480 	    {
       
   481             nSockAddr.Get(&temp,&len );
       
   482             if( *aSize > len )
       
   483                 *aSize = len;
       
   484             memcpy( anAddr,&temp,*aSize);
       
   485             
       
   486             }
       
   487 	
       
   488 	return ret;
       
   489 	}
       
   490 
       
   491 TInt CSocketDesc::GetSockOpt(TInt anOptionName, TInt anOptionLevel, TDes8& anOption)
       
   492 	{
       
   493 	TInt ret;
       
   494 	if (anOption.Ptr() == NULL)
       
   495 		{
       
   496 		return EFAULT;
       
   497 		}
       
   498 	if (anOption.Length() == 0)
       
   499 		{
       
   500 		return EINVAL;
       
   501 		}
       
   502 	if (iSocketPtr == NULL)
       
   503 		{
       
   504 		ret = OpenUsingPreference();
       
   505 		if (ret != KErrNone)	// Error in open
       
   506 			{
       
   507 			return ret;
       
   508 			}
       
   509 		}
       
   510 
       
   511 	if (SO_TYPE == anOptionName && SOL_SOCKET == anOptionLevel)
       
   512 		{
       
   513 		TProtocolDesc protocolInfo;
       
   514 		ret = iSocket.Info(protocolInfo);
       
   515 		if (KErrNone == ret )
       
   516 			{
       
   517 			//Copy the Socket Type to the buffer
       
   518 			TInt size;
       
   519 			size = (anOption.Length() < sizeof(protocolInfo.iSockType))? anOption.Length(): sizeof(protocolInfo.iSockType);
       
   520 			Mem::Copy((unsigned char*)anOption.Ptr(), &protocolInfo.iSockType, size);
       
   521 			anOption.SetLength(size);
       
   522 			}
       
   523 		return ret;
       
   524 		}
       
   525 
       
   526 	if(IPPROTO_IP == anOptionLevel && IP_MULTICAST_IF == anOptionName)
       
   527 		{
       
   528 		TUSockAddr addr;
       
   529 		struct sockaddr_in sockAddress;
       
   530 		sockAddress.sin_family = AF_INET;
       
   531 		sockAddress.sin_port = iSocket.LocalPort();	
       
   532 		iSocket.LocalName(addr);
       
   533 
       
   534 		TInt a = sizeof(sockAddress);
       
   535 		addr.Get(&sockAddress,(unsigned long*)&a);  
       
   536 		TInt size;
       
   537 		size = (anOption.Length() < sizeof(sockAddress.sin_addr))? anOption.Length(): sizeof(sockAddress.sin_addr);
       
   538 		Mem::Copy((unsigned char*)anOption.Ptr(), &(sockAddress.sin_addr), size); 
       
   539 		anOption.SetLength(size);
       
   540 		return KErrNone;
       
   541 		}
       
   542 
       
   543 
       
   544 
       
   545 	switch(anOptionLevel)
       
   546 		{
       
   547 		case IPPROTO_TCP:
       
   548 			anOptionLevel=SOL_TCP;
       
   549 			break;
       
   550 		case IPPROTO_IP:
       
   551 			anOptionLevel=SOL_IP;
       
   552 			break;
       
   553 		case SOL_SOCKET:
       
   554 			{
       
   555 			switch(anOptionName)
       
   556 				{
       
   557 				case SO_REUSEADDR: 
       
   558 					anOptionLevel=SOL_IP;
       
   559 					break;
       
   560 				case SO_OOBINLINE:
       
   561 				case SO_KEEPALIVE:
       
   562 					anOptionLevel=SOL_TCP;
       
   563 					break; 
       
   564 				case SO_BROADCAST:
       
   565 					*((TInt*)anOption.Ptr()) = 1;
       
   566 					return KErrNone;
       
   567 				}
       
   568 			}
       
   569 		} 
       
   570 
       
   571 	switch(anOptionName)
       
   572 		{
       
   573 		case IP_MULTICAST_TTL:
       
   574 			anOptionLevel=KSolInetIp;
       
   575 			anOptionName=KSoIp6MulticastHops;
       
   576 			break;
       
   577 		case IP_MULTICAST_LOOP:
       
   578 			anOptionLevel=KSolInetIp;
       
   579 			anOptionName=KSoIp6MulticastLoop;
       
   580 			break;
       
   581 		}
       
   582 
       
   583 	return iSocket.GetOpt(anOptionName,anOptionLevel,anOption);
       
   584 	}
       
   585 
       
   586 TInt CSocketDesc::GetInterfaceIndex(TUint32 anAddr)
       
   587 	{
       
   588 	TPckgBuf<TSoInetIfQuery> ifq;
       
   589 	TInt aIndex = -1;
       
   590 	if (KInetAddrAny == anAddr)
       
   591 		{
       
   592 		aIndex = 0;
       
   593 		return aIndex;
       
   594 		}
       
   595 	else 
       
   596 		{
       
   597 		TInt ret = iSocket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
       
   598 		if (ret != KErrNone)
       
   599 			return KErrGeneral;
       
   600 
       
   601 		TPckgBuf<TSoInetInterfaceInfo>iface;
       
   602 		while(iSocket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, iface) == KErrNone)
       
   603 			{
       
   604 			TSoInetInterfaceInfo &info = iface();
       
   605 			TInt result;
       
   606 			if(info.iState == EIfUp)
       
   607 				{
       
   608 				if (anAddr == info.iAddress.Address()) 
       
   609 					{      	
       
   610 					ifq().iName = info.iName;
       
   611 					result = iSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifq);
       
   612 					if (result == KErrNone)
       
   613 						aIndex = ifq().iIndex;
       
   614 
       
   615 					}
       
   616 				}
       
   617 
       
   618 			}   	
       
   619 		}
       
   620 	return aIndex;
       
   621 	}
       
   622 
       
   623 TInt CSocketDesc::SetSockOpt(TInt anOptionName, TInt anOptionLevel, TDesC8& anOption)
       
   624 	{
       
   625 	TInt ret;
       
   626 	if (anOption.Ptr() == NULL)
       
   627 		{
       
   628 		return EFAULT;
       
   629 		}
       
   630 	if (anOption.Length() == 0)
       
   631 		{
       
   632 		return EINVAL;
       
   633 		}
       
   634 	if (iSocketPtr == NULL)
       
   635 		{
       
   636 		ret = OpenUsingPreference();
       
   637 		if (ret != KErrNone)	// Error in open
       
   638 			{
       
   639 			return ret;
       
   640 			}
       
   641 		}
       
   642 
       
   643 	switch(anOptionLevel)
       
   644 		{
       
   645 		case IPPROTO_TCP:
       
   646 			anOptionLevel=SOL_TCP;
       
   647 			break;
       
   648 		case IPPROTO_IP:
       
   649 			anOptionLevel=SOL_IP;
       
   650 			break;
       
   651 		case SOL_SOCKET:
       
   652 			{
       
   653 			switch(anOptionName)
       
   654 				{
       
   655 				case SO_REUSEADDR: 
       
   656 					anOptionLevel=SOL_IP;
       
   657 					break;
       
   658 				case SO_OOBINLINE:
       
   659 				case SO_KEEPALIVE:
       
   660 					anOptionLevel=SOL_TCP;
       
   661 					break; 
       
   662 				}
       
   663 			}
       
   664 
       
   665 		}
       
   666 	TPckgBuf<TIp6Mreq> req;
       
   667 	struct ip_mreq *mreq;
       
   668 	TInt aIndex = -1;
       
   669 	TUint8 *from;
       
   670 	TUint32 srcAddr;
       
   671 	TUint32 maddr;
       
   672 	TInetAddr multiAddr;
       
   673 	TInt *Option = NULL;
       
   674 	TInt ttlValue = 0;
       
   675 	switch(anOptionName) 
       
   676 		{
       
   677 		case IP_ADD_MEMBERSHIP:  //KSoIp6JoinGroup
       
   678 		case IP_DROP_MEMBERSHIP: //KSoIp6LeaveGroup
       
   679 
       
   680 			mreq = (struct ip_mreq *)anOption.Ptr();
       
   681 			from = (TUint8 *)anOption.Ptr(); 
       
   682 			from+=4;
       
   683 			// swaping the byte order
       
   684 			srcAddr = ByteOrder::Swap32( mreq->imr_interface.s_addr); 
       
   685 			//fetch the interface index
       
   686 			aIndex = GetInterfaceIndex(srcAddr);
       
   687 
       
   688 			// Set the multicast addr
       
   689 			from = (TUint8 *)anOption.Ptr();
       
   690 			maddr=(from[0]<<24)+(from[1]<<16)+(from[2]<<8)+from[3];
       
   691 			multiAddr.SetAddress( maddr);
       
   692 			multiAddr.ConvertToV4Mapped();
       
   693 			if(multiAddr.IsMulticast()){
       
   694 			req().iAddr = multiAddr.Ip6Address();
       
   695 			req().iInterface = aIndex;  
       
   696 			}
       
   697 			return iSocket.SetOpt(anOptionName, anOptionLevel, req);
       
   698 
       
   699 		case IP_MULTICAST_TTL:
       
   700 			anOptionLevel=KSolInetIp;
       
   701 			anOptionName=KSoIp6MulticastHops;
       
   702 			Option = (TInt*)anOption.Ptr();
       
   703 			ttlValue = *Option;
       
   704 			return iSocket.SetOpt(anOptionName,anOptionLevel,ttlValue);
       
   705 
       
   706 		case SO_BROADCAST: 
       
   707 			//check if user is trying to disable broadcast
       
   708 			Option = (TInt*)anOption.Ptr();
       
   709 			if (*Option == 0)  
       
   710 				{
       
   711 				return KErrNotSupported;
       
   712 				}	
       
   713 			else 
       
   714 				{
       
   715 				return KErrNone;	
       
   716 				}
       
   717 
       
   718 		case IP_MULTICAST_IF:
       
   719 			{
       
   720 			//No support for equivalent flag KsoIp6MulticastIf presently
       
   721 			//call bind instead	    
       
   722 			struct in_addr *inAddress = (struct in_addr*)anOption.Ptr();	    
       
   723 			struct sockaddr_in sockAddress; 	 		    
       
   724 			sockAddress.sin_family = AF_INET;
       
   725 			sockAddress.sin_port = iSocket.LocalPort();
       
   726 			sockAddress.sin_addr.s_addr = inAddress->s_addr;
       
   727 			TUSockAddr ifAddress(&sockAddress, sizeof(sockAddress));    	
       
   728 			return iSocket.Bind(ifAddress);		
       
   729 			}
       
   730 
       
   731 		case IP_MULTICAST_LOOP:
       
   732 			anOptionLevel=KSolInetIp;
       
   733 			anOptionName=KSoIp6MulticastLoop;
       
   734 			break;	    	
       
   735 
       
   736 		default:
       
   737 			break;
       
   738 
       
   739 		}
       
   740 	return iSocket.SetOpt(anOptionName,anOptionLevel,anOption);
       
   741 	}
       
   742 
       
   743 void CSocketDesc::Sync (TRequestStatus& aStatus)
       
   744 	{
       
   745 	// Judging from the Solaris man pages, this does nothing.
       
   746 	Complete(aStatus,KErrNone);
       
   747 	}
       
   748 
       
   749 void CSocketDesc::RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus)
       
   750 	{
       
   751 	iReadLock.Wait();
       
   752 	// RSocket::Open() is postponed from socket()
       
   753 	if (iSocketPtr == NULL)
       
   754 		{
       
   755 		TInt ret = OpenUsingPreference();
       
   756 		if (ret != KErrNone)
       
   757 			{
       
   758 			Complete(aStatus,ret);	// Error in open
       
   759 			iReadLock.Signal();
       
   760 			return;
       
   761 			}
       
   762 		}
       
   763 
       
   764 	CSockDescBase::RecvFrom(aDesc, from, flags, aStatus);
       
   765 	iReadLock.Signal();
       
   766 	}
       
   767 
       
   768 void CSocketDesc::RecvFromCancel()
       
   769 	{
       
   770 	if (iSocketPtr != NULL)
       
   771 		{
       
   772 		CSockDescBase::RecvFromCancel();
       
   773 		}
       
   774 	}
       
   775 
       
   776 
       
   777 void CSocketDesc::SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen, int flags, TRequestStatus& aStatus)
       
   778 	{
       
   779 	iWriteLock.Wait();	
       
   780 
       
   781 	if (iSocketPtr == NULL)
       
   782 		{
       
   783 		TInt ret = OpenUsingPreference();
       
   784 		if (ret != KErrNone)
       
   785 			{
       
   786 			Complete(aStatus,ret);   // Error in open
       
   787 			iWriteLock.Signal();
       
   788 			return;
       
   789 			}
       
   790 		}
       
   791 	TUSockAddr toAddr(anAddr,aAddrLen);
       
   792 	CSockDescBase::SendTo(aDesc, toAddr, flags, aStatus);
       
   793 	iWriteLock.Signal();
       
   794 	}
       
   795 
       
   796 void CSocketDesc::SendToCancel()
       
   797 	{
       
   798 	if (iSocketPtr != NULL)
       
   799 		{
       
   800 		CSockDescBase::SendToCancel();
       
   801 		}
       
   802 	}
       
   803 
       
   804 void CSocketDesc::Shutdown(TUint aHow,TRequestStatus& aStatus)
       
   805 	{
       
   806 	if (iSocketPtr == NULL) // Not opened at all. Nothing to do.
       
   807 		{
       
   808 		Complete(aStatus,KErrNone);
       
   809 		return;
       
   810 		}
       
   811 
       
   812 	CSockDescBase::Shutdown(aHow,aStatus);
       
   813 	return;
       
   814 	}
       
   815 
       
   816 void CSocketDesc::Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs, TSockAddr * /*aAddr*/)
       
   817 	{
       
   818 	//Acquire the Lock before accept and release it later
       
   819 	iReadLock.Wait();
       
   820 
       
   821 	TInt err = KErrNone;
       
   822 	if (iSocketPtr == NULL)
       
   823 		{
       
   824 		err = OpenUsingPreference();
       
   825 		if (err != KErrNone)	// Error in open
       
   826 			{			
       
   827 			Complete(aStatus,err);
       
   828 			iReadLock.Signal();
       
   829 			return;
       
   830 			}
       
   831 		}
       
   832 
       
   833 	//coverity[alloc_fn]
       
   834 	//coverity[assign]
       
   835 	CSocketDesc *newSocket = new CSocketDesc;
       
   836 	if (newSocket!=0)
       
   837 		{
       
   838 		err = newSocket->CreateLock();
       
   839 		if (err)
       
   840 			{
       
   841 			Complete(aStatus, KErrNoMemory);
       
   842 			delete newSocket;
       
   843 			aNewSocket = NULL;
       
   844 			iReadLock.Signal();
       
   845 			//coverity[memory_leak]
       
   846 			return;
       
   847 			}
       
   848 
       
   849 		err=newSocket->iSocket.Open(aSs);
       
   850 		}
       
   851 	if (newSocket ==0 || err!=KErrNone)
       
   852 		{
       
   853 		Complete(aStatus,KErrNoMemory);
       
   854 		delete newSocket;
       
   855 		aNewSocket = NULL;
       
   856 		iReadLock.Signal();
       
   857 		//coverity[memory_leak]
       
   858 		return;
       
   859 		}
       
   860 	newSocket->iSocketPtr = &newSocket->iSocket;
       
   861 	newSocket->iStyle = iStyle;
       
   862 	iSocket.Accept(newSocket->iSocket,aStatus);
       
   863 	aNewSocket = newSocket;
       
   864 	iReadLock.Signal();
       
   865 	}
       
   866 
       
   867 void CSocketDesc::AcceptCancel()
       
   868 	{
       
   869 	if (iSocketPtr != NULL)
       
   870 		{
       
   871 		iSocket.CancelAccept();
       
   872 		}
       
   873 	}
       
   874 
       
   875 void CSocketDesc::Connect(const struct sockaddr* aAddr,unsigned long size,TRequestStatus& aStatus)
       
   876 	{
       
   877 	TUSockAddr addr(aAddr,size);
       
   878 
       
   879 	if (addr.iError != 0)
       
   880 		{
       
   881 		aStatus = addr.iError;
       
   882 		return;
       
   883 		}
       
   884 	if (iSocketPtr == NULL)
       
   885 		{
       
   886 		// RSocket::Open() is postponed from socket()	
       
   887 		TInt ret = OpenUsingPreference();
       
   888 		if (ret != KErrNone)	// error in open
       
   889 			{
       
   890 			aStatus = ret;
       
   891 			return;
       
   892 			}
       
   893 		}
       
   894 
       
   895 	iSocket.Connect(addr,aStatus);
       
   896 	User::WaitForRequest(aStatus);
       
   897 	}
       
   898 
       
   899 void CSocketDesc::ConnectCancel()
       
   900 	{
       
   901 	if (iSocketPtr != NULL)
       
   902 		{
       
   903 		iSocket.CancelConnect();
       
   904 		}
       
   905 	}
       
   906 
       
   907 void CSocketDesc::Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus)
       
   908 	{
       
   909 	TInt ret=KErrNone;
       
   910 	int* param = reinterpret_cast<int*>(aParam);
       
   911 
       
   912 	if (iSocketPtr == NULL)
       
   913 		{
       
   914 		ret = OpenUsingPreference();
       
   915 		if (ret != KErrNone)	// Error in open
       
   916 			{
       
   917 			Complete(aStatus,ret);
       
   918 			return;
       
   919 			}
       
   920 		}
       
   921 
       
   922 	switch ((unsigned)aCmd)
       
   923 		{
       
   924 		case FIONREAD:
       
   925 		case E32IONREAD:
       
   926 			ret=iSocket.GetOpt(KSOReadBytesPending,KSOLSocket,*param);
       
   927 			break;
       
   928 		case E32IOSELECT:
       
   929 			{
       
   930 			iIoctlBuf.Set((TText8*)aParam,4,4);
       
   931 			iIoctlLock.Wait();
       
   932 			iIoctlFlag = ETrue;		
       
   933 			iSocket.Ioctl(KIOctlSelect,aStatus,&iIoctlBuf,KSOLSocket);
       
   934 			}
       
   935 			return;
       
   936 		case SIOCGIFCONF:
       
   937 			ret = GetInterfaceList(aParam);
       
   938 			break;
       
   939 		case SIOCGIFINDEX:
       
   940 			ret = GetInterfaceIndexByName(aParam);
       
   941 			break;
       
   942 		case SIOCGIFACTIVECONF:
       
   943 			ret = GetActiveInterfaceList(aParam);
       
   944 			break;
       
   945 		case SIOCSIFNAME:
       
   946 			ret = SetInterfaceByName(aParam);
       
   947 			break;
       
   948 		case SIOCIFSTART:
       
   949 			ret = StartInterface(aParam);
       
   950 			if(KErrNone == ret)
       
   951 				{
       
   952 				iSocket.Close();
       
   953 				iSocketPtr = NULL;
       
   954 				}
       
   955 			break;
       
   956 		case SIOCIFACTIVESTART:
       
   957 			ret = StartActiveInterface(aParam);
       
   958 			if(KErrNone == ret)
       
   959 				{
       
   960 				iSocket.Close();
       
   961 				iSocketPtr = NULL;
       
   962 				}
       
   963 			break;
       
   964 		case SIOCIFSTOP:
       
   965 			ret = StopInterface(aParam);
       
   966 			break;	
       
   967 		case SIOCATMARK:
       
   968 			ret=iSocket.GetOpt(KSoTcpRcvAtMark,KSolInetTcp,*param);
       
   969 			break;	
       
   970 		case SIOCGIFADDR:
       
   971 			ret = GetIpAddress(aParam);
       
   972 			break;	
       
   973 		case SIOCGIFNUM:
       
   974 			ret = GetInterafceNumber(aParam);
       
   975 			break;	
       
   976 		case SIOCADDRT:
       
   977 			ret = RouteRequest(KSoInetAddRoute, aParam);
       
   978 			break;	
       
   979 		case SIOCDELRT:		
       
   980 			ret = RouteRequest(KSoInetDeleteRoute, aParam);
       
   981 			break;	
       
   982 		case SIOCGIFHWADDR:
       
   983 			ret = GetInterfaceHWAddress(aParam);
       
   984 		    break;
       
   985 		case SIOCGIFACTIVEIAP:
       
   986 		    ret = GetActiveInterface( aParam);
       
   987 		    break;
       
   988 		
       
   989 		default:
       
   990 			ret=KErrNotSupported;
       
   991 			break;
       
   992 		}
       
   993 	Complete(aStatus,ret);
       
   994 	}
       
   995 
       
   996 TInt CSocketDesc::IoctlCompletion(int /*aCmd*/, void* /*aParam*/, TInt aStatus)
       
   997 	{
       
   998 	if(iIoctlFlag)
       
   999 		{
       
  1000 		iIoctlLock.Signal();
       
  1001 		iIoctlFlag = EFalse;
       
  1002 		}
       
  1003 	return aStatus;
       
  1004 	}
       
  1005 
       
  1006 void CSocketDesc::IoctlCancel()
       
  1007 	{
       
  1008 	if (iSocketPtr && iIoctlFlag)
       
  1009 		{
       
  1010 		iSocket.CancelIoctl();
       
  1011 		iIoctlLock.Signal();
       
  1012 		iIoctlFlag = EFalse;
       
  1013 		}
       
  1014 	}
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // CSocketDesc::Fcntl
       
  1017 // Symbian Socket Specific Implementation for fcntl
       
  1018 // Implementation of fcntl for Socket will make use of  
       
  1019 // RSocket::SetOpt(KSONonBlockingIO/KSOBlockingIO, KSOLSocket)
       
  1020 // As of now fcntl supports F_SETFL and F_GETFL
       
  1021 // -----------------------------------------------------------------------------
       
  1022 //
       
  1023 TInt CSocketDesc::Fcntl(TUint anArg, TUint aCmd)
       
  1024 	{
       
  1025 	if (iSocketPtr == NULL)
       
  1026 		{
       
  1027 		TInt ret = OpenUsingPreference();
       
  1028 		if (ret != KErrNone)	// Error in open
       
  1029 			{
       
  1030 			return ret;
       
  1031 			}
       
  1032 		}
       
  1033 	return CSockDescBase::Fcntl(anArg, aCmd);
       
  1034 	}
       
  1035 
       
  1036 TInt CSocketDesc :: GetIpAddress( void *aParam )
       
  1037 	{
       
  1038 	TInetAddr myAddr;
       
  1039 	iSocket.LocalName(myAddr);
       
  1040 	TUint32 myIP = myAddr.Address();			
       
  1041 	ifreq *ifr = (ifreq *)aParam;
       
  1042 	if(myIP == 0)
       
  1043 		{
       
  1044 		return KErrGeneral;
       
  1045 		}
       
  1046 	((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr = myIP;
       
  1047 	return KErrNone;
       
  1048 	}
       
  1049 
       
  1050 TInt CSocketDesc :: GetRemoteIpAddress( void *aParam )
       
  1051 	{
       
  1052 	TInetAddr remoteAddr;
       
  1053 	iSocket.RemoteName(remoteAddr);
       
  1054 	TUint32 remoteIP = remoteAddr.Address();			
       
  1055 	ifreq *ifr = (ifreq *)aParam;
       
  1056 	if(remoteIP == 0)
       
  1057 		{
       
  1058 		return KErrGeneral;
       
  1059 		}
       
  1060 	((struct sockaddr_in *)&ifr->ifr_dstaddr)->sin_addr.s_addr = remoteIP;
       
  1061 	return KErrNone;
       
  1062 	}
       
  1063 
       
  1064 TInt CSocketDesc :: GetInterafceNumber( void *aParam )
       
  1065 	{
       
  1066 	TInt count = 0;	
       
  1067 	TInt ret = KErrNone;
       
  1068 	TRAP(ret, AccessPointCountL(count));
       
  1069 	*(TInt *)aParam = count;
       
  1070 	return ret;	
       
  1071 	}
       
  1072 
       
  1073 #ifdef __SYMBIAN_COMPILE_UNUSED__
       
  1074 TInt CSocketDesc :: GetInterafceParamInfo( void *aParam,TInt aType)
       
  1075 	{
       
  1076 	TInt ret = KErrNone;	
       
  1077 	TAccessPointRecord tempRecord;
       
  1078 	ifreq *ifr = (ifreq *)aParam;
       
  1079 	TRAP(ret,FindConnectionInfoL(tempRecord,ifr->ifr_name));
       
  1080 	if(ret != KErrNone)
       
  1081 		return ret;
       
  1082 	wchar_t *str = (wchar_t *)( tempRecord.iServiceType.PtrZ());	 
       
  1083 	TInt servFlag = 0;
       
  1084 	if(WcsCmp(str,L"LANService") == 0)
       
  1085 		{
       
  1086 		servFlag = 0;
       
  1087 		}
       
  1088 	else if(WcsCmp(str,L"OutgoingGPRS") == 0)
       
  1089 		{
       
  1090 		servFlag  = 1;	
       
  1091 		}
       
  1092 	if(aType == EACCESS_GETMETRIC)
       
  1093 		{
       
  1094 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETMETRIC);					
       
  1095 		}	
       
  1096 	else if(aType == EACCESS_GETMTU)
       
  1097 		{
       
  1098 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETMTU);					
       
  1099 		}
       
  1100 	else if(aType == EACCESS_GETNETMASK)
       
  1101 		{
       
  1102 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETNETMASK);					
       
  1103 		}
       
  1104 	else if(aType == EACCESS_GETBROADCAST)
       
  1105 		{
       
  1106 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETBROADCAST);					
       
  1107 		}
       
  1108 	else if(aType == EACCESS_GETPHYSADDR)
       
  1109 		{
       
  1110 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETPHYSADDR);					
       
  1111 		}
       
  1112 	else if(aType == EACCESS_GETFLAGS)
       
  1113 		{
       
  1114 		ret = GetInterfaceDetails(aParam,servFlag,EACCESS_GETFLAGS);					
       
  1115 		}
       
  1116 	return ret;	
       
  1117 	}
       
  1118 
       
  1119 TInt CSocketDesc :: SetInterafceParamInfo( void *aParam,TInt aType)
       
  1120 	{
       
  1121 	TInt ret = KErrNone;	
       
  1122 	TAccessPointRecord tempRecord;
       
  1123 	ifreq *ifr = (ifreq *)aParam;
       
  1124 	TRAP(ret,FindConnectionInfoL(tempRecord,ifr->ifr_name));
       
  1125 	if(ret != KErrNone)
       
  1126 		return ret;
       
  1127 	wchar_t *str = (wchar_t *)(tempRecord.iServiceType.PtrZ());	 
       
  1128 	TInt servFlag = 0;
       
  1129 	if(WcsCmp(str,L"LANService") == 0)
       
  1130 		{
       
  1131 		servFlag = 0;
       
  1132 		}
       
  1133 	else if(WcsCmp(str,L"OutgoingGPRS") == 0)
       
  1134 		{
       
  1135 		servFlag  = 1;	
       
  1136 		}
       
  1137 	if(aType == EACCESS_SETMETRIC)
       
  1138 		{
       
  1139 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETMETRIC);					
       
  1140 		}	
       
  1141 	else if(aType == EACCESS_SETMTU)
       
  1142 		{
       
  1143 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETMTU);					
       
  1144 		}		
       
  1145 	else if(aType == EACCESS_SETFLAGS)
       
  1146 		{
       
  1147 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETFLAGS);					
       
  1148 		}
       
  1149 	else if(aType == EACCESS_SETPHYSADDR)
       
  1150 		{
       
  1151 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETPHYSADDR);					
       
  1152 		}	
       
  1153 	else if(aType == EACCESS_SETNETMASK)
       
  1154 		{
       
  1155 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETNETMASK);					
       
  1156 		}	
       
  1157 	else if(aType == EACCESS_SETBROADCAST)
       
  1158 		{
       
  1159 		ret = SetInterfaceDetails(aParam,servFlag,EACCESS_SETBROADCAST);					
       
  1160 		}		
       
  1161 	return ret;	
       
  1162 
       
  1163 	}
       
  1164 
       
  1165 void CSocketDesc::FindConnectionInfoL(TAccessPointRecord &aRecord,char *ptr)
       
  1166 	{
       
  1167 	//TAccessPointRecord tempRecord;
       
  1168 	CCommsDatabase* iapDatabase;
       
  1169 	CCommsDbTableView* view;
       
  1170 	TInt res;	
       
  1171 	TPtrC8 tptr((TText8*)ptr);
       
  1172 	TBuf<KCommsDbSvrMaxColumnNameLength> temp;
       
  1173 	res = CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, tptr);
       
  1174 	if(res < KErrNone)
       
  1175 		{
       
  1176 		User::Leave(res);
       
  1177 		}
       
  1178 	else if(res > KErrNone)
       
  1179 		{
       
  1180 		User::Leave(KErrOverflow);
       
  1181 		}
       
  1182 	// This function can leave on insufficient memory
       
  1183 	OpenIapTableLC(&iapDatabase, &view);	
       
  1184 	res = view->GotoFirstRecord();
       
  1185 	while (res == KErrNone)
       
  1186 		{    	
       
  1187 		// On error continue with the next record	
       
  1188 		TRAP( res,ReadRecordFromIapTableL(view, aRecord));
       
  1189 		if (res == KErrNone)
       
  1190 			{   
       
  1191 			if(WcsCmp ((wchar_t*)aRecord.iName.PtrZ(),(wchar_t*)temp.PtrZ()) == 0)
       
  1192 				break; 	
       
  1193 			}    	
       
  1194 		res = view->GotoNextRecord();
       
  1195 		}
       
  1196 	CleanupStack::PopAndDestroy();// view
       
  1197 	CleanupStack::PopAndDestroy(iapDatabase);	
       
  1198 	return;
       
  1199 	}
       
  1200 
       
  1201 TInt CSocketDesc :: SetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType )
       
  1202 	{
       
  1203 	ifreq *ifr = (ifreq *)aParam;
       
  1204 	TPckgBuf<TSoInetIfQuery> ifq;
       
  1205 	TBuf8 <25> ipBuf8;
       
  1206 	TName aBuf;			
       
  1207 
       
  1208 	TInt ret = iSocket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
       
  1209 	if (ret != KErrNone)
       
  1210 		{
       
  1211 		return KErrGeneral;
       
  1212 		}    	
       
  1213 	TPckgBuf<TSoInet6InterfaceInfo> info;
       
  1214 	TSoInet6InterfaceInfo &in = info();	
       
  1215 
       
  1216 	while(iSocket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info) == KErrNone)
       
  1217 		{			
       
  1218 		if(info().iName != _L("") && info().iName != _L("loop6") && info().iName != _L("loop4"))
       
  1219 			{   			
       
  1220 			TDes16& aName = info().iName;							
       
  1221 			if( ((aFlag == 0 ) && ( aName.FindC(_L("WLAN")) != KErrNotFound )) ||
       
  1222 					((aFlag == 1) && (aName.FindC(_L("Generic")) != KErrNotFound )) )
       
  1223 				{
       
  1224 				switch(aType)
       
  1225 					{				
       
  1226 					case  EACCESS_SETMETRIC:
       
  1227 						if(info().iState == EIfUp)										 
       
  1228 							{
       
  1229 							info().iSpeedMetric =  ifr->ifr_metric;
       
  1230 							}
       
  1231 						goto setout;
       
  1232 
       
  1233 					case  EACCESS_SETMTU:										 
       
  1234 						if(info().iState == EIfUp)
       
  1235 							{
       
  1236 							info().iMtu = ifr->ifr_mtu ;		
       
  1237 							}		
       
  1238 						goto setout;
       
  1239 
       
  1240 					case  EACCESS_SETNETMASK :																																																					
       
  1241 						// Presently netmask address is NULL											
       
  1242 						if((info().iState == EIfUp) && (ifr->ifr_addr.sa_data !=NULL))
       
  1243 							{																																																		
       
  1244 							/*
       
  1245 							CharToTBuf8(ifr->ifr_addr.sa_data,ipBuf8);											
       
  1246 											if (CnvUtfConverter::ConvertToUnicodeFromUtf8( aBuf,ipBuf8 ) == KErrNone)
       
  1247 											{													
       
  1248 												ret = info().iNetMask.Input(aBuf);												
       
  1249 											}																							
       
  1250 							info().iNetMask.SetAddress(INET_ADDR(255,255,255,0));	
       
  1251 							*/
       
  1252 							return KErrNotSupported;
       
  1253 							}
       
  1254 						break;	
       
  1255 					case  EACCESS_SETBROADCAST :										
       
  1256 						if((info().iState == EIfUp) && (ifr->ifr_broadaddr.sa_data !=NULL))
       
  1257 							{																																																		
       
  1258 							/*CharToTBuf8(ifr->ifr_broadaddr.sa_data,ipBuf8);											
       
  1259 											if (CnvUtfConverter::ConvertToUnicodeFromUtf8( aBuf,ipBuf8 ) == KErrNone)
       
  1260 											{													
       
  1261 												ret = info().iBrdAddr.Input(aBuf);												
       
  1262 											} 
       
  1263 							*/												
       
  1264 							return KErrNotSupported;
       
  1265 							}
       
  1266 
       
  1267 						break;
       
  1268 					case  EACCESS_SETPHYSADDR :										
       
  1269 						// Currently no imeplentation is given as KIfHasHardwareAddr is always 
       
  1270 						// set to 0 for wlan and GPRS
       
  1271 						if(info().iFeatures&KIfHasHardwareAddr)
       
  1272 							{
       
  1273 							return KErrNotSupported;
       
  1274 							}
       
  1275 						break;									
       
  1276 					case  EACCESS_SETFLAGS :										
       
  1277 						info().iFeatures = 0;
       
  1278 						// Interface UP
       
  1279 						if((ifr->ifr_flags & IFF_UP) && (ifr->ifr_flags & IFF_DRV_RUNNING)) 
       
  1280 							{
       
  1281 							info().iState = EIfUp;																						
       
  1282 							}																						
       
  1283 						else
       
  1284 							{
       
  1285 							info().iState = EIfDown;																																	
       
  1286 							}																																	
       
  1287 
       
  1288 						// Loopback										
       
  1289 						if(ifr->ifr_flags & IFF_LOOPBACK)
       
  1290 							{
       
  1291 							info().iFeatures |= KIfIsLoopback;																				            													           
       
  1292 							}																				            													           
       
  1293 
       
  1294 						// point to point support
       
  1295 						if(ifr->ifr_flags &  IFF_POINTOPOINT)
       
  1296 							{
       
  1297 							info().iFeatures |= KIfIsPointToPoint; 							                
       
  1298 							} 							                
       
  1299 
       
  1300 						// Broadcast
       
  1301 						if(ifr->ifr_flags & IFF_BROADCAST)
       
  1302 							{
       
  1303 							info().iFeatures |=KIfCanBroadcast; 
       
  1304 							} 
       
  1305 
       
  1306 
       
  1307 						// Multicast
       
  1308 						if(ifr->ifr_flagshigh & IFF_MULTICAST)
       
  1309 							{
       
  1310 							info().iFeatures = KIfCanMulticast;							            	      
       
  1311 							}
       
  1312 						//these flags details are available in symbian but not used by lib layer.
       
  1313 						/* if(info().iFeatures&KIfCanSetMTU)			            	
       
  1314 							               if(info().iFeatures&KIfHasHardwareAddr)    
       
  1315 							               if(info().iFeatures&KIfCanSetHardwareAddr) */
       
  1316 						goto setout;							            	
       
  1317 
       
  1318 					default:
       
  1319 						break;					 
       
  1320 					}
       
  1321 				}
       
  1322 
       
  1323 			}					 	 
       
  1324 		}
       
  1325 	setout:	
       
  1326 	TPckgBuf<TSoInet6InterfaceInfo> changeToNew(info());
       
  1327 	return iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl,changeToNew); 		
       
  1328 	}
       
  1329 #endif // __SYMBIAN_COMPILE_UNUSED__
       
  1330 
       
  1331 TInt CSocketDesc::GetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType )
       
  1332 	{
       
  1333 	ifreq *ifr = (ifreq *)aParam;
       
  1334 	TPckgBuf<TSoInetIfQuery> ifq;
       
  1335 
       
  1336 	TInt ret = iSocket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
       
  1337 	if (ret != KErrNone)
       
  1338 		{
       
  1339 		return KErrGeneral;
       
  1340 		}
       
  1341     *(ifr->ifr_addr.sa_data) = '\0';
       
  1342 
       
  1343 	TPckgBuf<TSoInetInterfaceInfo> info;
       
  1344 	while(iSocket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info) == KErrNone)
       
  1345 		{
       
  1346 
       
  1347 		if(info().iName != _L("") && info().iName != _L("loop6") && info().iName != _L("loop4"))
       
  1348 			{   
       
  1349 			TDes16& aName = info().iName;
       
  1350 			TName aBuf;
       
  1351 			TBuf8<KMaxName> ipAddr;
       
  1352 			if( ((aFlag == 0 ) && ( aName.FindC(_L("WLAN")) != KErrNotFound )) ||
       
  1353 					((aFlag == 1) && (aName.FindC(_L("Generic")) != KErrNotFound )) )
       
  1354 				{
       
  1355 				switch(aType)
       
  1356 					{
       
  1357 
       
  1358 					case  EACTIVE_GETIP :
       
  1359 						if((info().iState == EIfUp) && (info().iAddress.Address() != NULL))
       
  1360 							{
       
  1361 							if(!((info().iAddress.IsLinkLocal()) || (info().iAddress.IsSiteLocal())))
       
  1362 								{
       
  1363 								info().iAddress.Output(aBuf);  
       
  1364 								if (CnvUtfConverter::ConvertFromUnicodeToUtf8( ipAddr, aBuf ) == KErrNone)
       
  1365 									{			
       
  1366 									StrlCopy(ifr->ifr_addr.sa_data,(const char *) ipAddr.PtrZ(),ipAddr.Length()+1);														
       
  1367 									}  
       
  1368 								}
       
  1369 							}
       
  1370 						break;
       
  1371 					case  EACCESS_GETMETRIC:
       
  1372 						ifr->ifr_metric = 0;
       
  1373 						if (info().iState == EIfUp)
       
  1374 							{
       
  1375 							ifr->ifr_metric = info().iSpeedMetric;
       
  1376 							}
       
  1377 						break;
       
  1378 					case  EACCESS_GETMTU:
       
  1379 						ifr->ifr_mtu = 0;
       
  1380 						if (info().iState == EIfUp)
       
  1381 							{
       
  1382 							ifr->ifr_mtu = info().iMtu;
       
  1383 							}
       
  1384 						break;	
       
  1385 					case  EACCESS_GETNETMASK :
       
  1386 						*(ifr->ifr_addr.sa_data) = '\0';
       
  1387 						// Presently netmask address is NULL
       
  1388 						if((info().iState == EIfUp) && (info().iNetMask.Address() != NULL))
       
  1389 							{
       
  1390 							//anAddr = info().iNetMask.Address();	
       
  1391 							info().iNetMask.Output(aBuf);  
       
  1392 							if (CnvUtfConverter::ConvertFromUnicodeToUtf8( ipAddr, aBuf ) == KErrNone)
       
  1393 								{			
       
  1394 								StrlCopy(ifr->ifr_addr.sa_data,(const char *) ipAddr.PtrZ(),ipAddr.Length()+1);												
       
  1395 								}  											
       
  1396 							}
       
  1397 						break;	
       
  1398 					case  EACCESS_GETBROADCAST :
       
  1399 						*(ifr->ifr_broadaddr.sa_data) = '\0';
       
  1400 						// Presently Breaodcast address is NULL
       
  1401 						if((info().iState == EIfUp) && (info().iBrdAddr.Address() != NULL))
       
  1402 							{
       
  1403 
       
  1404 							//anAddr = info().iBrdAddr.Address();	
       
  1405 							info().iBrdAddr.Output(aBuf);  
       
  1406 							if (CnvUtfConverter::ConvertFromUnicodeToUtf8( ipAddr, aBuf ) == KErrNone)
       
  1407 								{			
       
  1408 								StrlCopy(ifr->ifr_broadaddr.sa_data,(const char *) ipAddr.PtrZ(),ipAddr.Length()+1);												
       
  1409 								}											
       
  1410 							}
       
  1411 						break;
       
  1412 					case  EACCESS_GETPHYSADDR :
       
  1413 						ifr->ifr_phys = 0;
       
  1414 						// Currently no imeplentation is given as KIfHasHardwareAddr is always 
       
  1415 						// set to 0 for wlan and GPRS
       
  1416 						if(info().iFeatures&KIfHasHardwareAddr)
       
  1417 							{
       
  1418 							//nada.
       
  1419 							}
       
  1420 						break;									
       
  1421 					case  EACCESS_GETFLAGS :
       
  1422 						ifr->ifr_flags = 0;
       
  1423 						ifr->ifr_flagshigh=0;
       
  1424 						// Interface UP
       
  1425 						if(info().iState == EIfUp)
       
  1426 							{
       
  1427 							ifr->ifr_flags |= IFF_UP; 
       
  1428 							ifr->ifr_flags |= IFF_DRV_RUNNING;
       
  1429 							}
       
  1430 						// Loopback
       
  1431 						if(info().iFeatures&KIfIsLoopback)
       
  1432 							{
       
  1433 							ifr->ifr_flags |= IFF_LOOPBACK;
       
  1434 							}										            													           
       
  1435 
       
  1436 						// point to point support
       
  1437 						if(info().iFeatures&KIfIsPointToPoint) 
       
  1438 							{
       
  1439 							ifr->ifr_flags |= IFF_POINTOPOINT;	
       
  1440 							}
       
  1441 						
       
  1442 						// Broadcast
       
  1443 						if(info().iFeatures&KIfCanBroadcast)
       
  1444 							{
       
  1445 							ifr->ifr_flags |= IFF_BROADCAST;
       
  1446 							}      
       
  1447 
       
  1448 						// Multicast
       
  1449 						if(info().iFeatures&KIfCanMulticast)
       
  1450 							{
       
  1451 							ifr->ifr_flagshigh |= ((IFF_MULTICAST & 0xff00) >> 8);
       
  1452 							}
       
  1453 						//these flags details are available in symbian but not used by lib layer.
       
  1454 						/* if(info().iFeatures&KIfCanSetMTU)			            	
       
  1455 							               if(info().iFeatures&KIfHasHardwareAddr)    
       
  1456 							               if(info().iFeatures&KIfCanSetHardwareAddr) */
       
  1457 
       
  1458 						break;																 				 
       
  1459 					default:
       
  1460 						break;					 
       
  1461 					}
       
  1462 				}
       
  1463 
       
  1464 			}				 	 
       
  1465 		}
       
  1466 
       
  1467 	return KErrNone;	
       
  1468 	}
       
  1469 
       
  1470 TInt CSocketDesc::Poll(TPollMode aMode,TBool& aReadyStatus,TInt& aErrno)
       
  1471 	{
       
  1472 	TInt ret;
       
  1473 
       
  1474 	if (iSocketPtr == NULL)
       
  1475 		{
       
  1476 		ret = OpenUsingPreference();
       
  1477 		if (ret != KErrNone)	// Error in open
       
  1478 			{
       
  1479 			return ret;
       
  1480 			}
       
  1481 		}
       
  1482 
       
  1483     TInt status;
       
  1484     ret = iSocket.GetOpt(KSOSelectPoll, KSOLSocket, status);
       
  1485     if (ret == KErrNone)
       
  1486 		{
       
  1487     	aReadyStatus = status & aMode;	
       
  1488 		}
       
  1489     
       
  1490     return MapError(ret, aErrno);
       
  1491 	}
       
  1492 
       
  1493 /* The synchronous - non-blocking Poll */
       
  1494 TInt CSocketDesc::Poll(TUint aEvents)
       
  1495 	{
       
  1496 	TInt err = 0;
       
  1497 
       
  1498 	if (iSocketPtr == NULL)
       
  1499 		{
       
  1500 		err = OpenUsingPreference();
       
  1501 		if (err != KErrNone)	// Error in open
       
  1502 			{
       
  1503 			return err;
       
  1504 			}
       
  1505 		}
       
  1506 	return CSockDescBase::Poll(aEvents);
       
  1507 	}
       
  1508 
       
  1509 
       
  1510 /* Cancel an outstanding notification request */
       
  1511 void CSocketDesc::CancelNotify()
       
  1512 	{
       
  1513 	CSockDescBase::CancelNotify();
       
  1514 	}
       
  1515 
       
  1516 TAccessPointRecord::TAccessPointRecord()
       
  1517 :iId(0), 
       
  1518 iName(0),
       
  1519 iDialogPref(ECommDbDialogPrefDoNotPrompt),
       
  1520 iDirection(ECommDbConnectionDirectionUnknown), 
       
  1521 iService(0),
       
  1522 iServiceType(0), // Text value
       
  1523 iBearer(0),
       
  1524 iBearerType(0),	// Text value
       
  1525 iNetwork(0),
       
  1526 iNetworkWeighting(0),
       
  1527 iLocation(0)
       
  1528 		{
       
  1529 		}
       
  1530 
       
  1531 inline TInt CSocketDesc::GetInterfaceList(void *aParam)
       
  1532 	{
       
  1533 	return GetInterface(aParam, EACCESS_POINT);
       
  1534 	}
       
  1535 
       
  1536 TInt CSocketDesc::GetInterfaceIndexByName(void *aParam)
       
  1537 	{
       
  1538 	ifreq *ifrQuery = (ifreq*)aParam;	
       
  1539 	ifconf ifc;
       
  1540 
       
  1541 	// Know how many interfaces
       
  1542 	ifc.ifc_len = 0;
       
  1543 	ifc.ifc_buf = NULL;
       
  1544 	TInt ret = GetInterface(&ifc, EACCESS_POINT);
       
  1545 	if (ret != KErrNone)
       
  1546 		{
       
  1547 		return ret;
       
  1548 		}
       
  1549 
       
  1550 	// Allocate the memory to get the detail interface information
       
  1551 	ifc.ifc_buf = (caddr_t)Backend()->Alloc( ifc.ifc_len);
       
  1552 	if (ifc.ifc_buf == NULL)
       
  1553 		{
       
  1554 		return KErrNoMemory;
       
  1555 		}
       
  1556 	ret = GetInterface(&ifc, EACCESS_POINT);
       
  1557 	if (ret != KErrNone)
       
  1558 		{
       
  1559 		Backend()->Free(ifc.ifc_buf);
       
  1560 		return ret;
       
  1561 		}
       
  1562 	ifreq *ifr = ifc.ifc_req;
       
  1563 	TInt ifCount = ifc.ifc_len / sizeof(ifreq);
       
  1564 	TInt i = 0;
       
  1565 
       
  1566 	// Search for the interface name
       
  1567 	for (; i < ifCount; i++, ifr++)
       
  1568 		{
       
  1569 		if ( StrCmp(ifrQuery->ifr_name, ifr->ifr_name) == 0)
       
  1570 			{
       
  1571 			ifrQuery->ifr_index = ifr->ifr_index;
       
  1572 			break;
       
  1573 			}
       
  1574 		}
       
  1575 
       
  1576 	if (i == ifCount)
       
  1577 		{
       
  1578 		ret = KErrNotFound;
       
  1579 		}
       
  1580 	Backend()->Free(ifc.ifc_buf);
       
  1581 	return ret;
       
  1582 	}
       
  1583 
       
  1584 inline TInt CSocketDesc::GetActiveInterfaceList(void *aParam)
       
  1585 	{
       
  1586 	return GetInterface(aParam, EACTIVE_CONNECTION);
       
  1587 	}
       
  1588 
       
  1589 TInt CSocketDesc::GetInterface(void *aParam, TInt aType)
       
  1590 	{
       
  1591 	TInt ret = KErrNone;
       
  1592 	ifconf *ifc = (ifconf*)aParam;	
       
  1593 	TInt length = (ifc->ifc_len) / sizeof(ifreq);
       
  1594 	TInt count = 0;
       
  1595 	// If the length is zero, fill the number of interface information
       
  1596 	if ( length <= 0 || ifc->ifc_buf == NULL )
       
  1597 		{
       
  1598 		if (aType == EACCESS_POINT)
       
  1599 			{
       
  1600 			TRAP(ret, AccessPointCountL(count));
       
  1601 			}
       
  1602 		else if (aType == EACTIVE_CONNECTION)
       
  1603 			{
       
  1604 			ret = ActiveConnectionCount(count);
       
  1605 			}
       
  1606 		else
       
  1607 			{
       
  1608 			ret = KErrArgument;
       
  1609 			}
       
  1610 
       
  1611 		if (ret != KErrNone)
       
  1612 			{
       
  1613 			return ret;
       
  1614 			}
       
  1615 		ifc->ifc_len = sizeof(ifreq) * count;
       
  1616 		return ret;
       
  1617 		}
       
  1618 
       
  1619 	// length is not 0, read 'length' number of records
       
  1620 	CArrayFixFlat<TAccessPointRecord> *apArray;
       
  1621 	wchar_t *str;
       
  1622 	TInt apIndex;
       
  1623 	TInt result = KErrNone;
       
  1624 	ifreq *ifr = ifc->ifc_req;
       
  1625 	TInt ActiveSet = 0;
       
  1626 
       
  1627 	// Fixed array of 'length'
       
  1628 	apArray = new CArrayFixFlat<TAccessPointRecord>(length);
       
  1629 	if (apArray == NULL)
       
  1630 		{
       
  1631 		return KErrNoMemory;
       
  1632 		}
       
  1633 	if (aType == EACCESS_POINT)
       
  1634 		{
       
  1635 		// On return length would contain the number of access points.
       
  1636 		TRAP(result, AccessPointListL(apArray, length));
       
  1637 		}
       
  1638 	else if (aType == EACTIVE_CONNECTION)
       
  1639 		{
       
  1640 		TRAP(ret, ret=ActiveConnectionListL(apArray, length));
       
  1641 		if( ret == KErrNone )
       
  1642 			{
       
  1643 			TRAP(ret,FindConnectionDetailsL(apArray, length));
       
  1644 			ActiveSet = 1;  	
       
  1645 			}
       
  1646 		}
       
  1647 	if (ret != KErrNone)
       
  1648 		{
       
  1649 		delete apArray;
       
  1650 		return ret;
       
  1651 		}
       
  1652 	for (apIndex = 0; apIndex < length; apIndex++,ifr++)
       
  1653 		{
       
  1654 		TAccessPointRecord& ref = (*apArray)[apIndex];
       
  1655 		// Catch the character pointer
       
  1656 		TPtr8 ptr((TText8*)ifr->ifr_name, IFNAMSIZ);
       
  1657 
       
  1658 		ret = CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr, ref.iName);
       
  1659 		if(ret == KErrNone)
       
  1660 			{
       
  1661 			if(ptr.Length() < ptr.MaxLength())
       
  1662 				{
       
  1663 				ptr.ZeroTerminate();
       
  1664 				} 
       
  1665 			else
       
  1666 				{
       
  1667 				return KErrOverflow;
       
  1668 				} 
       
  1669 			}
       
  1670 		else if (ret > KErrNone)
       
  1671 			{
       
  1672 			return KErrOverflow;
       
  1673 			} 
       
  1674 		else
       
  1675 			{
       
  1676 			return ret;
       
  1677 			}
       
  1678 
       
  1679 		// Copy theinterface index
       
  1680 		ifr->ifr_index = ref.iId;
       
  1681 		if(ActiveSet == 1)
       
  1682 			{
       
  1683 			str = (wchar_t *)(ref.iServiceType.PtrZ() ); 
       
  1684 			TInt servFlag = 0;
       
  1685 			if(WcsCmp(str,L"LANService") == 0)
       
  1686 				{
       
  1687 				servFlag = 0;
       
  1688 				}
       
  1689 			else if(WcsCmp(str,L"OutgoingGPRS") == 0)
       
  1690 				{
       
  1691 				servFlag  = 1;	
       
  1692 				}
       
  1693 			GetInterfaceDetails(ifr,servFlag,EACTIVE_GETIP);
       
  1694 			}
       
  1695 		}
       
  1696 	ifc->ifc_len = sizeof(ifreq) * apIndex;
       
  1697 	delete apArray;	
       
  1698 	return KErrNone;
       
  1699 	}
       
  1700 
       
  1701 TInt CSocketDesc::SetInterfaceByName(void *aParam)
       
  1702 	{
       
  1703 	ifreq *ifr = (ifreq *)aParam;
       
  1704 	if (ifr == NULL)
       
  1705 		{
       
  1706 		return KErrArgument;
       
  1707 		}
       
  1708 
       
  1709 	// Copy the null terminated interface name
       
  1710 	TPtrC8 ptr((TText8*)ifr->ifr_name);
       
  1711 	TInt ret = CnvUtfConverter::ConvertToUnicodeFromUtf8(iConnPref.iName,ptr);
       
  1712 	if(ret > KErrNone )
       
  1713 		{
       
  1714 		return KErrOverflow;
       
  1715 		}
       
  1716 	return ret; 
       
  1717 	}
       
  1718 
       
  1719 inline TInt CSocketDesc::StartInterface(void *aParam)
       
  1720 	{
       
  1721 	return StartConnection(aParam);	
       
  1722 	}
       
  1723 
       
  1724 inline TInt CSocketDesc::StartActiveInterface(void *aParam)
       
  1725 	{
       
  1726 	return StartSubConnection(aParam);	
       
  1727 	}
       
  1728 
       
  1729 TInt CSocketDesc::StopInterface(void *)
       
  1730 	{
       
  1731 	if (iConnectionPtr != NULL)
       
  1732 		{
       
  1733 		StopConnection();
       
  1734 		return KErrNone;
       
  1735 		}
       
  1736 	else if (iSubConnectionPtr != NULL)
       
  1737 		{
       
  1738 		StopSubConnection();
       
  1739 		return KErrNone;
       
  1740 		}	
       
  1741 	return KErrNotFound;
       
  1742 	}
       
  1743 
       
  1744 TInt CSocketDesc::OpenUsingPreference()
       
  1745 	{
       
  1746 	TInt ret = 0;	
       
  1747 	RConnection defConnection = Backend()->GetDefaultConnection();
       
  1748 
       
  1749 	if (iConnectionPtr != NULL) // iConnection initialized
       
  1750 		{
       
  1751 		if (iAddrFamily == AF_INET6)
       
  1752 			{
       
  1753 			ret = iSocket.Open(*iSockServPtr,KAfInet,iStyle,iProtocol,iConnection);
       
  1754 			}
       
  1755 		else 
       
  1756 			{
       
  1757 			ret = iSocket.Open(*iSockServPtr,iAddrFamily,iStyle,iProtocol,iConnection);
       
  1758 		}
       
  1759 		}
       
  1760 	else if (iSubConnectionPtr != NULL) // iSubConnection initialized
       
  1761 		{
       
  1762 		if (iAddrFamily == AF_INET6)
       
  1763 			{
       
  1764 			ret = iSocket.Open(*iSockServPtr,KAfInet,iStyle,iProtocol,iSubConnection);
       
  1765 			}
       
  1766 		else 		
       
  1767 			{
       
  1768 			ret = iSocket.Open(*iSockServPtr,iAddrFamily,iStyle,iProtocol,iSubConnection);
       
  1769 		}
       
  1770 		}
       
  1771 	//Now check if the default connection is intialized. This is given lesser 
       
  1772 	//priority than the socket specific preferences checked above.
       
  1773 	else if(defConnection.SubSessionHandle() != 0)
       
  1774 		{
       
  1775 		if (iAddrFamily == AF_INET6)
       
  1776 			{
       
  1777 			ret = iSocket.Open(*iSockServPtr,KAfInet,iStyle,iProtocol,defConnection);
       
  1778 			}
       
  1779 		else 
       
  1780 			{
       
  1781 			ret = iSocket.Open(*iSockServPtr,iAddrFamily,iStyle,iProtocol,defConnection);
       
  1782 		}
       
  1783 		}
       
  1784 	else // No connection preference is set
       
  1785 		{
       
  1786 		if (iAddrFamily == AF_INET6)
       
  1787 			{
       
  1788 			ret = iSocket.Open(*iSockServPtr,KAfInet,iStyle,iProtocol);
       
  1789 			}
       
  1790 		else 		
       
  1791 			{
       
  1792 			ret = iSocket.Open(*iSockServPtr,iAddrFamily,iStyle,iProtocol);
       
  1793 		}
       
  1794 		}
       
  1795 	iSocketPtr = &iSocket;
       
  1796 	iConnectInProgress = EFalse;
       
  1797 	return ret;
       
  1798 	}
       
  1799 
       
  1800 void CSocketDesc::AccessPointListL(CArrayFixFlat<TAccessPointRecord> *&aRecordPtr,
       
  1801 		TInt &aCount)
       
  1802 	{
       
  1803 	TAccessPointRecord tempRecord;
       
  1804 	CCommsDatabase* iapDatabase;
       
  1805 	CCommsDbTableView* view;
       
  1806 
       
  1807 	// This function can leave on insufficient memory
       
  1808 	OpenIapTableLC(&iapDatabase, &view);
       
  1809 	TInt count = 0;
       
  1810 	TInt ret = view->GotoFirstRecord();
       
  1811     while (ret == KErrNone && count < aCount)
       
  1812 		{
       
  1813     	TRAP(ret, ReadRecordFromIapTableL(view, tempRecord));
       
  1814     	if (ret == KErrNone)
       
  1815 			{
       
  1816 			aRecordPtr->AppendL(tempRecord);
       
  1817 			count++;
       
  1818 			}	
       
  1819     	ret = view->GotoNextRecord();
       
  1820 		}
       
  1821     
       
  1822 	CleanupStack::PopAndDestroy();// view
       
  1823 	CleanupStack::PopAndDestroy(iapDatabase);
       
  1824 	aCount = aRecordPtr->Count();
       
  1825 	}
       
  1826 
       
  1827 void CSocketDesc::FindConnectionDetailsL(CArrayFixFlat<TAccessPointRecord> *&aRecordPtr,
       
  1828 		TInt &aCount)
       
  1829 	{
       
  1830 	TAccessPointRecord tempRecord;
       
  1831 	CCommsDatabase* iapDatabase;
       
  1832 	CCommsDbTableView* view;
       
  1833 
       
  1834 	// This function can leave on insufficient memory
       
  1835 	OpenIapTableLC(&iapDatabase, &view);
       
  1836 	TInt count = 0;
       
  1837 	TInt ret = view->GotoFirstRecord();
       
  1838     while (ret == KErrNone && count < aCount)
       
  1839 		{
       
  1840     	TRAP(ret, ReadRecordFromIapTableL(view, tempRecord));
       
  1841     	if (ret == KErrNone)
       
  1842 			{    		
       
  1843 			if((*aRecordPtr)[count].iId == tempRecord.iId )    			
       
  1844 				{    			    		
       
  1845 				(*aRecordPtr)[count].iServiceType = tempRecord.iServiceType;
       
  1846 				ret = view->GotoFirstRecord();
       
  1847 				count++;    		
       
  1848 				continue;
       
  1849 				}    		
       
  1850     		ret = view->GotoNextRecord();
       
  1851 			}
       
  1852 		}
       
  1853     
       
  1854 	CleanupStack::PopAndDestroy();// view
       
  1855 	CleanupStack::PopAndDestroy(iapDatabase);
       
  1856 	aCount = aRecordPtr->Count();
       
  1857 		}
       
  1858 
       
  1859 void CSocketDesc::AccessPointCountL(TInt &aCount)
       
  1860 	{
       
  1861 	CCommsDatabase* iapDatabase;
       
  1862 	CCommsDbTableView* view;
       
  1863 
       
  1864 	OpenIapTableLC(&iapDatabase, &view);
       
  1865 	aCount = 0;
       
  1866 	TInt ret = view->GotoFirstRecord();
       
  1867 	while(ret == KErrNone)
       
  1868 		{
       
  1869 		aCount++;
       
  1870 		ret = view->GotoNextRecord();
       
  1871 		}
       
  1872 	CleanupStack::PopAndDestroy();// view
       
  1873 	CleanupStack::PopAndDestroy(iapDatabase);
       
  1874 	}
       
  1875 
       
  1876 void CSocketDesc::ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord)
       
  1877 	{
       
  1878 	aView->ReadUintL(TPtrC(COMMDB_ID), aRecord.iId);
       
  1879 	aView->ReadTextL(TPtrC(COMMDB_NAME), aRecord.iName); 
       
  1880 	aRecord.iDialogPref = ECommDbDialogPrefDoNotPrompt;
       
  1881 	aView->ReadUintL(TPtrC(IAP_SERVICE), aRecord.iService);
       
  1882 	aView->ReadTextL(TPtrC(IAP_SERVICE_TYPE), aRecord.iServiceType);
       
  1883 	aView->ReadUintL(TPtrC(IAP_BEARER), aRecord.iBearer);
       
  1884 	/*
       
  1885 	 * IAP_BEARER_TYPE is not a column of IAP table even though its 
       
  1886 	 * listed in header. So not trying to read it.
       
  1887 	 */
       
  1888 	aView->ReadUintL(TPtrC(IAP_NETWORK), aRecord.iNetwork);
       
  1889 	aView->ReadUintL(TPtrC(IAP_NETWORK_WEIGHTING), aRecord.iNetworkWeighting);
       
  1890 	aView->ReadUintL(TPtrC(IAP_LOCATION), aRecord.iLocation);
       
  1891 	}
       
  1892 
       
  1893 void CSocketDesc::OpenIapTableLC(CCommsDatabase **aIapDatabase, CCommsDbTableView **aView)
       
  1894 	{
       
  1895 	// Get IAP names and ids from the database
       
  1896 	*aIapDatabase = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
  1897 	CleanupStack::PushL(*aIapDatabase);
       
  1898 
       
  1899 	(*aIapDatabase)->ShowHiddenRecords();
       
  1900 
       
  1901 	// This is LC code, that means code has pushed, but not popped
       
  1902 	(*aView) = (*aIapDatabase)->OpenTableLC(TPtrC(IAP));
       
  1903 	}
       
  1904 
       
  1905 inline TInt CSocketDesc::ActiveConnectionCount(TInt &aCount)
       
  1906 	{
       
  1907 	aCount = ((CFileTable*)iFids)->RConnectionCount();
       
  1908 	return KErrNone;
       
  1909 	}
       
  1910 
       
  1911 TInt CSocketDesc::ActiveConnectionListL(CArrayFixFlat<TAccessPointRecord> *aRecordPtr, TInt &aLength)
       
  1912 	{
       
  1913 	TInt rcIndex;
       
  1914 	RConnection *rc;
       
  1915 	TAccessPointRecord tempRecord;
       
  1916 
       
  1917 	for (rcIndex = 0;rcIndex < aLength; rcIndex++)
       
  1918 		{
       
  1919 		if  ( ((CFileTable*)iFids)->RConnectionAt(rcIndex, rc) != KErrNone )
       
  1920 			{
       
  1921 			break;
       
  1922 			}
       
  1923 		// Read index and name of the connection
       
  1924 		if  ( GetRConnectionDetails(rc, tempRecord) != KErrNone )
       
  1925 			{
       
  1926 			break;
       
  1927 			}
       
  1928 		aRecordPtr->AppendL(tempRecord);
       
  1929 		}
       
  1930 	aLength = aRecordPtr->Count();
       
  1931 	return KErrNone;
       
  1932 	}
       
  1933 
       
  1934 TInt CSocketDesc::GetRConnectionDetails(RConnection *aRc, TAccessPointRecord &aApr)
       
  1935 	{
       
  1936 	_LIT(KName, "IAP\\Name");
       
  1937 	_LIT(KId, "IAP\\Id");
       
  1938 
       
  1939 	TInt ret = aRc->GetDesSetting(KName, aApr.iName);
       
  1940 	if (ret == KErrNone)
       
  1941 		{
       
  1942 		ret = aRc->GetIntSetting(KId, aApr.iId);
       
  1943 		}
       
  1944 	
       
  1945 		return ret;
       
  1946 		}
       
  1947 
       
  1948 TInt CSocketDesc::StartConnection(void * /* ptr */)
       
  1949 	{
       
  1950 	if (iConnectionPtr != NULL)
       
  1951 		{
       
  1952 		return KErrAlreadyExists;
       
  1953 		}
       
  1954 	TCommDbConnPref connPref;
       
  1955 	TInt ret = GetConnectionPreference(connPref);
       
  1956 	if (ret != KErrNone)
       
  1957 		{
       
  1958 		return ret;
       
  1959 		}
       
  1960 	ret = iConnection.Open(*iSockServPtr);
       
  1961 	if (ret != KErrNone)
       
  1962 		{
       
  1963 		return ret;
       
  1964 		}	
       
  1965 	ret = iConnection.Start(connPref);
       
  1966 	if (ret != KErrNone)
       
  1967 		{
       
  1968 		iConnection.Close();
       
  1969 		return ret;
       
  1970 		}
       
  1971 	iConnectionPtr = &iConnection;
       
  1972 	ret = ((CFileTable*)iFids)->AddRConnectionPtr(iConnectionPtr, iRConnectionIndex);
       
  1973 	if (ret != KErrNone)
       
  1974 		{
       
  1975 		iConnection.Close();
       
  1976 		iConnectionPtr = NULL;
       
  1977 		}
       
  1978 	return ret;
       
  1979 	}
       
  1980 
       
  1981 TInt CSocketDesc::GetConnectionPreference(TCommDbConnPref &aCommPref)
       
  1982 	{
       
  1983 	if (iConnPref.iName.Length() == 0)
       
  1984 		{
       
  1985 		return KErrArgument;
       
  1986 		}
       
  1987 	
       
  1988 	TAccessPointRecord apr;	
       
  1989 	TInt ret;
       
  1990 
       
  1991 	// Connection preference is set
       
  1992 		TRAP(ret, GetIapDetailsByNameL(iConnPref.iName, apr));
       
  1993 
       
  1994 	if (ret == KErrNone)
       
  1995 		{
       
  1996 		aCommPref.SetIapId(apr.iId);
       
  1997 		aCommPref.SetNetId(apr.iNetwork);
       
  1998 		aCommPref.SetBearerSet(apr.iBearer);		
       
  1999 		aCommPref.SetDialogPreference((TCommDbDialogPref)apr.iDialogPref);
       
  2000 		aCommPref.SetDirection((TCommDbConnectionDirection)apr.iDirection);
       
  2001 		}
       
  2002 	return ret;	
       
  2003 	}
       
  2004 
       
  2005 void CSocketDesc::GetIapDetailsByNameL(
       
  2006 		TBuf<KCommsDbSvrMaxColumnNameLength> aIapName, 
       
  2007 		TAccessPointRecord &aRecord)
       
  2008 	{
       
  2009 	TAccessPointRecord tempRecord;
       
  2010 	CCommsDatabase* iapDatabase;
       
  2011 	CCommsDbTableView* view;
       
  2012 	TInt ret = KErrNotFound;
       
  2013 
       
  2014 	OpenIapTableLC(&iapDatabase, &view);
       
  2015 	ret = view->GotoFirstRecord();
       
  2016 	while (ret == KErrNone)
       
  2017 		{
       
  2018 		TRAP(ret, ReadRecordFromIapTableL(view, tempRecord));
       
  2019 		if (ret == KErrNone)
       
  2020 			{
       
  2021 			if (aIapName == tempRecord.iName)
       
  2022 				{
       
  2023 				aRecord = tempRecord;
       
  2024 				ret = KErrNone;
       
  2025 				break;
       
  2026 				}
       
  2027 			}    	
       
  2028 		ret = view->GotoNextRecord();
       
  2029 		}
       
  2030 	CleanupStack::PopAndDestroy();// view
       
  2031 	CleanupStack::PopAndDestroy(iapDatabase);
       
  2032 
       
  2033 	if (ret != KErrNone)
       
  2034 		{
       
  2035 		User::Leave(KErrNotFound);
       
  2036 		}
       
  2037 	}
       
  2038 
       
  2039 void CSocketDesc::StopConnection()
       
  2040 	{
       
  2041 	iConnection.Close();
       
  2042 	iConnectionPtr = NULL;
       
  2043 	((CFileTable*)iFids)->RemoveRConnectionPtrAt(iRConnectionIndex);
       
  2044 	iRConnectionIndex = -1;
       
  2045 	}
       
  2046 
       
  2047 void CSocketDesc::StopSubConnection()
       
  2048 	{
       
  2049 	iSubConnection.Close();
       
  2050 	iSubConnectionPtr = NULL;
       
  2051 	}
       
  2052 
       
  2053 TInt CSocketDesc::StartSubConnection(void *)
       
  2054 	{
       
  2055 	if (iSubConnectionPtr != NULL)
       
  2056 		{
       
  2057 		return KErrAlreadyExists;
       
  2058 		}
       
  2059 
       
  2060 	TInt ret = KErrArgument;
       
  2061 	TInt rcIndex = 0;
       
  2062 	RConnection *rc;
       
  2063 	TAccessPointRecord record;	
       
  2064 	do
       
  2065 		{
       
  2066 		if (((CFileTable*)iFids)->RConnectionAt(rcIndex, rc) != KErrNone)
       
  2067 			{
       
  2068 			break;
       
  2069 			}
       
  2070 
       
  2071 		// Read index and name of the connection
       
  2072 		GetRConnectionDetails(rc, record);
       
  2073 		if (record.iName == iConnPref.iName)
       
  2074 			{
       
  2075 			ret = KErrNone; // RConnection found
       
  2076 			break;
       
  2077 			}
       
  2078 		rcIndex++;	
       
  2079 		}
       
  2080 	while (ETrue); //Loop over all active connections
       
  2081 
       
  2082 	if (ret == KErrNone)
       
  2083 		{
       
  2084 		ret = iSubConnection.Open(*iSockServPtr, RSubConnection::EAttachToDefault, *rc);
       
  2085 		if (ret == KErrNone)
       
  2086 			{
       
  2087 			iSubConnectionPtr = &iSubConnection;
       
  2088 			}
       
  2089 		}
       
  2090 
       
  2091 	return ret;
       
  2092 	}
       
  2093 
       
  2094 inline void CSocketDesc::SetFids(void *aFids)
       
  2095 	{
       
  2096 	iFids = aFids;
       
  2097 	}
       
  2098 
       
  2099 //Add an entry in the interface routing table	
       
  2100 TInt CSocketDesc::RouteRequest(TInt aReq, void *aParam)
       
  2101 	{
       
  2102 	struct rtentry* rt=reinterpret_cast<struct rtentry*>(aParam);
       
  2103 
       
  2104 	if (!rt)
       
  2105 		{
       
  2106 		return KErrArgument;	
       
  2107 		}
       
  2108 
       
  2109 	TInt ret;
       
  2110 	TPckgBuf<TSoInetRouteInfo>iroute;	
       
  2111 	iroute().iType=ERtNormal;
       
  2112 	iroute().iState=ERtReady; 
       
  2113 	iroute().iMetric=rt->rt_metric;
       
  2114 	if (rt->rt_dev)
       
  2115 		{
       
  2116 		TPckgBuf<TSoInetInterfaceInfo> iface;		
       
  2117 		TFileName name;
       
  2118 		name.Copy(TPtrC8((TText8*)rt->rt_dev));
       
  2119 
       
  2120 		if((ret=GetInterfaceByName(name, iface)) != KErrNone)
       
  2121 			return ret;
       
  2122 
       
  2123 		Copy(iroute().iIfAddr, iface().iAddress);
       
  2124 		ConvertRtEntry(iroute(), rt);
       
  2125 
       
  2126 		//add the entry
       
  2127 		return iSocket.SetOpt(aReq, KSolInetRtCtrl, iroute);
       
  2128 		}
       
  2129 
       
  2130 	return KErrUnknown;				
       
  2131 	}
       
  2132 
       
  2133 
       
  2134 TInt CSocketDesc::Copy(TInetAddr& aDest, TInetAddr& aSrc)
       
  2135 	{
       
  2136 	if (aSrc.IsV4Mapped() || aSrc.IsV4Compat())
       
  2137 		{
       
  2138 		aSrc.ConvertToV4();
       
  2139 		}
       
  2140 
       
  2141 	aDest.SetAddress(aSrc.Address());
       
  2142 	aDest.SetFamily(aSrc.Family());
       
  2143 	aDest.SetPort(aSrc.Port());
       
  2144 
       
  2145 	return KErrNone;
       
  2146 	}
       
  2147 
       
  2148 TInt CSocketDesc::ConvertSockAddr(TInetAddr& aInetAddr, struct sockaddr_in *aSockAddr)
       
  2149 	{
       
  2150 	if (aSockAddr == NULL)
       
  2151 		{
       
  2152 		return KErrArgument;
       
  2153 		}
       
  2154 
       
  2155 		//convert the address and port from network to host byte order...
       
  2156 		aInetAddr.SetAddress(ByteOrder::Swap32(aSockAddr->sin_addr.s_addr));
       
  2157 		aInetAddr.SetFamily(aSockAddr->sin_family);
       
  2158 		aInetAddr.SetPort(ByteOrder::Swap16(aSockAddr->sin_port));
       
  2159 	return KErrNone;	
       
  2160 	}
       
  2161 
       
  2162 TInt CSocketDesc::ConvertRtEntry(TSoInetRouteInfo& aRouteInfo, struct rtentry *aRouteEntry)
       
  2163 	{
       
  2164 	if(aRouteEntry == NULL)	
       
  2165 		{
       
  2166 		return KErrArgument;
       
  2167 		}
       
  2168 
       
  2169 		ConvertSockAddr(aRouteInfo.iDstAddr, (struct sockaddr_in *)&aRouteEntry->rt_dst);
       
  2170 		ConvertSockAddr(aRouteInfo.iNetMask, (struct sockaddr_in *)&aRouteEntry->rt_genmask);
       
  2171 		ConvertSockAddr(aRouteInfo.iGateway, (struct sockaddr_in *)&aRouteEntry->rt_gateway);			
       
  2172 	return KErrNone;	
       
  2173 	}
       
  2174 
       
  2175 TInt CSocketDesc::GetInterfaceByName(const TDesC& aIfName, TPckgBuf<TSoInetInterfaceInfo>& aIface)
       
  2176 	{
       
  2177 	TInt ret = iSocket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
       
  2178 	if (ret != KErrNone)
       
  2179 		{
       
  2180 		return ret;
       
  2181 		}
       
  2182 	TPckgBuf<TSoInetInterfaceInfo> iface;
       
  2183 	while((ret = iSocket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, iface)) == KErrNone)
       
  2184 		{
       
  2185 		if(!iface().iAddress.IsUnspecified()
       
  2186 				&& iface().iName.CompareF(aIfName) == 0)
       
  2187 			{
       
  2188 			aIface = iface;
       
  2189 			return ret;    	        
       
  2190 			}
       
  2191 		}   	
       
  2192 
       
  2193 	return KErrUnknown;	
       
  2194 	}
       
  2195 
       
  2196 TInt CSocketDesc::GetInterfaceHWAddress(void *aParam)
       
  2197 	{
       
  2198 	ifreq *ifr = reinterpret_cast<ifreq *>(aParam);
       
  2199 
       
  2200 	if (!ifr)
       
  2201 		{
       
  2202 		return KErrArgument;	
       
  2203 		}
       
  2204 
       
  2205 	if (ifr->ifr_name[0]!='\0')
       
  2206 		{
       
  2207 	TPckgBuf<TSoInetInterfaceInfo> iface;
       
  2208 	TFileName name;
       
  2209 	name.Copy(TPtrC8((TText8*)ifr->ifr_name));
       
  2210 
       
  2211 		TInt ret = GetInterfaceByName(name, iface); 		
       
  2212 		
       
  2213 		if (ret != KErrNone)
       
  2214 			{
       
  2215 		return ret;		
       
  2216 			}
       
  2217 
       
  2218 	if(iface().iHwAddr.Length() > sizeof(SSockAddr))		
       
  2219 		{
       
  2220 		Mem::Copy(&(ifr->ifr_hwaddr.sa_data[0]),&(iface().iHwAddr[sizeof(SSockAddr)]), 6);
       
  2221 		ifr->ifr_hwaddr.sa_family = (TUint16)iface().iHwAddr.Family();
       
  2222 		ifr->ifr_hwaddr.sa_port = ByteOrder::Swap16(iface().iHwAddr.Port());				
       
  2223 		return ret;				
       
  2224 		}
       
  2225 		}	
       
  2226 
       
  2227 	return KErrUnknown;
       
  2228 	}
       
  2229 
       
  2230 //This function retrieves the Currently active IAP ID using the RSocket Query.
       
  2231 //First get the interface index of the active connection using KSoInterfaceIndex
       
  2232 //Then with the help of the interface index, fetch the TSoInetIfQuery, under which iZone
       
  2233 //will contain the snap id. User is supposed to call if_indextoname() api to get the IAP name
       
  2234 //from the ID retured with this Ioctl implementation.
       
  2235 TInt CSocketDesc::GetActiveInterface( void *aParam)
       
  2236     {
       
  2237     TInt ifindex = -1;
       
  2238     TInt ret = iSocket.GetOpt(KSoInterfaceIndex, KSolInetIp , ifindex);
       
  2239     if(ret!=KErrNone)
       
  2240         {
       
  2241         return ret;
       
  2242         }   
       
  2243     TPckgBuf<TSoInetIfQuery> opt;
       
  2244     opt().iIndex = ifindex;
       
  2245     ret = iSocket.GetOpt(KSoInetIfQueryByIndex, KSolInetIfQuery, opt);
       
  2246     if(ret!=KErrNone)
       
  2247         {
       
  2248         return ret;
       
  2249         }
       
  2250     ifreq *ifr = (ifreq * )aParam;
       
  2251     ifr->ifr_index  = opt().iZone[1]; //IAP_ID
       
  2252     return KErrNone;
       
  2253     }