// -----------------------------------------------------------------------------
// CMceLocalAddrResolver::RefreshLocalAddressesL
// -----------------------------------------------------------------------------
//
void CMceLocalAddrResolver::RefreshLocalAddressesL()
    {
    RSocket socket;
	User::LeaveIfError( socket.Open( iSocketServ, KAfInet, KSockDatagram, 
		                             KProtocolInetUdp ) );

	iAddr.Init( KAfInet );
	iIPv4Addr.Init( KAfInet );

	if ( socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) == KErrNone )
		{
		TPckgBuf<TSoInetInterfaceInfo> info;
		while ( socket.GetOpt( KSoInetNextInterface,
		                       KSolInetIfCtrl, info ) == KErrNone )
			{
			TPckgBuf<TSoInetIfQuery> query;
			query().iName = info().iName;
			if ( socket.GetOpt( KSoInetIfQueryByName,
			                    KSolInetIfQuery, query ) == KErrNone )
				{
				if ( Match( info(), query() ) )
				    {
                    SetAddressesIfNotSet( info().iAddress );
				    }
				}
			}
		}
		
	socket.Close();
	}	
int ILibSocketWrapper_GetLocalIPAddressList(int iplist[])
{
	int socketObject = ILibSocketWrapper_socket(SOCK_STREAM);
	RSocket *sock = (RSocket*)SocketArray[socketObject];
	TPckgBuf<TSoInetInterfaceInfo> item;
	int results=0;
	
	// Initialize the iterator to start getting Interface list
	TInt result = sock->SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);

	// if the above line fails, then this will just fail too. 
	result = sock->GetOpt(KSoInetNextInterface, KSolInetIfCtrl, item);
	while (result == KErrNone)
	{
	
		TSoInetInterfaceInfo& ifInfo = item();
		if (ifInfo.iState == EIfUp && ifInfo.iAddress.Address()!=0)
		{
			iplist[results] = ntohl(ifInfo.iAddress.Address());
			++results;
		}
		result = sock->GetOpt(KSoInetNextInterface, KSolInetIfCtrl, item);
	}
	ILibSocketWrapper_close(socketObject);
	return(results);
}
// -----------------------------------------------------------------------------
// CLocalAddrResolver::GetLocalAddrL
// -----------------------------------------------------------------------------
//
void CLocalAddrResolver::GetLocalAddrL(TInetAddr& aAddr, TUint32 aIap)
	{
	RSocket socket;
	User::LeaveIfError( socket.Open( *iServer, KAfInet, KSockDatagram, 
		                             KProtocolInetUdp ) );

	if (socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) == KErrNone )
		{
		TPckgBuf<TSoInetInterfaceInfo> opt;
		
		while ( socket.GetOpt( KSoInetNextInterface, KSolInetIfCtrl, opt ) == KErrNone)
			{
			TPckgBuf<TSoInetIfQuery> optifquery;
			optifquery().iName = opt().iName;
		
			if(socket.GetOpt( KSoInetIfQueryByName, KSolInetIfQuery, optifquery ) == KErrNone)
				{
				CheckAndSetAddr( aAddr, ( TInetAddr& )opt().iAddress,
				                 optifquery().iZone[1], aIap );
				}
			}
		}
		
	socket.Close();
	}
int ILibSocketWrapper_GetInterfaceIndex(long localAddr)
{
	int RetVal = -1;
	int idx = 1;
	
	int socketObject = ILibSocketWrapper_socket(SOCK_STREAM);
	RSocket *sock = (RSocket*)SocketArray[socketObject];
	TPckgBuf<TSoInetInterfaceInfo> item;
	
	// Initialize the iterator to start getting Interface list
	TInt result = sock->SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);

	// if the above line fails, then this will just fail too. 
	result = sock->GetOpt(KSoInetNextInterface, KSolInetIfCtrl, item);
	while (result == KErrNone)
	{
	
		TSoInetInterfaceInfo& ifInfo = item();
		if (ifInfo.iState == EIfUp && ifInfo.iAddress.Address()!=0)
		{
			if(ntohl(ifInfo.iAddress.Address())==localAddr)
			{
				RetVal = idx;
				break;
			}
		}
		++idx;
		result = sock->GetOpt(KSoInetNextInterface, KSolInetIfCtrl, item);
	}
	ILibSocketWrapper_close(socketObject);
	return(RetVal);
}
enum TVerdict CSocketTest8_2::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Ioctl observes InternalOptionBit"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// get a protocol
	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
	TProtocolDesc protoInfo;
	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// check internal options bit
	RSocket socket;
	Logger().WriteFormat(_L("Opening a new socket"));
	ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Trying Ioctl on internal options bit"));
	TRequestStatus stat;
	socket.Ioctl(KInternalIoctlBit, stat);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrAccessDenied == stat.Int());
	
	Logger().WriteFormat(_L("Trying to SetOpt internal options bit"));
	ret = socket.SetOpt(KSocketInternalOptionBit, KSOLSocket);
	Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret));
	TESTL(KErrAccessDenied == ret);
	
	Logger().WriteFormat(_L("Trying to GetOpt internal options bit"));
	TPckgBuf<TBool> boolean;
	ret = socket.GetOpt(KSocketInternalOptionBit, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOpt returned %S"), &EpocErrorToText(ret));
	TESTL(KErrAccessDenied == ret);
	
	Logger().WriteFormat(_L("Testing StartL() with Ioctl KDummyIoctlCheckStarted"));
	socket.Ioctl(KDummyIoctlCheckStarted, stat, NULL, KIoctlDummyLevel);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrNone == stat.Int());
	
	CleanupStack::Pop(&ss);
	ss.Close();
	
	SetTestStepResult(verdict);
	return verdict;
	}
