Sharpened exception handling for IPv6 support.
This commit is contained in:
parent
bf8177c148
commit
ce921bf199
|
@ -107,7 +107,8 @@ class AddressMessageParser:
|
||||||
return port
|
return port
|
||||||
|
|
||||||
# Consume one entry in the addr_list.
|
# Consume one entry in the addr_list.
|
||||||
# Returns (timestamp, stream, services, host, port) tuple on success.
|
# Returns (timestamp, stream, services, host, port) tuple on success,
|
||||||
|
# and None on failure.
|
||||||
def __consumeAddress(self):
|
def __consumeAddress(self):
|
||||||
past_position = self.position
|
past_position = self.position
|
||||||
try:
|
try:
|
||||||
|
@ -116,9 +117,13 @@ class AddressMessageParser:
|
||||||
services = self.__consumeServices()
|
services = self.__consumeServices()
|
||||||
host = self.__consumeHost()
|
host = self.__consumeHost()
|
||||||
port = self.__consumePort()
|
port = self.__consumePort()
|
||||||
|
addressDetails = (timestamp, stream, services, host, port)
|
||||||
|
except Exception as err:
|
||||||
|
logger.warning('Could not read address in addr message. Err: %s' % (err))
|
||||||
|
addressDetails = None
|
||||||
finally:
|
finally:
|
||||||
if self.remoteProtocolVersion == 1:
|
if self.remoteProtocolVersion == 1:
|
||||||
self.position = past_position + 34
|
self.position = past_position + 34
|
||||||
elif self.remoteProtocolVersion == 2:
|
elif self.remoteProtocolVersion == 2:
|
||||||
self.position = past_position + 38
|
self.position = past_position + 38
|
||||||
return (timestamp, stream, services, host, port)
|
return addressDetails
|
||||||
|
|
|
@ -77,6 +77,9 @@ def isInSqlInventory(hash):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class IPv6NotSupportedException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def packNetworkAddress(address):
|
def packNetworkAddress(address):
|
||||||
# For windows, we need to avoid socket.inet_pton()
|
# For windows, we need to avoid socket.inet_pton()
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
@ -89,7 +92,7 @@ def packNetworkAddress(address):
|
||||||
# Chop off the IPv4-mapped IPv6 prefix from the standard-form address.
|
# Chop off the IPv4-mapped IPv6 prefix from the standard-form address.
|
||||||
address = address[7:]
|
address = address[7:]
|
||||||
else:
|
else:
|
||||||
raise Exception('IPv6 not supported by packNetworkAddress on Windows.')
|
raise IPv6NotSupportedException('IPv6 not supported by packNetworkAddress on Windows.')
|
||||||
|
|
||||||
# Pack the standard-form IPv4 address and add prefix to make packed IPv4-mapped IPv6.
|
# Pack the standard-form IPv4 address and add prefix to make packed IPv4-mapped IPv6.
|
||||||
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
|
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
|
||||||
|
|
Reference in New Issue
Block a user