Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/netutil.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Linux network utilities. | """Linux network utilities. | ||||
Roughly based on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code/ by Ricardo Pascal | Roughly based on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code/ by Ricardo Pascal | ||||
""" | """ | ||||
import array | import array | ||||
from binascii import unhexlify | |||||
from errno import ENOENT, EINVAL | |||||
import os | import os | ||||
import socket | import socket | ||||
import struct | import struct | ||||
import sys | import sys | ||||
from binascii import unhexlify | |||||
from errno import EINVAL, ENOENT | |||||
# STATE_ESTABLISHED = '01' | # STATE_ESTABLISHED = '01' | ||||
# STATE_SYN_SENT = '02' | # STATE_SYN_SENT = '02' | ||||
# STATE_SYN_RECV = '03' | # STATE_SYN_RECV = '03' | ||||
# STATE_FIN_WAIT1 = '04' | # STATE_FIN_WAIT1 = '04' | ||||
# STATE_FIN_WAIT2 = '05' | # STATE_FIN_WAIT2 = '05' | ||||
# STATE_TIME_WAIT = '06' | # STATE_TIME_WAIT = '06' | ||||
# STATE_CLOSE = '07' | # STATE_CLOSE = '07' | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | def addr_to_hex(addr): | ||||
return bytearray(addr).hex() | return bytearray(addr).hex() | ||||
def test_ipv6_local(): | def test_ipv6_local(): | ||||
''' | ''' | ||||
Check for (local) IPv6 support. | Check for (local) IPv6 support. | ||||
''' | ''' | ||||
import socket | import socket | ||||
# By using SOCK_DGRAM this will not actually make a connection, but it will | # By using SOCK_DGRAM this will not actually make a connection, but it will | ||||
# fail if there is no route to IPv6 localhost. | # fail if there is no route to IPv6 localhost. | ||||
have_ipv6 = True | have_ipv6 = True | ||||
try: | try: | ||||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) | s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) | ||||
s.connect(('::1', 0)) | s.connect(('::1', 0)) | ||||
except socket.error: | except socket.error: | ||||
have_ipv6 = False | have_ipv6 = False | ||||
return have_ipv6 | return have_ipv6 |