enum TVerdict CSocketTest8_7::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: getOpt with small client buffer"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// try SetLocalPort
	Logger().WriteFormat(_L("Opening a socket"));
	RSocket socket;
	ret = socket.Open(ss, _L("Dummy Protocol 1"));
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// try with small buffer - 8 bit descriptor
	Logger().WriteFormat(_L("Trying to GetOption KSOBlockingIO"));
	TBuf8<1> smallBuf8;
	ret = socket.GetOpt(KSOBlockingIO, KSOLSocket, smallBuf8);
	Logger().WriteFormat(_L("GetOption returned %S"),&EpocErrorToText(ret));
	TESTL(KErrOverflow == ret);
		
	// try with correct size descriptor
	Logger().WriteFormat(_L("Trying to GetOption KSOBlockingIO"));
	TPckgBuf<TBool> boolean;
	ret = socket.GetOpt(KSOBlockingIO, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOption returned %S, value %d"), 
			&EpocErrorToText(ret), boolean());
	TESTL(KErrNone == ret);
	TESTL(TRUE == boolean());
		
	CleanupStack::Pop(&ss);
	ss.Close();
	
	return verdict;
	}
void CApConnectEngine::FetchIpAddressL()
{
	RSocket socket;
	CleanupClosePushL( socket);
	while (socket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp,
			iConnect)!= KErrNone)
	{
	};
	TSoInetInterfaceInfo inf;
	TPckg<TSoInetInterfaceInfo> opt( inf);
	TRAPD(err, socket.SetOpt (KSoInetEnumInterfaces, KSolInetIfCtrl ))
	;
	if (err != KErrNone)
	{
		return;
	}

	while ( socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt)== KErrNone)
	{
		if ( inf.iAddress.Address()==0) // if the stored address is not an IPv4 address
		{
		}
		else
		{
			if ( inf.iAddress.IsUnspecified())
			{
				// Interface inf.iName has no address        	
			}
			else
			{
				// have to do this, strange
				TInetAddr addr;
				addr.SetAddress( inf.iAddress.Address());
				addr.Output(iConnInfo.ipAddress);
				// have to do this, strange

				if ( iConnInfo.ipAddress.Compare(KZeroIP)!= 0 && iConnInfo.ipAddress.Compare(KLocalIP)!= 0)
				{
					if ( iConnInfo.ipAddress.Left(3).Compare(_L("169"))!= 0)
					{
						CleanupStack::PopAndDestroy(); // socket
						return;
					}
				}
			}
		}
	}
	CleanupStack::PopAndDestroy(); // socket	
}
// ---------------------------------------------------------------------------
// This method prepares the streamer for incoming data. 
// ---------------------------------------------------------------------------
//
EXPORT_C void CBTAudioStreamer::StartL(RSocket& aSocket, const TUint aFrameLength, CBTAudioStreamInputBase *aAudioInput, const TUint aTargetBitrate)
    {
    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamer::StartL() ->")));
    iAudioInput = aAudioInput; 

    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FPrint(_L("[BTAudioStreamer]\t Framelength: %d"), aFrameLength));

    if(iStarted != EFalse) 
        {
        BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t Error: Already started!")));
        User::Leave(KErrInUse); 
        }

    TInt inboundMTUSize = 0; 
    if(aSocket.GetOpt(KL2CAPInboundMTU, KSolBtL2CAP, inboundMTUSize) != KErrNone) 
        {
        BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t Failed to get inbound MTU size, using L2CAP default value")));
        inboundMTUSize = KL2CAPDefaultMTUSize; 
        }

    iRtpSession.OpenL(aSocket, inboundMTUSize); 
    iSender = CBTAudioStreamSender::NewL(*this, iRtpSession); 

    TInt outboundMTUSize; 
    if(aSocket.GetOpt(KL2CAPGetOutboundMTU, KSolBtL2CAP, outboundMTUSize) != KErrNone) 
        {
        BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t Failed to get outbound MTU size, using L2CAP default value")));
        outboundMTUSize = KL2CAPDefaultMTUSize; 
        }

    iSender->StartL(outboundMTUSize, aFrameLength, aTargetBitrate); 

		iStarted = ETrue; 
		
    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamer::StartL() <-")));
    }
