本文整理汇总了C++中GetAdaptersInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ GetAdaptersInfo函数的具体用法?C++ GetAdaptersInfo怎么用?C++ GetAdaptersInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetAdaptersInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
DWORD WINAPI CLuzj_ZTEDlg::GetMacIP(const char *adaptername, char *ip, unsigned char *mac)
{
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD dwBufLen = sizeof(IP_ADAPTER_INFO);
DWORD dwStatus;
AdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen);
if(AdapterInfo == NULL) return -1;
dwStatus = GetAdaptersInfo(AdapterInfo,&dwBufLen);
if(dwStatus == ERROR_BUFFER_OVERFLOW) {
free(AdapterInfo);
AdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen);
dwStatus = GetAdaptersInfo(AdapterInfo,&dwBufLen);
if(AdapterInfo == NULL) return -1;
}
if(dwStatus != NO_ERROR) {
if(AdapterInfo != NULL) free(AdapterInfo);
return -2;
}
if(ip) memset(ip, 0, 16);
if(mac) memset(mac, 0, 6);
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
if(adaptername != NULL) {
while(pAdapterInfo) {
if (stricmp(adaptername,pAdapterInfo->AdapterName) == 0) {
if(mac) memcpy(mac, pAdapterInfo->Address, 6);
if(ip) strncpy(ip, pAdapterInfo->IpAddressList.IpAddress.String, 16);
break;
}
pAdapterInfo = pAdapterInfo->Next;
};
}
free(AdapterInfo);
if(pAdapterInfo == NULL) return -3;
return 0;
}
示例2: main
int main(int argc, char** argv)
{
WSADATA wsaData;
PIP_ADAPTER_INFO pAdapterInfo = NULL, pAdapter = NULL;
ULONG ulOutBufLen;
u_char p[6];
WSAStartup(MAKEWORD(2,2), &wsaData);
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo);
pAdapterInfo = (PIP_ADAPTER_INFO) malloc(ulOutBufLen);
}
GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
pAdapter = pAdapterInfo;
while(pAdapter) {
printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
memcpy(p, pAdapter->Address, 6);
printf("\tAdapter Addr: \t%02X:%02X:%02X:%02X:%02X:%02X\n",
p[0],p[1],p[2],p[3],p[4],p[5]);
printf("\tIP Addr: \t%s\n", pAdapter->IpAddressList.IpAddress.String);
printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);
printf("\tIP Gateway: \t%s\n", pAdapter->GatewayList.IpAddress.String);
if (pAdapter->DhcpEnabled) {
printf("\tDHCP Enable: Yes\n");
printf("\tLease Obtained: %ld\n", pAdapter->LeaseObtained);
} else {
printf("\tDHCP Enable: No\n");
}
if (pAdapter->HaveWins) {
printf("\tHave Wins: Yes\n");
printf("\t\tPrimary Wins Server: \t%s\n", pAdapter->PrimaryWinsServer.IpAddress.String);
printf("\t\tSecondary Wins Server: \t%s\n", pAdapter->SecondaryWinsServer.IpAddress.String);
} else {
printf("\tHave Wins: No\n");
}
pAdapter = pAdapter->Next;
}
return 0;
}
示例3: GetMACaddress
void GetMACaddress(char *mac_address)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs
DWORD dwBufLen = sizeof(AdapterInfo); // Save the memory size of buffer
DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
assert(dwStatus == ERROR_SUCCESS); // Verify return value is valid, no buffer overflow
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
sprintf(mac_address,"%02X:%02X:%02X:%02X:%02X:%02X", pAdapterInfo->Address[0],pAdapterInfo->Address[1],pAdapterInfo->Address[2],pAdapterInfo->Address[3],pAdapterInfo->Address[4],pAdapterInfo->Address[5]);
}
示例4: getMAC
//////////////////////////////////////////////////////
//Anti Cheat
char* getMAC(){// By Yuri-BR
PIP_ADAPTER_INFO AdapterInfo;
DWORD dwBufLen = sizeof(AdapterInfo);
char *mac_addr = (char*)malloc(17);
AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
if (AdapterInfo == NULL)
{
printf("Error allocating memory needed to call GetAdaptersinfo\n");
}
// Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW)
{
AdapterInfo = (IP_ADAPTER_INFO *) malloc(dwBufLen);
if (AdapterInfo == NULL)
{
printf("Error allocating memory needed to call GetAdaptersinfo\n");
}
}
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR)
{
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
do
{
sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X", // By Yuri-BR
pAdapterInfo->Address[0], pAdapterInfo->Address[1],
pAdapterInfo->Address[2], pAdapterInfo->Address[3],
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
return mac_addr;
printf("\n");
pAdapterInfo = pAdapterInfo->Next;
}
while(pAdapterInfo);
}
free(AdapterInfo);
}
示例5: udp_join_multicast_group_with_all_ip
static TinyRet udp_join_multicast_group_with_all_ip(int fd, const char *group)
{
IP_ADAPTER_INFO * pNextAdapter = NULL;
IP_ADAPTER_INFO * ipAdaptersInfo = NULL;
ULONG infolen = sizeof(IP_ADAPTER_INFO);
ipAdaptersInfo = (IP_ADAPTER_INFO *)tiny_malloc(infolen);
if (GetAdaptersInfo(ipAdaptersInfo, &infolen) == ERROR_BUFFER_OVERFLOW)
{
tiny_free(ipAdaptersInfo);
ipAdaptersInfo = (IP_ADAPTER_INFO *)tiny_malloc(infolen);
}
if (GetAdaptersInfo(ipAdaptersInfo, &infolen))
{
tiny_free(ipAdaptersInfo);
return TINY_RET_E_INTERNAL;
}
for (pNextAdapter = ipAdaptersInfo; pNextAdapter; pNextAdapter = pNextAdapter->Next)
{
IP_ADDR_STRING *pNextIp = NULL;
for (pNextIp = &(pNextAdapter->IpAddressList); pNextIp; pNextIp = pNextIp->Next)
{
unsigned long ip = inet_addr(pNextIp->IpAddress.String);
if (ip == 0)
{
break;
}
LOG_D(TAG, "join MultiGroup ip: %s", pNextIp->IpAddress.String);
udp_join_multicast_group_with_ip(fd, group, ip);
}
}
tiny_free(ipAdaptersInfo);
return TINY_RET_OK;
}
示例6: STDMETHODIMP_
// 是否存在网关
STDMETHODIMP_(BOOL) CStatistic::IsNetGatewayExists(void)
{
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
BOOL bExists = FALSE;
DWORD dwRetVal = 0;
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);
if(pAdapterInfo)
{
dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen);
if(dwRetVal == ERROR_BUFFER_OVERFLOW )
{
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
if(pAdapterInfo)
dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen);
}
if( dwRetVal == NO_ERROR)
{
pAdapter = pAdapterInfo;
while (pAdapter)
{
if(pAdapter->GatewayList.IpAddress.String[0])
{
bExists = TRUE;
break;
}
pAdapter = pAdapter->Next;
}
}
free(pAdapterInfo);
}
return bExists;
}
示例7: malloc
char *macAddress(void)
{
IP_ADAPTER_INFO *adapterInfo;
ULONG adapterInfoSize = 0;
if (GetAdaptersInfo(NULL, &adapterInfoSize) != ERROR_SUCCESS)
{
adapterInfo = (IP_ADAPTER_INFO *) malloc(adapterInfoSize);
}
if (GetAdaptersInfo(adapterInfo, &adapterInfoSize) != ERROR_SUCCESS)
{
return NULL;
}
{
char *mac = String_asHex(adapterInfo->Address, adapterInfo->AddressLength);
free(adapterInfo);
return mac;
}
}
示例8: getAdaptersInfo
int getAdaptersInfo()
{
char MacAddressStr[256]; //mac address converted to a string
char MacOneByteStr[10]; //used to hold one byte of mac address
int retval = 0; //return -1 if no adapters found
if (isIPHLPAvail()) //inits iphlpapi and returns true if dll loaded
{
//just return count if we already did this before
if (AdapterCount)
return AdapterCount;
IP_ADAPTER_INFO *pAdapterInfo; //points to buffer hold linked list adapter info
DWORD dwSize = (sizeof(IP_ADAPTER_INFO) * MAX_ADAPTERS) + sizeof(DWORD); //size for lots of adapters
char *buffer = new char[dwSize]; //allocate space for lots of adapters
if (buffer)
{
pAdapterInfo = (IP_ADAPTER_INFO *)buffer; //point to buffer
if (GetAdaptersInfo(
pAdapterInfo, // buffer for mapping table
&dwSize) == NO_ERROR) // sort the table
{
while (pAdapterInfo)
{
strcpy(adapters[AdapterCount].AdapterName, pAdapterInfo->Description);
strcpy(adapters[AdapterCount].IpAddress, (const char *)pAdapterInfo->IpAddressList.IpAddress.String);
//build mac address as a string
*MacAddressStr = '\0';
for (unsigned int loop = 0; loop < pAdapterInfo->AddressLength; loop++)
{
if (strlen(MacAddressStr))
strcat(MacAddressStr,"-");
sprintf(MacOneByteStr,"%02X",pAdapterInfo->Address[loop]);
strcat(MacAddressStr,MacOneByteStr);
}
strcpy((char *)adapters[AdapterCount].MacAddress, MacAddressStr);
AdapterCount++;
pAdapterInfo = pAdapterInfo->Next;
}
retval = AdapterCount;
}
delete [] buffer;
}
}
return retval;
}
示例9: GetAdaptersInfo
const char* wyDevice::getDeviceId() {
// Get the buffer length required for IP_ADAPTER_INFO.
ULONG bufLen = 0;
BYTE* buffer = 0;
if(GetAdaptersInfo(0, &bufLen) == ERROR_BUFFER_OVERFLOW) {
// Now the BufferLength contain the required buffer length.
// Allocate necessary buffer.
buffer = new BYTE[bufLen];
// Get the Adapter Information.
PIP_ADAPTER_INFO adapterInfo = reinterpret_cast<PIP_ADAPTER_INFO>(buffer);
GetAdaptersInfo(adapterInfo, &bufLen);
// Iterate the network adapters and print their MAC address.
if(adapterInfo) {
// Assuming pAdapterInfo->AddressLength is 6.
sprintf(sIMEI, "%02x:%02x:%02x:%02x:%02x:%02x",
adapterInfo->Address[0],
adapterInfo->Address[1],
adapterInfo->Address[2],
adapterInfo->Address[3],
adapterInfo->Address[4],
adapterInfo->Address[5]);
}
// make md5 for mac address
const char* md5 = wyMD5::md5(sIMEI);
memcpy(sIMEI, md5, strlen(md5));
wyFree((void*)md5);
// release buffer
delete[] buffer;
// return
return sIMEI;
} else {
return NULL;
}
}
示例10: UpdateData
void CIPFindDlg::OnCbnSelchangeCmbDevice()
{
UpdateData(FALSE);
int nCurSel = m_Device.GetCurSel();
ULONG len = 0;
GetAdaptersInfo(NULL, &len);
PIP_ADAPTER_INFO p = static_cast<PIP_ADAPTER_INFO>(malloc(len));
GetAdaptersInfo(p, &len);
int i=0;
for (PIP_ADAPTER_INFO q = p; q != NULL; q = q->Next)
{
if (i++ == nCurSel)
{
GetCurSelIPMask(q->IpAddressList.IpAddress.String, q->IpAddressList.IpMask.String);
}
}
free(p);
}
示例11: mapport
bool mapport(short port)
{
UPnP UPnPvar;
PIP_ADAPTER_INFO pAdapterInfo = NULL;
DWORD dwRetVal = 0;
char strLocalIP[256];
pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
}
if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
{
strcpy(strLocalIP,pAdapterInfo->IpAddressList.IpAddress.String);
}
else
{
strcpy(strLocalIP,"");
}
free(pAdapterInfo);
UPnPvar.Set_UPnP(strLocalIP,"TCP","UVNC",port);
UPnPvar.OpenPorts(true);
char testchar[256];
strcpy(testchar,UPnPvar.GetExternalIP());
UPnPvar.ClosePorts(true);
return 0;
}
示例12: GetAllAdaptersInfo
// 取得所有网卡的信息 David 2010.6.2 add
PIP_ADAPTER_INFO GetAllAdaptersInfo()
{
PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
ASSERT(NULL != pAdapterInfo);
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
// 空间不够则重新分配空间
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
}
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == NO_ERROR){
return pAdapterInfo;
}
else
{
free(pAdapterInfo);
return NULL;
}
}
示例13: IP_ADAPTER_INFO
vector<ULONG>* SocketExtension::LocalIPs()
{
PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO();
unsigned long stSize = sizeof(IP_ADAPTER_INFO);
int nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize);
if (ERROR_BUFFER_OVERFLOW == nRel)
{
delete pIpAdapterInfo;
pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize];
nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize);
}
vector<ULONG>* address = NULL;
if (ERROR_SUCCESS == nRel)
{
while (pIpAdapterInfo)
{
IP_ADDR_STRING *pIpAddrString = &(pIpAdapterInfo->IpAddressList);
do
{
ULONG addrnum = inet_addr(pIpAddrString->IpAddress.String);
if (addrnum != 0)
{
if (address == NULL)
{
address = new vector<ULONG>;
}
address->push_back(addrnum);
}
pIpAddrString = pIpAddrString->Next;
} while (pIpAddrString);
pIpAdapterInfo = pIpAdapterInfo->Next;
}
}
if (pIpAdapterInfo)
delete pIpAdapterInfo;
return address;
}
示例14: sizeof
void EnvironmentImpl::nodeIdImpl(NodeId& id)
{
std::memset(&id, 0, sizeof(id));
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = 0;
ULONG len = sizeof(IP_ADAPTER_INFO);
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
// Make an initial call to GetAdaptersInfo to get
// the necessary size into len
DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
if (rc == ERROR_BUFFER_OVERFLOW)
{
delete [] reinterpret_cast<char*>(pAdapterInfo);
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
}
else if (rc != ERROR_SUCCESS)
{
return;
}
if (GetAdaptersInfo(pAdapterInfo, &len) == NO_ERROR)
{
pAdapter = pAdapterInfo;
bool found = false;
while (pAdapter && !found)
{
if (pAdapter->Type == MIB_IF_TYPE_ETHERNET && pAdapter->AddressLength == sizeof(id))
{
found = true;
std::memcpy(&id, pAdapter->Address, pAdapter->AddressLength);
}
pAdapter = pAdapter->Next;
}
}
delete [] reinterpret_cast<char*>(pAdapterInfo);
}
示例15: FillAdaptersInfo
unsigned __int64 FillAdaptersInfo(unsigned int *pRet2)
{
IP_ADAPTER_INFO AdapterInfo[16], *pAdapter;
ULONG uBufLen = sizeof(AdapterInfo);
__int64 ret = 0;
if (GetAdaptersInfo(AdapterInfo, &uBufLen) == ERROR_SUCCESS)
{
for (pAdapter = AdapterInfo; pAdapter; pAdapter = pAdapter->Next)
{
if (pAdapter->AddressLength == 6 && pAdapter->Type == MIB_IF_TYPE_ETHERNET)
ret ^= BytesSHA1I64(pAdapter->Address, pAdapter->AddressLength);
}
}
return ret;
}