Add comment about dual-use socket struct util.sockaddr
This commit is contained in:
@@ -1024,15 +1024,23 @@ else:
|
|||||||
"""
|
"""
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
|
|
||||||
class sockaddr(ctypes.Structure):
|
class sockaddr(ctypes.Structure):
|
||||||
|
"""
|
||||||
|
Shared struct for ipv4 and ipv6.
|
||||||
|
|
||||||
|
https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx
|
||||||
|
|
||||||
|
``__pad1`` always covers the port.
|
||||||
|
|
||||||
|
When being used for ``sockaddr_in6``, ``ipv4_addr`` actually covers ``sin6_flowinfo``, resulting
|
||||||
|
in proper alignment for ``ipv6_addr``.
|
||||||
|
"""
|
||||||
_fields_ = [("sa_family", ctypes.c_short),
|
_fields_ = [("sa_family", ctypes.c_short),
|
||||||
("__pad1", ctypes.c_ushort),
|
("__pad1", ctypes.c_ushort),
|
||||||
("ipv4_addr", ctypes.c_byte * 4),
|
("ipv4_addr", ctypes.c_byte * 4),
|
||||||
("ipv6_addr", ctypes.c_byte * 16),
|
("ipv6_addr", ctypes.c_byte * 16),
|
||||||
("__pad2", ctypes.c_ulong)]
|
("__pad2", ctypes.c_ulong)]
|
||||||
|
|
||||||
|
|
||||||
if hasattr(ctypes, 'windll'):
|
if hasattr(ctypes, 'windll'):
|
||||||
WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
|
WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
|
||||||
WSAAddressToStringA = ctypes.windll.ws2_32.WSAAddressToStringA
|
WSAAddressToStringA = ctypes.windll.ws2_32.WSAAddressToStringA
|
||||||
@@ -1043,7 +1051,6 @@ else:
|
|||||||
WSAStringToAddressA = not_windows
|
WSAStringToAddressA = not_windows
|
||||||
WSAAddressToStringA = not_windows
|
WSAAddressToStringA = not_windows
|
||||||
|
|
||||||
|
|
||||||
def inet_pton(address_family, ip_string):
|
def inet_pton(address_family, ip_string):
|
||||||
if address_family == socket.AF_INET:
|
if address_family == socket.AF_INET:
|
||||||
return socket.inet_aton(ip_string)
|
return socket.inet_aton(ip_string)
|
||||||
@@ -1066,7 +1073,6 @@ else:
|
|||||||
|
|
||||||
raise socket.error('unknown address family')
|
raise socket.error('unknown address family')
|
||||||
|
|
||||||
|
|
||||||
def inet_ntop(address_family, packed_ip):
|
def inet_ntop(address_family, packed_ip):
|
||||||
if address_family == socket.AF_INET:
|
if address_family == socket.AF_INET:
|
||||||
return socket.inet_ntoa(packed_ip)
|
return socket.inet_ntoa(packed_ip)
|
||||||
|
|||||||
Reference in New Issue
Block a user