Exemple #9
0
SYSCALL(int, maConnGetAddr(MAHandle conn, MAConnAddr* addr)) {
	LOGST("maConnGetAddr(%i, 0x%08X)", conn, addr);
	if(conn == HANDLE_LOCAL) {
		if(addr->family == CONN_FAMILY_BT) {
			TBTDevAddr btaddr;
			//TPckgBuf<TBTDevAddr> pckg(btaddr);

			//old style, might work on Symbian 7.0 and earlier
			//update: doesn't work on 6630.
#if 0//!defined(__SERIES60_3X__)
			RSocket socket;
			socket.Open(gSocketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP);
			TRequestStatus status;
			socket.Ioctl(KHCILocalAddressIoctl, status, &pckg, KSolBtHCI);
			User::WaitForRequest(status);
			LOG("KHCILocalAddressIoctl result: %i\n", status.Int());
			socket.Close();
			if(status != KErrNone) {
				return CONNERR_GENERIC;
			}
#else
#if 0	//doesn't work; bug in Symbian.
			int result = RProperty::Get(KUidSystemCategory,
				KPropertyKeyBluetoothGetLocalDeviceAddress, pckg);
			LOG("KPropertyKeyBluetoothGetLocalDeviceAddress result: %i\n", result);
			if(result != KErrNone) {
				return CONNERR_GENERIC;
			}
#else
			//open a server socket and read its address.
			RSocket socket;
			socket.Open(gSocketServ, KBTAddrFamily, KSockStream, KRFCOMM);
			int channel;
			LHEL_BASE(socket.GetOpt(KRFCOMMGetAvailableServerChannel, KSolBtRFCOMM, channel),
				return CONNERR_GENERIC);
			TBTSockAddr btsockaddr;
			btsockaddr.SetPort(channel);
			LHEL_BASE(socket.Bind(btsockaddr), return CONNERR_GENERIC);
			socket.LocalName(btsockaddr);
			socket.Close();
			btaddr = btsockaddr.BTAddr();
#endif	//0
#endif	//0//__SERIES60_3X__
			storeBtAddr(btaddr, addr);
			return 1;
		} else {	//TCP server
			return CONNERR_INTERNAL;
// for 'getting' a RBTBaseband from a connected socket
TInt RBTBaseband::Open(RSocketServ& aSocketServ, RSocket& aConnectedSocket)
	{
	if (!aConnectedSocket.SubSessionHandle())
		{
		return KErrNotReady;
		}
	
	THCIConnHandle bbHandle;
	TPckg<THCIConnHandle> bbHandleBuf(bbHandle);

	TInt err = aConnectedSocket.GetOpt(KLMGetACLHandle, KSolBtACL, bbHandleBuf);
	if (err)
		{
		return err;
		}
	err = iSocket.Open(aSocketServ, KBTAddrFamily, bbHandle, KBTLinkManager);

	return err;
	}
enum TVerdict CEsockTest10_2::easyTestStepL()
	{
	
	// Ioctl on an unconnected socket
	
	// open a TCP socket
	RSocket sock;
	CleanupClosePushL(sock);
	TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
	TESTEL(KErrNone == nRet, nRet);
	
	// get select state of the socket
	sock.GetOpt (KSOSelectPoll, KSOLSocket, (nRet = 0));
	
	// socket is blocked for writing, has no data for reading
	// and has no exception condition
	TESTEL(0 == nRet, nRet);
	
	// close the socket
	CleanupStack::PopAndDestroy();
	
	return EPass;
	}
enum TVerdict CSocketTest8_6::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Retention of socket options from before Accept to after Accept"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss1;
	TInt ret = OptimalConnect(ss1);
	TESTL(KErrNone == ret);
	CleanupClosePushL(ss1);
	
	Logger().WriteFormat(_L("Opening Socket on pdummy3"));
	RSocket sock1;
	ret = sock1.Open(ss1,_L("Dummy Protocol 3"));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Binding Sock1"));
	TSockAddr addr;
	ret = sock1.Bind(addr);
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Listening on Sock1"));
	ret = sock1.Listen(5);
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Opening a null Socket"));
	RSocket nullSock;
	nullSock.Open(ss1);
	TESTL(KErrNone == ret);
	
	const TUint KBufferSize = 1024;
	Logger().WriteFormat(_L("Setting a whole bunch of KSOLSocket options on the parent (sock1) socket"));
	ret = sock1.SetOpt(KSOSendBuf, KSOLSocket, KBufferSize);
	TESTL(KErrNone == ret);
	ret = sock1.SetOpt(KSORecvBuf, KSOLSocket, KBufferSize);
	TESTL(KErrNone == ret);
	ret = sock1.SetOpt(KSODebug, KSOLSocket, ETrue);
	TESTL(KErrNone == ret);
	ret = sock1.SetOpt(KSONonBlockingIO, KSOLSocket);
	TESTL(KErrNone == ret);
	_LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl);
	ret = nullSock.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package());
	TESTL(KErrNotReady == ret);
	
	Logger().WriteFormat(_L("Now simulating a remote connection to complete the accept"));
	ret = sock1.SetOpt(KDummyOptionSetConnectComplete, KIoctlDummyLevel);
	TESTL(KErrNone == ret);
	Logger().WriteFormat(_L("Now performing accept"));
	TRequestStatus stat;
	sock1.Accept(nullSock, stat);
	User::WaitForRequest(stat);
	TESTL(KErrNone == stat.Int());
	
	Logger().WriteFormat(_L("Now retrieving all the options set on the null socket with getOpts"));
	TInt retrievedOpt;
	ret = nullSock.GetOpt(KSOSendBuf, KSOLSocket, retrievedOpt);
	TESTL(KErrNone == ret);
	if (retrievedOpt != KBufferSize)
		{
		Logger().WriteFormat(_L("Opt KSOSendBuf did not return the correct value"));
		User::Leave(EFail);
		}	
	ret = nullSock.GetOpt(KSORecvBuf, KSOLSocket, retrievedOpt);
	TESTL(KErrNone == ret);
	if (retrievedOpt != KBufferSize)
		{
		Logger().WriteFormat(_L("Opt KSORecvBuf did not return the correct value"));
		User::Leave(EFail);
		}	
	ret = nullSock.GetOpt(KSODebug, KSOLSocket, retrievedOpt);
	TESTL(KErrNone == ret);
	if (!retrievedOpt) 
		{
		Logger().WriteFormat(_L("Opt KSODebug did not return the correct value"));
		User::Leave(EFail);
		}
	ret = nullSock.GetOpt(KSONonBlockingIO, KSOLSocket, retrievedOpt);
	TESTL(KErrNone == ret);
	if (!retrievedOpt)
		{
		Logger().WriteFormat(_L("Opt KSONonBlockingIO did not return the correct value"));
		User::Leave(EFail);
		}
	
	CleanupStack::Pop(&ss1);
	ss1.Close();
	
	return verdict;
	}
