Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PIPSocket::IsLocalHost ( const PString hostname ) [static, inherited]

Determine if the specified host is actually the local machine. This can be any of the host aliases or multi-homed IP numbers or even the special number for the loopback device.

TRUE if the host is the local machine.

Definition at line 782 of file winsock.cxx.

References PIPSocket::GetHostAddress(), PIPSocket::GetHostName(), PString::IsEmpty(), and PIPSocket::Address::IsLoopback().

Referenced by PSTUNClient::GetNatType().

  if (hostname.IsEmpty())
    return TRUE;

  if (hostname *= "localhost")
    return TRUE;

  // lookup the host address using inet_addr, assuming it is a "." address
  PIPSocket::Address addr = hostname;
  if (addr.IsLoopback())  // Is or ::1
    return TRUE;

  if (addr == 0) {
    if (!GetHostAddress(hostname, addr))
      return FALSE;

  // Seb: Should check that it's really IPv4 aware.
  struct hostent * host_info = ::gethostbyname(GetHostName());

  if (P_IsOldWin95())
    return addr == *(struct in_addr *)host_info->h_addr_list[0];

  for (PINDEX i = 0; host_info->h_addr_list[i] != NULL; i++) {
#if P_HAS_IPV6
    if (host_info->h_length == 16) {
      if (addr == *(struct in6_addr *)host_info->h_addr_list[i])
        return TRUE;
    if (addr == *(struct in_addr *)host_info->h_addr_list[i])
      return TRUE;
  return FALSE;

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index