Exemplo n.º 1
0
/**
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);
	}
Exemplo n.º 2
0
// 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;
}
Exemplo n.º 3
0
QString QHostInfo::localHostName()
{
    // Connect to ESOCK
    RSocketServ socketServ(qt_symbianGetSocketServer());
    RHostResolver hostResolver;

    // RConnection not required to get the host name
    int err = hostResolver.Open(socketServ, KAfInet, KProtocolInetUdp);
    if (err)
        return QString();

    THostName hostName;
    err = hostResolver.GetHostName(hostName);
    if (err)
        return QString();

    hostResolver.Close();

    return qt_TDesC2QString(hostName);
}