enum TVerdict CSocketTest8_4::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Ioctl Get and Set Options"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// try SetLocalPort
	Logger().WriteFormat(_L("Opening a socket"));
	RSocket socket;
	ret = socket.Open(ss, _L("Dummy Protocol 1"));
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Trying SetLocalPort to 666"));
	ret = socket.SetLocalPort(666);
	Logger().WriteFormat(_L("SetLocalPort returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	Logger().WriteFormat(_L("Port now set to %d"), socket.LocalPort());
	TESTL(666 == socket.LocalPort());
	
	// try blocking Get/Set
	Logger().WriteFormat(_L("Testing blocking mode Get and Set options"));
	Logger().WriteFormat(_L("Trying to SetOption KSONonBlockingIO"));
	ret = socket.SetOpt(KSONonBlockingIO, KSOLSocket);
	Logger().WriteFormat(_L("SetOption returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Trying to GetOption KSONonBlockingIO"));
	TPckgBuf<TBool> boolean;
	ret = socket.GetOpt(KSONonBlockingIO, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOption returned %S, value %d"), 
		&EpocErrorToText(ret), boolean());
	TESTL(KErrNone == ret);
	TESTL(TRUE == boolean());
	
	Logger().WriteFormat(_L("Trying to GetOption KSOBlockingIO"));
	ret = socket.GetOpt(KSOBlockingIO, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOption returned %S, value %d"), 
		&EpocErrorToText(ret), boolean());
	TESTL(KErrNone == ret);
	TESTL(FALSE == boolean());
	
	Logger().WriteFormat(_L("Trying to SetOption KSOBlockingIO"));
	ret = socket.SetOpt(KSOBlockingIO, KSOLSocket);
	Logger().WriteFormat(_L("SetOption returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Trying to GetOption KSONonBlockingIO"));
	ret = socket.GetOpt(KSONonBlockingIO, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOption returned %S, value %d"), 
		&EpocErrorToText(ret), boolean());
	TESTL(KErrNone == ret);
	TESTL(FALSE == boolean());
	
	Logger().WriteFormat(_L("Trying to GetOption KSOBlockingIO"));
	ret = socket.GetOpt(KSOBlockingIO, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOption returned %S, value %d"), 
		&EpocErrorToText(ret), boolean());
	TESTL(KErrNone == ret);
	TESTL(TRUE == boolean());
	
	CleanupStack::Pop(&ss);
	ss.Close();
	
	return verdict;
	}
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
    TInt err(KErrNone);
    QList<QNetworkInterfacePrivate *> interfaces;

    // Connect to Native socket server
    RSocketServ socketServ;
    err = socketServ.Connect();
    if (err)
        return interfaces;

    // Open dummy socket for interface queries
    RSocket socket;
    err = socket.Open(socketServ, _L("udp"));
    if (err) {
        socketServ.Close();
        return interfaces;
    }

    // Ask socket to start enumerating interfaces
    err =  socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
    if (err) {
        socket.Close();
        socketServ.Close();
        return interfaces;
    }

    int ifindex = 0;
    TPckgBuf<TSoInetInterfaceInfo> infoPckg;
    TSoInetInterfaceInfo &info = infoPckg();
    while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, infoPckg) == KErrNone) {
        // Do not include IPv6 addresses because netmask and broadcast address cannot be determined correctly
        if (info.iName != KNullDesC && info.iAddress.IsV4Mapped()) {
            TName address;
            QNetworkAddressEntry entry;
            QNetworkInterfacePrivate *iface = 0;

            iface = new QNetworkInterfacePrivate;
            iface->index = ifindex++;
            interfaces << iface;
            iface->name = qt_TDesC2QString(info.iName);
            iface->flags = convertFlags(info);

            if (/*info.iFeatures&KIfHasHardwareAddr &&*/ info.iHwAddr.Family() != KAFUnspec) {
                for (TInt i = sizeof(SSockAddr); i < sizeof(SSockAddr) + info.iHwAddr.GetUserLen(); i++) {
                    address.AppendNumFixedWidth(info.iHwAddr[i], EHex, 2);
                    if ((i + 1) < sizeof(SSockAddr) + info.iHwAddr.GetUserLen())
                        address.Append(_L(":"));
                }
                address.UpperCase();
                iface->hardwareAddress = qt_TDesC2QString(address);
            }

            // Get the address of the interface
            info.iAddress.Output(address);
            entry.setIp(QHostAddress(qt_TDesC2QString(address)));

            // Get the interface netmask
            // For some reason netmask is always 0.0.0.0
            // info.iNetMask.Output(address);
            // entry.setNetmask( QHostAddress( qt_TDesC2QString( address ) ) );

            // Workaround: Let Symbian determine netmask based on IP address class
            // TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
            TInetAddr netmask;
            netmask.NetMask(info.iAddress);
            netmask.Output(address);
            entry.setNetmask(QHostAddress(qt_TDesC2QString(address)));

            // Get the interface broadcast address
            if (iface->flags & QNetworkInterface::CanBroadcast) {
                // For some reason broadcast address is always 0.0.0.0
                // info.iBrdAddr.Output(address);
                // entry.setBroadcast( QHostAddress( qt_TDesC2QString( address ) ) );

                // Workaround: Let Symbian determine broadcast address based on IP address
                // TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
                TInetAddr broadcast;
                broadcast.NetBroadcast(info.iAddress);
                broadcast.Output(address);
                entry.setBroadcast(QHostAddress(qt_TDesC2QString(address)));
            }

            // Add new entry to interface address entries
            iface->addressEntries << entry;

#if defined(QNETWORKINTERFACE_DEBUG)
            printf("\n       Found network interface %s, interface flags:\n\
                IsUp = %d, IsRunning = %d, CanBroadcast = %d,\n\
                IsLoopBack = %d, IsPointToPoint = %d, CanMulticast = %d, \n\
                ip = %s, netmask = %s, broadcast = %s,\n\
                hwaddress = %s",
                   iface->name.toLatin1().constData(),
                   iface->flags & QNetworkInterface::IsUp, iface->flags & QNetworkInterface::IsRunning, iface->flags & QNetworkInterface::CanBroadcast,
                   iface->flags & QNetworkInterface::IsLoopBack, iface->flags & QNetworkInterface::IsPointToPoint, iface->flags & QNetworkInterface::CanMulticast,
                   entry.ip().toString().toLatin1().constData(), entry.netmask().toString().toLatin1().constData(), entry.broadcast().toString().toLatin1().constData(),
                   iface->hardwareAddress.toLatin1().constData());
#endif
        }
    }
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
    TInt err(KErrNone);
    QList<QNetworkInterfacePrivate *> interfaces;
    QList<QHostAddress> addressesWithEstimatedNetmasks;

    // Open dummy socket for interface queries
    RSocket socket;
    err = socket.Open(qt_symbianGetSocketServer(), _L("udp"));
    if (err) {
        return interfaces;
    }

    // Ask socket to start enumerating interfaces
    err =  socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
    if (err) {
        socket.Close();
        return interfaces;
    }

    int ifindex = 0;
    TPckgBuf<TSoInetInterfaceInfo> infoPckg;
    TSoInetInterfaceInfo &info = infoPckg();
    while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, infoPckg) == KErrNone) {
        if (info.iName != KNullDesC) {
            TName address;
            QNetworkAddressEntry entry;
            QNetworkInterfacePrivate *iface = 0;

            iface = new QNetworkInterfacePrivate;
            iface->index = ifindex++;
            interfaces << iface;
            iface->name = qt_TDesC2QString(info.iName);
            iface->flags = convertFlags(info);

            if (/*info.iFeatures&KIfHasHardwareAddr &&*/ info.iHwAddr.Family() != KAFUnspec) {
                for (TInt i = sizeof(SSockAddr); i < sizeof(SSockAddr) + info.iHwAddr.GetUserLen(); i++) {
                    address.AppendNumFixedWidth(info.iHwAddr[i], EHex, 2);
                    if ((i + 1) < sizeof(SSockAddr) + info.iHwAddr.GetUserLen())
                        address.Append(_L(":"));
                }
                address.UpperCase();
                iface->hardwareAddress = qt_TDesC2QString(address);
            }

            // Get the address of the interface
            entry.setIp(qt_QHostAddressFromTInetAddr(info.iAddress));

#if defined(QNETWORKINTERFACE_DEBUG)
            qDebug() << "address is" << info.iAddress.Family() << entry.ip();
            qDebug() << "netmask is" << info.iNetMask.Family() << qt_QHostAddressFromTInetAddr( info.iNetMask );
#endif

            // Get the interface netmask
            if (info.iNetMask.IsUnspecified()) {
                // For some reason netmask is always 0.0.0.0 for IPv4 interfaces
                // and loopback interfaces (which we statically know)
                if (info.iAddress.IsV4Mapped()) {
                    if (info.iFeatures & KIfIsLoopback) {
                        entry.setPrefixLength(32);
                    } else {
                        // Workaround: Let Symbian determine netmask based on IP address class (IPv4 only API)
                        TInetAddr netmask;
                        netmask.NetMask(info.iAddress);
                        entry.setNetmask(QHostAddress(netmask.Address())); //binary convert v4 address
                        addressesWithEstimatedNetmasks << entry.ip();
#if defined(QNETWORKINTERFACE_DEBUG)
                        qDebug() << "address class determined netmask" << entry.netmask();
#endif
                    }
                } else {
                    // For IPv6 interfaces
                    if (info.iFeatures & KIfIsLoopback) {
                        entry.setPrefixLength(128);
                    } else if (info.iNetMask.IsUnspecified()) {
                        //Don't see this error for IPv6, but try to handle it if it happens
                        entry.setPrefixLength(64); //most common
#if defined(QNETWORKINTERFACE_DEBUG)
                        qDebug() << "total guess netmask" << entry.netmask();
#endif
                        addressesWithEstimatedNetmasks << entry.ip();
                    }
                }
            } else {
                //Expected code path for IPv6 non loopback interfaces (IPv4 could come here if symbian is fixed)
                entry.setNetmask(qt_QHostAddressFromTInetAddr(info.iNetMask));
#if defined(QNETWORKINTERFACE_DEBUG)
                qDebug() << "reported netmask" << entry.netmask();
#endif
            }

            // broadcast address is determined from the netmask in postProcess()

            // Add new entry to interface address entries
            iface->addressEntries << entry;

#if defined(QNETWORKINTERFACE_DEBUG)
            qDebug("\n       Found network interface %s, interface flags:\n\
                IsUp = %d, IsRunning = %d, CanBroadcast = %d,\n\
                IsLoopBack = %d, IsPointToPoint = %d, CanMulticast = %d, \n\
                ip = %s, netmask = %s, broadcast = %s,\n\
                hwaddress = %s",
                   iface->name.toLatin1().constData(),
                   iface->flags & QNetworkInterface::IsUp, iface->flags & QNetworkInterface::IsRunning, iface->flags & QNetworkInterface::CanBroadcast,
                   iface->flags & QNetworkInterface::IsLoopBack, iface->flags & QNetworkInterface::IsPointToPoint, iface->flags & QNetworkInterface::CanMulticast,
                   entry.ip().toString().toLatin1().constData(), entry.netmask().toString().toLatin1().constData(), entry.broadcast().toString().toLatin1().constData(),
                   iface->hardwareAddress.toLatin1().constData());
#endif
        }
    }
