def METHOD_NAME(u):
    # type: (Union[IP, IPv6]) -> bytes
    if isinstance(u, IP):
        return inet_pton(socket.AF_INET, u.src)
    elif isinstance(u, IPv6):
        return inet_pton(socket.AF_INET6, u.src)
    else:
        raise Exception("Neither IP nor IPv6 found on packet")