Minor refactor in GetAdaptersAddresses functions

This commit is contained in:
Alberto Ortega 2015-08-30 18:44:49 +02:00
parent 017d5dfbbd
commit 54f33a2929

View File

@ -148,34 +148,28 @@ inline int pafish_exists_file(char * filename) {
}
int pafish_check_mac_vendor(char * mac_vendor) {
WSADATA WSD;
int res = FALSE;
unsigned long alist_size = 0, ret;
if(!WSAStartup(MAKEWORD(2,2),&WSD)){
unsigned long alist_size = 0;
int ret = GetAdaptersAddresses(AF_UNSPEC,GAA_FLAG_INCLUDE_PREFIX,0,0,&alist_size);
ret = GetAdaptersAddresses(AF_UNSPEC,0,0,0,&alist_size);
if(ret==ERROR_BUFFER_OVERFLOW) {
IP_ADAPTER_ADDRESSES* palist = (IP_ADAPTER_ADDRESSES*)LocalAlloc(LMEM_ZEROINIT,alist_size);
if(palist) {
GetAdaptersAddresses(AF_UNSPEC,GAA_FLAG_INCLUDE_PREFIX,0,palist,&alist_size);
IP_ADAPTER_ADDRESSES* ppalist=palist;
GetAdaptersAddresses(AF_UNSPEC,0,0,palist,&alist_size);
char mac[6]={0};
while (ppalist){
if (ppalist->PhysicalAddressLength==0x6){
memcpy(mac,ppalist->PhysicalAddress,0x6);
while (palist){
if (palist->PhysicalAddressLength==0x6){
memcpy(mac,palist->PhysicalAddress,0x6);
if (!memcmp(mac_vendor, mac, 3)) { /* First 3 bytes are the same */
res = TRUE;
break;
LocalFree(palist);
return TRUE;
}
}
ppalist = ppalist->Next;
palist = palist->Next;
}
LocalFree(palist);
}
}
WSACleanup();
}
return res;
return FALSE;
}
int pafish_check_adapter_name(char * name) {
@ -187,6 +181,7 @@ int pafish_check_adapter_name(char * name) {
ret = GetAdaptersAddresses(AF_UNSPEC, 0, 0, 0, &alist_size);
if (ret == ERROR_BUFFER_OVERFLOW) {
IP_ADAPTER_ADDRESSES *palist = (IP_ADAPTER_ADDRESSES*)LocalAlloc(LMEM_ZEROINIT, alist_size);
if (palist) {
if (GetAdaptersAddresses(AF_UNSPEC, 0, 0, palist, &alist_size) == ERROR_SUCCESS) {
while (palist) {
if (wcsstr(palist->Description, aux)) {
@ -198,6 +193,7 @@ int pafish_check_adapter_name(char * name) {
}
LocalFree(palist);
}
}
return FALSE;
}