static TInt socket_open(lua_State* L) { lua_pushstring(L, reinterpret_cast<const char*>(KSocketServ().Ptr())); lua_gettable(L, LUA_REGISTRYINDEX); TInt handle = luaL_checkint(L, -1); // Remove handle from stack lua_pop(L, 1); RSocketServ s; s.SetHandle(handle); TUint addrFamily = to_addr_family(luaL_optstring(L, 1, "inet")); TUint sockType = to_sock_type(luaL_optstring(L, 2, "stream")); TUint protocol = to_protocol(luaL_optstring(L, 3, "tcp")); // Allocate socket using user data so that we can return it from the function, // and have it collected using __gc CActiveSocket** socket = static_cast<CActiveSocket**>(lua_newuserdata(L, sizeof(CActiveSocket*))); TRAPD(err, *socket = CActiveSocket::NewL(s, addrFamily, sockType, protocol)); if (err != KErrNone) { // Raise massive error! } // Set up metadata table lua_pushstring(L, reinterpret_cast<const char*>(KSocketType().Ptr())); lua_gettable(L, LUA_REGISTRYINDEX); lua_setmetatable(L, 1); return 1; }
/** Get the internet name of this host. Actually this will always return a null string with TCPIP 030 and onwards because the "name" of a mobile host isn't really very meaningful - in practice the IP address is chosen dynamically once you start doing real networking, at which time the ISP can resolve the IP address into a name of some sort if you really want. @return @param name @param size */ EXPORT_C int gethostname (char *name, size_t size) { int* perrno=__errno(); RSocketServ ss; TInt err=ss.Connect(1); if (err==KErrNone) { RHostResolver r; err=r.Open(ss, AF_INET, KProtocolInetUdp); if (err==KErrNone) { TBuf<128> hostname; err=r.GetHostName(hostname); if (err==KErrNone) { if (size>(size_t)hostname.Length()) { TPtr8 retval((TText8*)name,size); retval.Copy(hostname); retval.PtrZ(); } else err=ENAMETOOLONG; } r.Close(); } ss.Close(); } return MapError(err,*perrno); }
TBool TestFrameworkActionsUtils::CheckIfSmsWatcherAlreadyRunningL() { RSocketServ socketServer; RSocket socket; User::LeaveIfError(socketServer.Connect()); CleanupClosePushL(socketServer); TProtocolDesc protoInfo; TProtocolName protocolname; protocolname.Copy(KSmsDatagram); User::LeaveIfError(socketServer.FindProtocol(protocolname,protoInfo)); User::LeaveIfError(socket.Open(socketServer, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol)); CleanupClosePushL(socket); TSmsAddr addr; addr.SetSmsAddrFamily(ESmsAddrRecvAny); TInt err = socket.Bind(addr); socket.CancelAll(); CleanupStack::PopAndDestroy(2); //socketServer, socket return (err == KErrAlreadyExists); }
TVerdict CDhcpTestStep1_2::doTestStepL() /** * @return - TVerdict code only ever returns EPass, else leaves with error! * Override of base class pure virtual * Connect to DHCP Daemon - Daemon not found(test doc 4.1.2) * Daemon name in commDB specifies a non-existent daemon therefore * connection start will fail as the settings for it are incorrect... */ { SetTestStepResult(EFail); RSocketServ eSock; TInt err = eSock.Connect(); TESTEL(err == KErrNone, err); CleanupClosePushL(eSock); #ifdef _DEBUG User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 67)); #endif RConnection connNET1; err = connNET1.Open(eSock); TESTEL(err == KErrNone, err); CleanupClosePushL(connNET1); err = connNET1.Start(iConnPrefs); // see test script for IAP used TESTEL(err == KErrNotFound, err); CleanupStack::PopAndDestroy(&connNET1); CleanupStack::PopAndDestroy(&eSock); SetTestStepResult(EPass); return TestStepResult(); }
void CGetPortCommand::DoExecuteL() { TInt errorCode = KErrNone; RSocketServ socketServer; errorCode = socketServer.Connect(); if(errorCode == KErrNone) { RSocket listeningSocket; TSockAddr localAddress; //TODO: add retrying to find ports for(int i = 0; errorCode == KErrNone && i < iFreePortsNum; i++) { TInt port = iDriver->NextRandomPort(); listeningSocket.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp); localAddress.SetPort(port); errorCode = listeningSocket.Bind(localAddress); if(errorCode == KErrNone) { iFreePorts.Append(port); } listeningSocket.Close(); } } socketServer.Close(); User::LeaveIfError(errorCode); }
enum TVerdict CTestIdna08::doTestStepL() { INFO_PRINTF1(_L(" Testing the Loading of the new Library ")); INFO_PRINTF1(_L("****************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RLibrary testLibrary; TInt err = testLibrary.Load(_L("punycodeconverter.dll")); if(err == KErrNone) { INFO_PRINTF1(_L(" Loading the punycodeconverter library is successful")); SetTestStepResult(EPass); } else { INFO_PRINTF1(_L(" Loading the punycodeconverter library is NOT successful")); User::LeaveIfError(KErrNone); // just to suppress the LeaveScan warning } INFO_PRINTF1(_L("Negative Testing of SetOpt ")); INFO_PRINTF1(_L("****************************************")); RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); TBool enableIdn = ETrue;//enabling the option of IDN support TPckgC<TBool> pckgEnable(enableIdn); TInt setOptErr = hr.SetOpt(KSoInetConfigInterface , KSolInetDns , pckgEnable); if(setOptErr != KErrNone) { INFO_PRINTF1(_L(" Negative Testing of the Setopt successful ")); SetTestStepResult(EPass); } setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable); User::LeaveIfError(setOptErr); enableIdn = EFalse; TPckgC<TBool> pckgDisable(enableIdn); setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgDisable); User::LeaveIfError(setOptErr); hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
TBool CSmsReplyToStep::WatchersAlreadyRunningL() { RSocketServ server; RSocket socket; User::LeaveIfError(server.Connect()); CleanupClosePushL(server); // test if it's there... TProtocolDesc protoInfo; TProtocolName protocolname; protocolname.Copy(KSmsDatagram); User::LeaveIfError(server.FindProtocol(protocolname,protoInfo)); User::LeaveIfError(socket.Open(server, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol)); CleanupClosePushL(socket); TSmsAddr addr; addr.SetSmsAddrFamily(ESmsAddrRecvAny); TInt err = socket.Bind(addr); CleanupStack::Pop(2, &server); socket.CancelAll(); socket.Close(); server.Close(); return (err == KErrAlreadyExists); }
// from PDIS miso library // Gets the local device name. // Arguments: // - aName - object to hold the retrieved name. // // Returns an error code. static TInt GetLocalName(TDes& aName) { TInt err = KErrNone; RSocketServ socketServ; err = socketServ.Connect(); if (!err) { TProtocolName protocolName; // address and name queries are apparently supplied // by the BT stack's link manager _LIT(KBtLinkManager, "BTLinkManager"); protocolName.Copy(KBtLinkManager); TProtocolDesc protocolDesc; err = socketServ.FindProtocol(protocolName, protocolDesc); if (!err) { RHostResolver hostResolver; err = hostResolver.Open(socketServ, protocolDesc.iAddrFamily, protocolDesc.iProtocol); if (!err) { err = hostResolver.GetHostName(aName); hostResolver.Close(); } } socketServ.Close(); } return err; }
EXPORT_C int active_sock_open(lua_State* L) { RSocketServ sockServ; if (sockServ.Connect() != KErrNone) { return 0; } /* Register socket server with global context */ lua_pushstring(L, reinterpret_cast<const char*>(KSocketServ().Ptr())); lua_pushnumber(L, sockServ.Handle()); lua_settable(L, LUA_REGISTRYINDEX); luaL_register(L, "socket", active_socket); luaL_newmetatable(L, reinterpret_cast<const char*>(KSocketType().Ptr())); lua_pushcfunction(L, socket_gc); lua_setfield(L, -2, "__gc"); lua_pushstring(L, reinterpret_cast<const char*>(KSocketType().Ptr())); lua_settable(L, LUA_REGISTRYINDEX); return 1; }
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; }
// Looks up the name of the device with the given address. // Arguments: // - wantedAddr - address of the device to look up. Note that the address // is expected without colons!! e.g. "000D9319C868" // - aDeviceName - the object to hold the name once it is found // - ignoreCache - if True, performs a remote name request even if the device // name is known in the cache from a previous request. // // Returns an error code. static TInt LookupName(TBTDevAddr& wantedAddr, THostName* aDeviceName, bool ignoreCache) { TInt err = KErrNone; RSocketServ socketServer; RHostResolver hostResolver; TRequestStatus status; TNameEntry nameEntry; // make a TInquirySockAddr with the address of the device we want to look up TBTSockAddr sockAddr; sockAddr.SetBTAddr(wantedAddr); TInquirySockAddr addr = addr.Cast(sockAddr); // connect err = socketServer.Connect(); if (err) return err; // load protocol for discovery TProtocolDesc protocolDesc; err = socketServer.FindProtocol(_L("BTLinkManager"), protocolDesc); if (!err) { // initialize host resolver err = hostResolver.Open(socketServer, protocolDesc.iAddrFamily, protocolDesc.iProtocol); if (!err) { // Request name lookup. // We don't need to call SetIAC() if we're just doing name lookup. // Don't put KHostResInquiry flag in SetAction(), because that // will start a device inquiry, when we just want to find the one // name. if (ignoreCache) { addr.SetAction(KHostResName|KHostResIgnoreCache); } else { addr.SetAction(KHostResName); } hostResolver.GetByAddress(addr, nameEntry, status); User::WaitForRequest(status); if (status == KErrNone) { *aDeviceName = nameEntry().iName; err = KErrNone; } else { err = KErrGeneral; } hostResolver.Close(); } } socketServer.Close(); return err; }
TVerdict CDhcpTestStep1_3::doTestStepL() /** * @return - TVerdict code only ever returns EPass, else leaves with error! * Override of base class pure virtual * Get Active IP Address (test doc 4.1.3) * from a connection that does not use DHCP * configuration but the static settings in * commDB. Therefore any request for the address * from the DHCP daemon will fail. */ { SetTestStepResult(EFail); RSocketServ eSock; TInt err = eSock.Connect(); TESTEL(err == KErrNone, err); INFO_PRINTF2(_L("eSock.Connect() returned %d"),err); CleanupClosePushL(eSock); #ifdef _DEBUG User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 67)); #endif RConnection connNET1; err = connNET1.Open(eSock); INFO_PRINTF2(_L("connNET1.Open(eSock) returned %d"),err); TESTEL(err == KErrNone, err); CleanupClosePushL(connNET1); err = connNET1.Start(iConnPrefs); // see test script for IAP used INFO_PRINTF2(_L("connNET1.Start(prefs) returned %d"),err); TESTEL(err == KErrNone, err); TRequestStatus stat; TConnectionAddrBuf address; address().iAddressFamily = IpAddressFamilyL(); INFO_PRINTF1(_L("Just before connNET1.Ioctl(...)")); INFO_PRINTF2(_L("Size: %d "), address.Size()); INFO_PRINTF2(_L("MaxSize: %d "), address.MaxSize()); INFO_PRINTF2(_L("MaxLength: %d "), address.MaxLength()); connNET1.Ioctl(KCOLConfiguration, KConnGetCurrentAddr, stat, &address); User::WaitForRequest(stat); INFO_PRINTF2(_L("err = connNET1.Ioctl(...) returned %d"),stat.Int()); TESTEL(stat == KErrNotSupported, stat.Int()); err = connNET1.Stop(); INFO_PRINTF2(_L("connNET1.Stop() returned %d"),err); TESTEL(err == KErrNone, err); CleanupStack::PopAndDestroy(&connNET1); CleanupStack::PopAndDestroy(&eSock); SetTestStepResult(EPass); return TestStepResult(); }
/** * Get the local IP address of the device * * @note Requires at least one IP packet sent in advance! */ int net_if_getaddr4(const char *ifname, int af, struct sa *ip) { (void)ifname; if (AF_INET != af) return EAFNOSUPPORT; /* Already cached? */ if (sa_isset(&local_ip, SA_ADDR)) { sa_cpy(ip, &local_ip); return 0; } RSocketServ ss; RSocket s; TInt ret; ret = ss.Connect(); if (KErrNone != ret) { DEBUG_WARNING("connecting to socket server fail (ret=%d)\n", ret); return ECONNREFUSED; } ret = s.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp); if (KErrNone != ret) { DEBUG_WARNING("open socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr bind; bind.SetPort(0); bind.SetAddress(KInetAddrAny); ret = s.Bind(bind); if (KErrNone != ret) { DEBUG_WARNING("bind socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr local; s.LocalName(local); s.Close(); ss.Close(); sa_set_in(&local_ip, local.Address(), local.Port()); DEBUG_NOTICE("local IP addr: %j\n", &local_ip); if (!sa_isset(&local_ip, SA_ADDR)) return EINVAL; sa_cpy(ip, &local_ip); return 0; }
enum TVerdict CSocketTest8_3::InternalDoTestStepL( void ) { TVerdict verdict = EPass; Logger().WriteFormat(_L("Test Purpose: Ioctl auto bind and check started")); // 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); Logger().WriteFormat(_L("Opening a new socket")); RSocket 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("Testing StartL() with Ioctl KDummyIoctlCheckStarted")); TRequestStatus stat; socket.Ioctl(KDummyIoctlCheckStarted, stat, NULL, KIoctlDummyLevel); User::WaitForRequest(stat); Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int())); TESTL(KErrNone == stat.Int()); Logger().WriteFormat(_L("Testing AutoBind()")); TSockAddr addr; Logger().WriteFormat(_L("Trying to Connect socket")); socket.Connect(addr, stat); User::WaitForRequest(stat); Logger().WriteFormat(_L("Connect returned with status %S"), &EpocErrorToText(stat.Int())); TESTL(KErrNone == stat.Int()); Logger().WriteFormat(_L("Checking bound status with Ioctl")); socket.Ioctl(KDummyIoctlCheckBound, 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 CTestIdna04::doTestStepL() { INFO_PRINTF1(_L(" Testing GetByAddress(for an IDN) with IDN Enabled ")); INFO_PRINTF1(_L("*********************************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); TBool enableIdn = ETrue;//enabling the option of IDN support TPckgC<TBool> pckgEnable(enableIdn); TInt setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable); User::LeaveIfError(setOptErr); TInetAddr inetAddr; //inetAddr.Input(_L("83.241.177.38")); // this is the IPAddress of the domain räksmörgås.josefsson.org // as of 06 Feb 2009. If this IP changes, this test case might fail // but no harm on this. //TNameEntry resultEntry; inetAddr.Input(_L("64.233.169.103")); TNameRecord asdf; TPckgBuf<TNameRecord> resultEntry(asdf); hr.GetByAddress(inetAddr,resultEntry,myStatus); User::WaitForRequest(myStatus); TInt err = myStatus.Int(); if(err == KErrNone) { INFO_PRINTF2(_L(" GetByAddress with IDN disabled returned %d"),err); SetTestStepResult(EPass); } hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
/** RHostResolver::Open() */ void CT_InquirySockAddrData::DoCmdOpenHostResolver(const TDesC& aSection) { RSocketServ sockServ; TPtrC bluetoothSocketName; if(GetStringFromConfig(aSection, KBTSocket(), bluetoothSocketName)) { CT_BluetoothSocketNotifier* bluetoothSocketData=static_cast<CT_BluetoothSocketNotifier*>(GetDataObjectL(bluetoothSocketName)); if ( bluetoothSocketData!=NULL ) { sockServ = bluetoothSocketData->iSocketServer; } else { ERR_PRINTF1(_L("CT_CBluetoothSocketDataPersistentObject is NULL")); SetBlockResult(EFail); } } // Find protocol from socket TProtocolDesc protocolDesc; TInt err=sockServ.FindProtocol(_L("BTLinkManager"), protocolDesc); if ( err!=KErrNone ) { ERR_PRINTF2(_L("iSockServ.FindProtocol(aProtocolName, protocolDesc) = %d"), err); SetBlockResult(EFail); } if ( protocolDesc.iAddrFamily != KBTAddrFamily ) { ERR_PRINTF1(_L("Wrong iAddrFamily")); SetBlockResult(EFail); } INFO_PRINTF1(_L("Close a RHostResolver first...")); iHostResolver.Close(); // Open host resolver INFO_PRINTF1(_L("Create and initialise an RHostResolver")); err=iHostResolver.Open(sockServ, protocolDesc.iAddrFamily, protocolDesc.iProtocol); if ( err!=KErrNone ) { ERR_PRINTF2(_L("iHostResolver.Open(iSockServ, protocolDesc.iAddrFamily, protocolDesc.iProtocol) = %d"), err); SetError(err); } else { iHostResolverOpen = ETrue; INFO_PRINTF1(_L("Create and initialise an RHostResolver Completed...")); } }
// Util function void GetIpFromDHCPServer(void) { RSocketServ rSockServer; if(KErrNone==rSockServer.Connect()) { RConnection rConnect; if(KErrNone==rConnect.Open(rSockServer)) { TRequestStatus status; rConnect.Start(status); User::WaitForRequest(status); } } }
int CUdpSocket::Open() { TInt err; if (socketServer) { DEBUG_INFO("UDPsock(%p): Using RSocketServ=%p (handle=%d)\n", us, socketServer, socketServer->Handle()); iSocketServer = *socketServer; } else { err = iSocketServer.Connect(); if (KErrNone != err) { DEBUG_WARNING("iSocketServer.Connect failed\n"); return kerr2errno(err); } } if (rconnection) { DEBUG_INFO("UDPsock: Using RConnection=%p\n", rconnection); err = iSocket.Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp, *rconnection); } else { err = iSocket.Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp); } if (KErrNone != err) { DEBUG_WARNING("iSocket.Open failed (err=%d)\n", err); return kerr2errno(err); } return 0; }
// Gets the local device class. // Arguments: // - aDeviceData - object to hold the retrieved class data. // // Returns an error code. //static TInt GetLocalDeviceClass(TDeviceData& aDeviceData) static TInt GetLocalDeviceClass(TBTDeviceClass& aDeviceClass) { TInt err = KErrNone; #if defined(__SYMBIAN_9__) TInt cod; err = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetDeviceClass, cod); if (err == KErrNone) { aDeviceClass = TBTDeviceClass(cod); } #elif defined(__SYMBIAN_8__) TInt cod; err = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothDeviceClass, cod); if (err == KErrNone) { aDeviceClass = TBTDeviceClass(cod); } #else RSocketServ socketServ; RSocket sock; err = socketServ.Connect(); if (!err) { err = sock.Open(socketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP); if (!err) { THCIDeviceClassBuf codBuf; TRequestStatus status; sock.Ioctl(KHCIReadDeviceClassIoctl, status, &codBuf, KSolBtHCI); User::WaitForRequest(status); if (status.Int() == KErrNone) { aDeviceClass = TBTDeviceClass(codBuf().iMajorServiceClass, codBuf().iMajorDeviceClass, codBuf().iMinorDeviceClass); } sock.Close(); } socketServ.Close(); } #endif return err; }
enum TVerdict CTestIdna02::doTestStepL() { INFO_PRINTF1(_L(" Testing GetByName(IDN) with IDN Enabled ")); INFO_PRINTF1(_L("****************************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); _LIT(KTestName1,"räksmörgås.josefsson.org"); TName myHostName = KTestName1(); TNameEntry myResolvedName; RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); TBool enableIdn = ETrue;//enabling the option of IDN support TPckgC<TBool> pckgEnable(enableIdn); TInt setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable); User::LeaveIfError(setOptErr); hr.GetByName(myHostName,myResolvedName,myStatus); User::WaitForRequest(myStatus); TInt err = myStatus.Int(); if(err == KErrNone) { INFO_PRINTF2(_L(" GetByName(%S) with IDN Enabled returned KErrNone "),&myHostName); SetTestStepResult(EPass); } hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
// methods to allow for the closing of the socket server when the chain is stopped void ILibSocketWrapper_Create() { if(Initialized==0) { socketServer.Connect(16); Initialized = 1; } }
TVerdict CDhcpTestStep1_1::doTestStepL() /** * @return - TVerdict code, only ever returns EPass, else leaves with error! * Override of base class pure virtual * Connect to DHCP Daemon (test doc 4.1.1) * Test cannot explicitly connect as we use the * RConnection API here which will test full * functionality through the system. This test * therefore starts an ethernet connection with * settings in commDB to specify using dhcp configuration * to provide the connection with an address. If the connection * starts successfully, then DHCP was used to configure an * address therefore connection to DHCP by NIFMAN was achieved... */ { SetTestStepResult(EFail); RSocketServ eSock; TInt err = eSock.Connect(); TESTEL(err == KErrNone, err); CleanupClosePushL(eSock); #ifdef _DEBUG User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 67)); User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv6, 547)); #endif RConnection connNET1; err = connNET1.Open(eSock); TESTEL(err == KErrNone, err); CleanupClosePushL(connNET1); err = connNET1.Start(iConnPrefs); // see test script for IAP used TESTEL(err == KErrNone, err); err = connNET1.Stop(); TESTEL(err == KErrNone, err); CleanupStack::PopAndDestroy(&connNET1); CleanupStack::PopAndDestroy(&eSock); SetTestStepResult(EPass); return TestStepResult(); }
void CTe_rtpSuite::ConfigureReflectorModeL(TBool aMode, TInetAddr& aAddr) { /* Configures the reflector to change the SSRC or not */ RSocketServ sockServer; //Open a connection RConnection conn; User::LeaveIfError(sockServer.Connect()); CleanupClosePushL(sockServer); User::LeaveIfError(conn.Open(sockServer)); CleanupClosePushL(conn); //Start the connection User::LeaveIfError(conn.Start()); RSocket ctrlSock; User::LeaveIfError(ctrlSock.Open(sockServer,KAfInet, KSockDatagram, KProtocolInetUdp, conn)); CleanupClosePushL(ctrlSock); TBuf8<64> lCmdBuff; TUint8* lPtr = const_cast<TUint8*>(lCmdBuff.Ptr()); TUint32* lIntData = (TUint32*)lPtr; *lIntData = ByteOrder::Swap32(0xFF00BABE); if (aMode) { *(lIntData + 1) = ByteOrder::Swap32(0xCD000100); } else { *(lIntData + 1) = ByteOrder::Swap32(0xCD000101); } lCmdBuff.SetLength(64); TRequestStatus lMyReqStat; ctrlSock.SendTo(lCmdBuff,aAddr,0,lMyReqStat); User::WaitForRequest(lMyReqStat); ctrlSock.Close(); conn.Close(); sockServer.Close(); CleanupStack::Pop(3); }
// from PDIS miso library // Gets the local device address. // Arguments: // - aAddress - object to hold the retrieved address. // // Returns an error code. static TInt GetLocalAddress(TBTDevAddr& aAddress) { TInt err = KErrNone; #if defined(__SYMBIAN_9__) TPtr8 ptr(aAddress.Des()); err = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetLocalDeviceAddress, ptr); #elif defined(__SYMBIAN_8__) TPtr8 ptr(aAddress.Des()); err = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothLocalDeviceAddress, ptr); #else RSocketServ socketServ; err = socketServ.Connect(); if (err) return err; // this solution comes from the "bthci" Series 60 example; // does not work on Symbian 8-up RSocket socket; err = socket.Open(socketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP); if (!err) { TPckgBuf<TBTDevAddr> btDevAddrPckg; TRequestStatus status; socket.Ioctl(KHCILocalAddressIoctl, status, &btDevAddrPckg, KSolBtHCI); User::WaitForRequest(status); err = status.Int(); if (!err) { TPtrC8 src(btDevAddrPckg().Des()); TPtr8 dest(aAddress.Des()); dest.Copy(src); } socket.Close(); } socketServ.Close(); #endif return err; }
TVerdict CDhcpTestStep1_4::doTestStepL() /** * @return - TVerdict code only ever returns EPass, else leaves with error! * Override of base class pure virtual * Get DHCP Server Address (test case 4.1.4) * As no DHCP configuration is used for this * test, the connection cannot be queried for * the DHCP Server that assigned any address... */ { SetTestStepResult(EFail); RSocketServ eSock; TInt err = eSock.Connect(); TESTEL( err == KErrNone, err); CleanupClosePushL(eSock); #ifdef _DEBUG User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 67)); #endif RConnection connNET1; err = connNET1.Open(eSock); TESTEL( err == KErrNone, err); CleanupClosePushL(connNET1); err = connNET1.Start(iConnPrefs); // see test script for IAP used TESTEL(err == KErrNone, err); TRequestStatus stat; TConnectionAddrBuf address; address().iAddressFamily = IpAddressFamilyL(); connNET1.Ioctl(KCOLConfiguration, KConnGetServerAddr, stat, &address); User::WaitForRequest(stat); TESTEL( stat == KErrNotSupported, stat.Int()); err = connNET1.Stop(); TESTEL(err == KErrNone, err); CleanupStack::PopAndDestroy(&connNET1); CleanupStack::PopAndDestroy(&eSock); SetTestStepResult(EPass); return TestStepResult(); }
enum TVerdict CTestIdna05::doTestStepL() { INFO_PRINTF1(_L(" Testing GetByName(IDN in UTF-16) without IDN Enabled ")); INFO_PRINTF1(_L("***********************************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); THostName utf16HostName; TInt surrogateInt = 55301 ; //0xD805 utf16HostName.Copy((const unsigned short*)&surrogateInt); surrogateInt = 57173; // 0xDF55 utf16HostName.Append((const unsigned short*)&surrogateInt, sizeof(TInt)); TNameEntry myResolvedName; hr.GetByName(utf16HostName,myResolvedName,myStatus); User::WaitForRequest(myStatus); TInt err = myStatus.Int(); if(err == KErrDndBadName) { INFO_PRINTF1(_L(" GetByName (IDN in UTF16) without IDN enabled returned KErrDndBadName")); SetTestStepResult(EPass); } hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
enum TVerdict CTestIdna03::doTestStepL() { INFO_PRINTF1(_L(" Testing GetByAddress(for an IDN) without IDN Enabled ")); INFO_PRINTF1(_L("*********************************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); TInetAddr inetAddr; inetAddr.Input(_L("83.241.177.38")); // this is the IPAddress of the domain räksmörgås.josefsson.org // as of 06 Feb 2009. If this IP changes, this test case might fail // but no harm on this. TNameEntry resultEntry; hr.GetByAddress(inetAddr,resultEntry,myStatus); User::WaitForRequest(myStatus); TInt err = myStatus.Int(); if(err == KErrNone) { INFO_PRINTF2(_L(" GetByAddress with IDN disabled returned %d"),err); SetTestStepResult(EPass); } hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
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; }
enum TVerdict CTestIdna01::doTestStepL() { INFO_PRINTF1(_L(" Testing GetByName(IDN) without IDN Enabled ")); INFO_PRINTF1(_L("****************************************************")); SetTestStepResult(EFail); // By default start the test case with failure. RSocketServ pSocketServ; User::LeaveIfError(pSocketServ.Connect()); RConnection myConnection; myConnection.Open(pSocketServ, KAfInet); TRequestStatus myStatus=KErrNone; myConnection.Start(myStatus); User::WaitForRequest(myStatus); _LIT(KTestName1,"räksmörgås.josefsson.org"); TName myHostName = KTestName1(); TNameEntry myResolvedName; RHostResolver hr; hr.Open(pSocketServ,KAfInet,KProtocolInetUdp); hr.GetByName(myHostName,myResolvedName,myStatus); User::WaitForRequest(myStatus); TInt err = myStatus.Int(); if(err == KErrDndNameNotFound) { INFO_PRINTF2(_L(" GetByName(%S) without IDN Enabled returned KErrDndNameNotFound "),&myHostName); SetTestStepResult(EPass); } hr.Close(); myConnection.Close(); pSocketServ.Close(); return TestStepResult(); }
void ILibSocketWrapper_Destroy() { // make sure all sockets and connections are closed for (int i = 0; i < SOCKET_ARRAY_SIZE; i++) { ILibSocketWrapper_close(i); } // release the socket server socketServer.Close(); }