Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. ipsupp.cxx
  5. Abstract:
  6. This module defines functions that are generic for Internet servers
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 15-Nov-1995
  9. --*/
  10. #include "precomp.hxx"
  11. #include <inetsvcs.h>
  12. #include <winsock2.h>
  13. #define LOCAL127 0x0100007F // 127.0.0.1
  14. BOOL
  15. IsIPAddressLocal(
  16. IN DWORD LocalIP,
  17. IN DWORD RemoteIP
  18. )
  19. {
  20. INT err;
  21. CHAR nameBuf[MAX_PATH+1];
  22. PHOSTENT hostent;
  23. PIN_ADDR p;
  24. CHAR **list;
  25. //
  26. // if local and remote are the same, then this is local
  27. //
  28. if ( (LocalIP == RemoteIP) ||
  29. (RemoteIP == LOCAL127) ||
  30. (LocalIP == LOCAL127) ) {
  31. return(TRUE);
  32. }
  33. err = gethostname( nameBuf, sizeof(nameBuf));
  34. if ( err != 0 ) {
  35. IIS_PRINTF((buff,"IsIPAddressLocal: Err %d in gethostname\n",
  36. WSAGetLastError()));
  37. return(FALSE);
  38. }
  39. hostent = gethostbyname( nameBuf );
  40. if ( hostent == NULL ) {
  41. IIS_PRINTF((buff,"IsIPAddressLocal: Err %d in gethostbyname\n",
  42. WSAGetLastError()));
  43. return(FALSE);
  44. }
  45. list = hostent->h_addr_list;
  46. while ( (p = (PIN_ADDR)*list++) != NULL ) {
  47. if ( p->s_addr == RemoteIP ) {
  48. return(TRUE);
  49. }
  50. }
  51. IIS_PRINTF((buff,"Not Local[%x %x]\n", LocalIP, RemoteIP));
  52. return(FALSE);
  53. } // IsIPAddressLocal