Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue occurring when multiple DNS Servers are configured #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion fakenet/diverters/winutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import subprocess

NO_ERROR = 0
ERROR_BUFFER_OVERFLOW = 111

AF_INET = 2
AF_INET6 = 23
Expand Down Expand Up @@ -873,7 +874,29 @@ def get_network_params(self):
OutBufLen = ULONG(sizeof(FIXED_INFO))
FixedInfo = FIXED_INFO()

if not windll.iphlpapi.GetNetworkParams(byref(FixedInfo), byref(OutBufLen)) == NO_ERROR:
ret = windll.iphlpapi.GetNetworkParams(byref(FixedInfo), byref(OutBufLen))

if ERROR_BUFFER_OVERFLOW == ret:
# Not enough space in FixedInfo - there are likely multiple DNS
# servers configured for this system, and the IP_ADDR_STRING
# structures for all but the first will get placed at the end
# of the buffer we pass in. To handle this, first figure out
# how much additional space is needed (the size needed is in
# OutBufLen now.)

AdditionalDataLen = OutBufLen.value - sizeof(FIXED_INFO)

# Make a new ctype struct that accommodates this and try again
NewFixedInfoType = type("FIXED_INFO_PLUS_%d" % AdditionalDataLen, \
(Structure,), \
{"_fields_": FIXED_INFO._fields_ + [("_data", BYTE * AdditionalDataLen)]})

OutBufLen.value = sizeof(NewFixedInfoType)
FixedInfo = NewFixedInfoType()

ret = windll.iphlpapi.GetNetworkParams(byref(FixedInfo), byref(OutBufLen))

if not ret == NO_ERROR:
self.logger.error('Failed calling GetNetworkParams')
return None

Expand Down