Leaked source code of windows server 2003
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.

55 lines
988 B

  1. #include "precomp.h"
  2. #include "getip.h"
  3. #define MAX_HOSTNAME_LENGTH 80
  4. int __stdcall GetIPAddresses(char **szAddressArray, int numAddresses)
  5. {
  6. hostent *pHostent;
  7. char szHostname[MAX_HOSTNAME_LENGTH];
  8. int nRet, nIndex;
  9. int nCount;
  10. in_addr* pInterfaceAddr;
  11. nRet = gethostname(szHostname, MAX_HOSTNAME_LENGTH);
  12. szHostname[MAX_HOSTNAME_LENGTH-1] = '\0';
  13. if (nRet < 0)
  14. {
  15. return nRet;
  16. }
  17. pHostent = gethostbyname(szHostname);
  18. if (pHostent == NULL)
  19. {
  20. return -1;
  21. }
  22. nCount = 0;
  23. for (nIndex = 0; nIndex < numAddresses; nIndex++)
  24. {
  25. if (pHostent->h_addr_list[nIndex] != NULL)
  26. nCount++;
  27. else
  28. break;
  29. }
  30. // enumerate the addresses backwards - PPP addresses will get listed
  31. // first ???
  32. for (nIndex = (nCount-1); nIndex >= 0; nIndex--)
  33. {
  34. pInterfaceAddr = (in_addr*)(pHostent->h_addr_list[nIndex]);
  35. lstrcpy(szAddressArray[nCount - 1 - nIndex], inet_ntoa(*pInterfaceAddr));
  36. }
  37. return nCount;
  38. }