vinegar.utils.socket

Utilities for dealing with sockets.

vinegar.utils.socket.ipv6_address_unwrap(ipv6_address: str)str

Unwrap an IPv4 address that is encoded in an IPv6 address.

This function works on IPv6 address in the form ::ffff:127.0.0.1 (127.0.0.1 might be any IPv4 address). If such an address is encountered, the actual IPv4 address is extracted and returned.

For any string not matching this pattern, this function simply returns the original string.

Parameters

ipv6_address – string that might represent an IPv4 address wrapped in an IPv6 address (like ::ffff::127.0.0.1).

Returns

the unwrapped IPv4 address or ipv6_address if the string does not match the expected format.

vinegar.utils.socket.socket_address_to_str(socket_address: Tuple)

Return the string representation of a socket address.

Parameters

socket_address – tuple representing a socket address. If the tuple contains at least two elements, the first two elements are treated as a host address and a port number. Otherwise, the only element of the tuple is simply converted to a string.