enum TVerdict CEsockTest29_10::easyTestStepL( void )
	{
	SetTestStepResult(EFail);
	TInt ret;
	const TUint KOneSecond = 1000000;
	
	Logger().WriteFormat(_L("Send/ Recv on PDummy3 socket but no avail MBuf Memory, mBuf becomes avail after send"));
	RSocketServ ss;
	ret = ss.Connect();
	TESTL(KErrNone == ret);	
    
    // open dummy prot 3
	Logger().WriteFormat(_L("Openning Dummy Protocol 3"));             
	RSocket sock;                                                  
	ret = sock.Open(ss,_L("Dummy Protocol 3"));
	TESTL(KErrNone == ret);
	
	// connect socket
	TSockAddr addr;
	TRequestStatus connStat;
	sock.Connect(addr, connStat);
	User::WaitForRequest(connStat);
	TESTL(KErrNone == connStat.Int());
	
	// send packet 1
	TRequestStatus stat;
	Logger().WriteFormat(_L("Attempting to create a packet to receive later"));	
	_LIT8(sendDataOne, "First Send");
	sock.Send(sendDataOne,0,stat);
	User::WaitForRequest(stat);
	TESTL(KErrNone == stat.Int());	
	// wait for packets to go through esock
	User::After(KOneSecond * 2);
	// gobble mBufs
	TInt nFree = 0;
	sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
	Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol"));
	while (nFree > 0)
		{
		ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0);
		sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
		}
	Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret);
	
	// we are running in high priority and allocating in a loop.
	// so kernel may not be able to enlarge the pools.
	// wait for kernel to enlarge the pool
	// We have to come out from the loop as well.
    User::After(KOneSecond * 2);
	
    sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
    Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol"));
    while (nFree > 0)
        {
        ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0);
        sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
        }
    Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret);
    // Once again
    User::After(KOneSecond * 2);
    sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
    Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol"));
    while (nFree > 0)
        {
        ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0);
        sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
        }
    Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret);
    // Once again
    User::After(KOneSecond * 2);
    sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
    Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol"));
    while (nFree > 0)
        {
        ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0);
        sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
        }
    // Once again
    User::After(KOneSecond * 2);
    sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
    Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol"));
    while (nFree > 0)
        {
        ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0);
        sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree);
        }

	
	// send packet 2
	User::After(KOneSecond);
	TRequestStatus stat2;
	_LIT8(sendDataTwo, "Second Send");
	Logger().WriteFormat(_L("Sending Data - Should never complete"));             
	sock.Send(sendDataTwo,0,stat2);

	User::After(KOneSecond);
	Logger().WriteFormat(_L("Now cancel the Send"));     
	sock.CancelSend();
	User::WaitForRequest(stat2);
	TESTL(stat2 == KErrCancel);
	
	Logger().WriteFormat(_L("Receiving Data -- expected to pick up sendDataOne"));
	TBuf8<100> buf;          
	TRequestStatus stat3;
	sock.Recv(buf, 0, stat3);
	User::After(KOneSecond);
	User::WaitForRequest(stat3);
	TESTL(buf.Compare(sendDataOne) == 0);
		
	// send packet 3
	_LIT8(sendDataThree, "Third Send");
	Logger().WriteFormat(_L("Sending Data ... again"));             
	TRequestStatus stat4;
	sock.Send(sendDataThree,0,stat4);
	User::After(1000);
			
	// free memory
	Logger().WriteFormat(_L("Now free memory - should get send and receive completion"));	
	Logger().WriteFormat(_L("Attempting to set KDummyOptionSetFreeMBufs Option in Protocol"));	
	ret = sock.SetOpt(KDummyOptionSetFreeMBufs, 0, 0);
	Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetFreeMBufs returned %d"), ret);
	TESTL(KErrNone == ret);	

	Logger().WriteFormat(_L("Sending Data - Should now complete"));             
	User::WaitForRequest(stat4);
	TESTL(stat4.Int() == KErrNone);

	// recieve data and compare contents to sent data
	Logger().WriteFormat(_L("Receiving Data"));
	sock.Recv(buf, 0, stat);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Recv has returned %d"), stat.Int());
	TBuf<100> buf16;
	buf16.Copy(buf);
	if(buf.Compare(sendDataThree) == 0)
		{
		SetTestStepResult(EPass);
		}
		
	Logger().WriteFormat(_L("Data Recv'ed is '%S'"), &buf16);
	sock.Close();
	ss.Close();
	return TestStepResult();
	}
