Opening a file with 'rw' in Python3 returns an error, moreover using 'rw' in Python2 is wrong too since it opens the file using O_RDONLY and not by using O_RDWR.
This commit fixes it by using the low-level os.open function with O_RDWR as suggested by the Linux kernel (tuntap.txt) documentation. This commit fixes also some usual bytes vs string incompatibilities. Tested on Python 2.7.15 and Python 3.6.5 Signed-off-by: Timothy Redaelli <tredae...@redhat.com> --- utilities/ovs-tcpdump.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in index 91fa14e5a..17b5d48f1 100755 --- a/utilities/ovs-tcpdump.in +++ b/utilities/ovs-tcpdump.in @@ -62,8 +62,8 @@ def _install_tap_linux(tap_name, mtu_value=None): TUNSETIFF = 0x400454CA # This is derived by printf() of TUNSETIFF TUNSETOWNER = TUNSETIFF + 2 - tapdev_fd = open('/dev/net/tun', 'rw') - ifr = struct.pack('16sH', tap_name, IFF_TAP | IFF_NO_PI) + tapdev_fd = os.open('/dev/net/tun', os.O_RDWR) + ifr = struct.pack('16sH', tap_name.encode('utf8'), IFF_TAP | IFF_NO_PI) fcntl.ioctl(tapdev_fd, TUNSETIFF, ifr) fcntl.ioctl(tapdev_fd, TUNSETOWNER, os.getegid()) @@ -457,10 +457,10 @@ def main(): pipes = _doexec(*([dump_cmd, '-i', mirror_interface] + tcpdargs)) try: while pipes.poll() is None: - data = pipes.stdout.readline().strip('\n') + data = pipes.stdout.readline().strip(b'\n') if len(data) == 0: raise KeyboardInterrupt - print(data) + print(data.decode('utf-8')) raise KeyboardInterrupt except KeyboardInterrupt: if pipes.poll() is None: -- 2.17.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev