mirror of
https://github.com/a0rtega/pafish
synced 2024-11-22 06:11:18 +03:00
Minor refactor in GetAdaptersAddresses functions
This commit is contained in:
parent
017d5dfbbd
commit
54f33a2929
@ -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);
|
||||
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;
|
||||
char mac[6]={0};
|
||||
while (ppalist){
|
||||
if (ppalist->PhysicalAddressLength==0x6){
|
||||
memcpy(mac,ppalist->PhysicalAddress,0x6);
|
||||
if (!memcmp(mac_vendor, mac, 3)) { /* First 3 bytes are the same */
|
||||
res = TRUE;
|
||||
break;
|
||||
}
|
||||
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,0,0,palist,&alist_size);
|
||||
char mac[6]={0};
|
||||
while (palist){
|
||||
if (palist->PhysicalAddressLength==0x6){
|
||||
memcpy(mac,palist->PhysicalAddress,0x6);
|
||||
if (!memcmp(mac_vendor, mac, 3)) { /* First 3 bytes are the same */
|
||||
LocalFree(palist);
|
||||
return TRUE;
|
||||
}
|
||||
ppalist = ppalist->Next;
|
||||
}
|
||||
LocalFree(palist);
|
||||
palist = palist->Next;
|
||||
}
|
||||
LocalFree(palist);
|
||||
}
|
||||
WSACleanup();
|
||||
}
|
||||
return res;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int pafish_check_adapter_name(char * name) {
|
||||
@ -187,16 +181,18 @@ 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 (GetAdaptersAddresses(AF_UNSPEC, 0, 0, palist, &alist_size) == ERROR_SUCCESS) {
|
||||
while (palist) {
|
||||
if (wcsstr(palist->Description, aux)) {
|
||||
LocalFree(palist);
|
||||
return TRUE;
|
||||
if (palist) {
|
||||
if (GetAdaptersAddresses(AF_UNSPEC, 0, 0, palist, &alist_size) == ERROR_SUCCESS) {
|
||||
while (palist) {
|
||||
if (wcsstr(palist->Description, aux)) {
|
||||
LocalFree(palist);
|
||||
return TRUE;
|
||||
}
|
||||
palist = palist->Next;
|
||||
}
|
||||
palist = palist->Next;
|
||||
}
|
||||
LocalFree(palist);
|
||||
}
|
||||
LocalFree(palist);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user