/**
*   List existing network interfaces, IP addresses bound to them 
*   and fill up array of IP addresses for all interfaces.
*/
void CTestStepLLMNR_Init::ListInterfacesL()
    {
    
    RSocket socket;
    TInt    nRes;
    TInt    exceed;
    TInt    idx;
    TName   tmpBuf;
    TName   tmpBuf1;
    
    nRes = socket.Open(ipTestServer->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
    TESTL(nRes == KErrNone);
    
    TUint   bufsize = 2048;
    
    HBufC8 *buffer =NULL;
    buffer = GetBuffer(buffer, bufsize);
    TESTL(buffer != NULL);
    
    TPtr8 bufdes = buffer->Des();
    
    //-- reset array of local addresses
    ipTestServer->iLocalAddrs.Reset();
    
    //-- list all available network interfaces
    INFO_PRINTF1(KNewLine);
    INFO_PRINTF1(_L("--- available network interfaces:"));
    
    do
        {//-- get list of network interfaces
        // if exceed>0, all interface could not fit into the buffer.
        // In that case allocate a bigger buffer and retry.
        // There should be no reason for this while loop to take more than 2 rounds.
        bufdes.Set(buffer->Des());
        exceed = socket.GetOpt(KSoInetInterfaceInfo, KSolInetIfQuery, bufdes);
        if(exceed > 0)
            {
            bufsize += exceed * sizeof(TInetInterfaceInfo);
            buffer = GetBuffer(buffer, bufsize);
            TESTL(buffer != NULL);
            }
        } while (exceed > 0);
        
        if (exceed < 0)
            {
            INFO_PRINTF1(_L("socket.GetOpt() error!"));
            TESTL(EFalse);
            }
        
        TOverlayArray<TInetInterfaceInfo> infoIface(bufdes);
        
        for(idx=0; idx < infoIface.Length(); ++idx)
            {
            TInetInterfaceInfo& iface = infoIface[idx];
            
            tmpBuf.Format(_L("index:%d, name: "),iface.iIndex);
            tmpBuf.Append(iface.iName );
            tmpBuf.AppendFormat(_L(" state:%d"), iface.iState);
            INFO_PRINTF1(tmpBuf);
            }
        
        //-- list all IP addresses, bound to the interfaces
        //-- and append this address to the array of host-local addresses
        INFO_PRINTF1(KNewLine);
        INFO_PRINTF1(_L("--- IP addresses bound to the interfaces:"));
        
        do
            {
            // if exceed>0, all interface could not fit into the buffer.
            // In that case allocate a bigger buffer and retry.
            // There should be no reason for this while loop to take more than 2 rounds.
	        bufdes.Set(buffer->Des());
            exceed = socket.GetOpt(KSoInetAddressInfo, KSolInetIfQuery, bufdes);
            if(exceed > 0)
                {
                bufsize += exceed * sizeof(TInetAddressInfo);
                buffer = GetBuffer(buffer, bufsize);
                }
            } while (exceed > 0);
            
            if (exceed < 0)
                {
                INFO_PRINTF1(_L("socket.GetOpt() error!"));
                TESTL(EFalse);
                }
            
            
            //-- print out IP addresses
            TOverlayArray<TInetAddressInfo> infoAddr(bufdes);
            TInetAddr inetAddr;
            
            for(idx=0; idx < infoAddr.Length(); ++idx)
                {
                TInetAddressInfo& addr = infoAddr[idx];
                
                tmpBuf.Format(_L("iface index: %d, scopeID: %d, state: %d, IP addr: "), addr.iInterface, addr.iScopeId, addr.iState);
                inetAddr.SetAddress(addr.iAddress);
                inetAddr.Output(tmpBuf1);
                tmpBuf.Append(tmpBuf1);
                INFO_PRINTF1(tmpBuf);
                
                //-- if obtained IP address is valid and not loopback, add it to the array.
                if(inetAddr.IsLoopback() || inetAddr.IsUnspecified())
                    {}
                else
                    ipTestServer->iLocalAddrs.Append(inetAddr);
                
                }
            
            
            delete buffer;
            socket.Close();
            
            INFO_PRINTF1(KNewLine);
}
static pj_status_t rsock_enum_interface(int af,
					unsigned *p_cnt,
					pj_sockaddr ifs[]) 
{
    TInt rc;
    RSocket rSock;
    TPckgBuf<TSoInetInterfaceInfo> info;
    unsigned i;
    
    if (PjSymbianOS::Instance()->Connection()) {
    	
    	rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
    			af, PJ_SOCK_DGRAM, KProtocolInetUdp,
    			*PjSymbianOS::Instance()->Connection());
    } else {
    	
    	rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
    			af, PJ_SOCK_DGRAM, KProtocolInetUdp);
    			
    }
        
    if (rc != KErrNone)
	return PJ_RETURN_OS_ERROR(rc);
    
    rSock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
    
    for (i=0; i<*p_cnt &&
    		rSock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, 
    		             info) == KErrNone; ) 
    {
    	TInetAddr &iAddress = info().iAddress;
    	int namelen;

#if TRACE_ME
		if (1) {
			pj_sockaddr a;
			char ipaddr[PJ_INET6_ADDRSTRLEN+2];
			
			namelen = sizeof(pj_sockaddr);
			if (PjSymbianOS::Addr2pj(iAddress, a, &namelen, 
									 PJ_FALSE) == PJ_SUCCESS) 
			{
				PJ_LOG(5,(THIS_FILE, "Enum: found address %s", 
						pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2)));
			}
		}
