1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #include <winsock2.h> #include <iphlpapi.h> #include <stdio.h> #include <stdlib.h> #pragma comment(lib, "IPHLPAPI.lib") #define MALLOC(x) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) /* * According Microsofts example on MSDN * */ int main() { PIP_ADAPTER_INFO lAdapterInfo; PIP_ADAPTER_INFO lAdapter = NULL; UINT lCounter; ULONG lOutBufLen = sizeof(IP_ADAPTER_INFO); if ((lAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO))) != NULL) { if (GetAdaptersInfo(lAdapterInfo, &lOutBufLen) == ERROR_BUFFER_OVERFLOW) { FREE(lAdapterInfo); if ((lAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(lOutBufLen)) == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); return(1); } // if ((lAdapt... } // if (GetAd... if (GetAdaptersInfo(lAdapterInfo, &lOutBufLen) == NO_ERROR) { for (lAdapter = lAdapterInfo; lAdapter; lAdapter = lAdapter->Next) { printf("\tComboIndex: \t%d\n", lAdapter->ComboIndex); printf("\tAdapter Name: \t%s\n", lAdapter->AdapterName); printf("\tAdapter Desc: \t%s\n", lAdapter->Description); printf("\tAdapter Addr: \t"); for (lCounter = 0; lCounter < lAdapter->AddressLength; lCounter++) { if (lCounter == (lAdapter->AddressLength - 1)) printf("%.2X\n", (int) lAdapter->Address[lCounter]); else printf("%.2X-", (int) lAdapter->Address[lCounter]); } // for (lCou... printf("\tIndex: \t%d\n", lAdapter->Index); printf("\tType: \t"); switch (lAdapter->Type) { case MIB_IF_TYPE_OTHER: printf("Other\n"); break; case MIB_IF_TYPE_ETHERNET: printf("Ethernet\n"); break; case MIB_IF_TYPE_TOKENRING: printf("Token Ring\n"); break; case MIB_IF_TYPE_FDDI: printf("FDDI\n"); break; case MIB_IF_TYPE_PPP: printf("PPP\n"); break; case MIB_IF_TYPE_LOOPBACK: printf("Lookback\n"); break; case MIB_IF_TYPE_SLIP: printf("Slip\n"); break; default: printf("Unknown type %ld\n", lAdapter->Type); break; } // switch(... printf("\tIP Address: \t%s\n", lAdapter->IpAddressList.IpAddress.String); printf("\tIP Mask: \t%s\n", lAdapter->IpAddressList.IpMask.String); printf("\tGateway: \t%s\n", lAdapter->GatewayList.IpAddress.String); printf("\n\n"); } // for (pAdapter... } // if (GetAdapte... if (lAdapterInfo) FREE(lAdapterInfo); } // if ((lAdapterInfo... system("pause"); return(0); } |