~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to qa/rpc-tests/test_framework/netutil.py

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2
2
 
# Copyright (c) 2014-2015 The Bitcoin Core developers
 
1
#!/usr/bin/env python3
 
2
# Copyright (c) 2014-2016 The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
 
6
6
# Linux network utilities
 
7
 
7
8
import sys
8
9
import socket
9
10
import fcntl
10
11
import struct
11
12
import array
12
13
import os
13
 
import binascii
 
14
from binascii import unhexlify, hexlify
14
15
 
15
16
# Roughly based on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code/ by Ricardo Pascal
16
17
STATE_ESTABLISHED = '01'
43
44
def _convert_ip_port(array):
44
45
    host,port = array.split(':')
45
46
    # convert host from mangled-per-four-bytes form as used by kernel
46
 
    host = binascii.unhexlify(host)
 
47
    host = unhexlify(host)
47
48
    host_out = ''
48
 
    for x in range(0, len(host)/4):
 
49
    for x in range(0, len(host) // 4):
49
50
        (val,) = struct.unpack('=I', host[x*4:(x+1)*4])
50
51
        host_out += '%08x' % val
51
52
 
94
95
    max_possible = 8 # initial value
95
96
    while True:
96
97
        bytes = max_possible * struct_size
97
 
        names = array.array('B', '\0' * bytes)
 
98
        names = array.array('B', b'\0' * bytes)
98
99
        outbytes = struct.unpack('iL', fcntl.ioctl(
99
100
            s.fileno(),
100
101
            0x8912,  # SIOCGIFCONF
105
106
        else:
106
107
            break
107
108
    namestr = names.tostring()
108
 
    return [(namestr[i:i+16].split('\0', 1)[0],
 
109
    return [(namestr[i:i+16].split(b'\0', 1)[0],
109
110
             socket.inet_ntoa(namestr[i+20:i+24]))
110
111
            for i in range(0, outbytes, struct_size)]
111
112
 
136
137
        addr = sub[0] + ([0] * nullbytes) + sub[1]
137
138
    else:
138
139
        raise ValueError('Could not parse address %s' % addr)
139
 
    return binascii.hexlify(bytearray(addr))
 
140
    return hexlify(bytearray(addr)).decode('ascii')
 
141
 
 
142
def test_ipv6_local():
 
143
    '''
 
144
    Check for (local) IPv6 support.
 
145
    '''
 
146
    import socket
 
147
    # By using SOCK_DGRAM this will not actually make a connection, but it will
 
148
    # fail if there is no route to IPv6 localhost.
 
149
    have_ipv6 = True
 
150
    try:
 
151
        s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
 
152
        s.connect(('::1', 0))
 
153
    except socket.error:
 
154
        have_ipv6 = False
 
155
    return have_ipv6