#endif
    	
    	namelen = sizeof(ifs[i]);
    	if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen, 
    							 PJ_TRUE) != PJ_SUCCESS)
    	{
    	    continue;
    	}

    	if (ifs[i].addr.sa_family != af)
		    continue;
    	
    	++i;
    }
    
    rSock.Close();
    
    // Done
    *p_cnt = i;
    
    return PJ_SUCCESS;
}
/**
 * Change the default MTU size on NCM networking connection
 */
void CNcmConnectionManager::SetCustomMtuL()
    {    
    OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_ENTRY);
    
    RSocket socket;
    User::LeaveIfError(socket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp,
            iConnection));

    TPckgBuf<TSoInet6InterfaceInfo> interfaceInfo;
    TPckgBuf<TConnInterfaceName> interfaceName;
    
    TUint cnt = 0;
    iConnection.EnumerateConnections(cnt); // Count all underlying interfaces
    
    TUint iap = iConnPref.IapId();
    TInt index = 1;
    for (index = 1; index <= cnt; index++)
        {
        TConnectionInfoBuf info;
        iConnection.GetConnectionInfo(index, info);
        if (info().iIapId == iap)
            {
            break;
            }
        }
    
    if (index > cnt)
        {
        OstTrace0( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL, "Can not find an interface based on NCM!" );
        User::Leave(KErrNotFound);
        }
    
    interfaceName().iIndex = index;    
    OstTraceExt2( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_INFO, ";cnt=%d;interfaceName().iIndex=%u", cnt, interfaceName().iIndex );
    User::LeaveIfError(iConnection.Control(KCOLProvider, KConnGetInterfaceName, interfaceName));
    OstTraceExt3( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_NEW_MTU_SIZE, ";Interface Name=%S, ;current MTU=%d. MTU size will be changed to %d!", interfaceName().iName, interfaceInfo().iMtu, KEthernetFrameSize);
        
    TInt err = socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
    if (err != KErrNone)
        {
        OstTrace1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_START_INTER_ENUM, "Failed to set KSoInetEnumInterfaces option [%d]", err);
        User::LeaveIfError(err);              
        }
        
    err = KErrNotFound;
    while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, interfaceInfo) == KErrNone)
        {
        OstTraceExt1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_NAME, "InterfaceInfo().iName = %S", interfaceInfo().iName);
        OstTrace1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_MTU, "InterfaceInfo().iMtu = %d", interfaceInfo().iMtu);
        if (interfaceInfo().iName == interfaceName().iName)
            {
            // found the interface
            err = KErrNone;
            break;
            }
        }
    if (KErrNone != err)
        {
        OstTrace1(TRACE_ERROR, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_SEARCH_FAIL, "Can not find NCM connection: err=%x", err);
        User::LeaveIfError(err);
        }
    
    // Set new MTU size
    TPckgBuf<TSoInet6InterfaceInfo> newinterfaceInfo;
    newinterfaceInfo().iMtu = KEthernetFrameSize;	
    newinterfaceInfo().iDoPrefix = 0;
    newinterfaceInfo().iDoId = 0;
    newinterfaceInfo().iDoState = 0;
    newinterfaceInfo().iDoAnycast = 0;
    newinterfaceInfo().iDoProxy = 0;
    newinterfaceInfo().iAlias = interfaceInfo().iAlias;
    newinterfaceInfo().iDelete = interfaceInfo().iDelete;
    newinterfaceInfo().iState = interfaceInfo().iState;
    newinterfaceInfo().iSpeedMetric = interfaceInfo().iSpeedMetric;
    newinterfaceInfo().iFeatures = interfaceInfo().iFeatures;
    newinterfaceInfo().iTag = interfaceInfo().iTag;
    newinterfaceInfo().iName = interfaceInfo().iName;
    newinterfaceInfo().iSpeedMetric = interfaceInfo().iSpeedMetric;
    newinterfaceInfo().iFeatures = interfaceInfo().iFeatures;	
    newinterfaceInfo().iHwAddr = interfaceInfo().iHwAddr;
    newinterfaceInfo().iAddress = interfaceInfo().iAddress;
    newinterfaceInfo().iNetMask = interfaceInfo().iNetMask;
    newinterfaceInfo().iDefGate = interfaceInfo().iDefGate;
    newinterfaceInfo().iNameSer2 = interfaceInfo().iNameSer2;
    newinterfaceInfo().iNameSer1 = interfaceInfo().iNameSer1;
	
    OstTrace0( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_PRE_SETMTU, "About to change the default MTU size." );
	User::LeaveIfError(socket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, newinterfaceInfo));

    socket.Close();
    
    OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_EXIT);
    }
/*
 * Enumerates and returns all IPv4 interfaces
 */
static netif *enumIPvXInterfaces(JNIEnv *env, netif *ifs, TUint family)
{
    TPckgBuf<TSoInetInterfaceInfo> info;
    TSoInetInterfaceInfo &i = info();
    RSocket r;
    _LIT(proto, "ip");
    TInt err = r.Open(sserv, proto);
    if (err != KErrNone) {
	JNU_ThrowByName(env , JNU_JAVANETPKG "SocketException",
			 "Socket creation failed");
	return ifs;
    }

    /*
     * Iterate through each interface
     */
    int idx = 1;
    err = r.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl, 1);
    while ((err = r.GetOpt(KSoInetNextInterface,
	KSolInetIfCtrl, info)) == KErrNone)
    {
#ifdef _UNICODE
	TName n = i.iName;
	TUint8 n8[0x20];
	TPtr8 name8(n8, sizeof n8);
	TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(name8, n);
	fprintf(stderr, "Interface proto %s status %x\n", name8.PtrZ(),
	    i.iState);
{
	TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(name8, i.iTag);
	fprintf(stderr, "tag %s\n", name8.PtrZ());
}
	const char *if_name = (const char *)name8.PtrZ();
#else
	const char *if_name = (const char *)i.iTag.PtrZ();
#endif
	if (i.iState == EIfUp) {
	    TInetAddr ia = i.iAddress;
	    fprintf(stderr, "Address %x\n", ia.Address());
	}
	if (i.iAddress.Family() == family) {
	    TInetAddr ia = i.iAddress;
	    /*
	     * Add to the list 
	     */
	    ifs = addif(env, ifs, if_name, idx, KAfInet, ia);

	    /*
	     * If an exception occurred then free the list
	     */
	    if ((*env)->ExceptionOccurred(env)) {
		freeif(ifs);
		ifs = NULL;
		goto done;
	    }
	}
	++idx;
    }

{
    TPckgBuf<TSoInetIfQuery> q1;
    TSoInetIfQuery &q = q1();
    TInt inum = 1;
    q.iIndex = inum;

    while ((err = r.GetOpt(KSoInetIfQueryByIndex,
	KSolInetIfQuery, q1)) == KErrNone)
    {
	fprintf(stderr, "Interface %d up %d\n", inum, q.iIsUp);
#ifdef _UNICODE
	TUint8 n8[0x20];
	TPtr8 name8(n8, sizeof n8);
	TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(name8, q.iName);
	fprintf(stderr, "Interface %d name %s\n", inum, name8.PtrZ());
#endif
	fprintf(stderr, "src addr %x\n", q.iSrcAddr.Address());
	fprintf(stderr, "dst addr %x\n", q.iDstAddr.Address());
	q.iIndex = ++inum;
    }
}

done:
    r.Close();
    return ifs;
}