Python socket.IPPROTO_IPV6 Examples
The following are 30
code examples of socket.IPPROTO_IPV6().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
Example #1
Source File: wsgiserver3.py From SalesforceXyTools with Apache License 2.0 | 7 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See https://bitbucket.org/cherrypy/cherrypy/issue/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #2
Source File: wsgiserver2.py From SalesforceXyTools with Apache License 2.0 | 7 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See https://bitbucket.org/cherrypy/cherrypy/issue/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #3
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 6 votes |
def testSingleCmsgTruncInData(self): # Test truncation of a control message inside its associated # data. The message may be returned with its data truncated, # or not returned at all. self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg( self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) self.assertLessEqual(len(ancdata), 1) if ancdata: cmsg_level, cmsg_type, cmsg_data = ancdata[0] self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) self.assertEqual(cmsg_type, socket.IPV6_HOPLIMIT) self.assertLess(len(cmsg_data), SIZEOF_INT)
Example #4
Source File: relay.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, is_ipv6=False): self.__creator = creator_fd self.__sent = [] if is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.connect(address) return self.fileno
Example #5
Source File: relay.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, redirect_address, listen_is_ipv6=False, redirect_is_ipv6=False): self.__session_fds = {} self.__session_fds_reverse = {} if listen_is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if listen_is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__redirect_is_ipv6 = redirect_is_ipv6 self.__redirect_address = redirect_address self.set_socket(s) self.bind(address) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
Example #6
Source File: relay.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, is_ipv6=False): self.__creator = creator_fd self.__time = time.time() if is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.connect(address) self.register(self.fileno) self.add_evt_read(self.fileno) self.set_timeout(self.fileno, 10) return self.fileno
Example #7
Source File: minusconf.py From scoop with GNU Lesser General Public License v3.0 | 6 votes |
def _init_advertiser(self): sock = _find_sock() sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, struct.pack('@I', 1)) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, struct.pack('@I', 1)) if sock.family == socket.AF_INET6: sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP, struct.pack('@I', 1)) sock.bind(('', self.port)) addrs = _resolve_addrs(self.addresses, None, self.ignore_unavailable, (sock.family,)) for fam,to,orig_fam,orig_addr in addrs: try: _multicast_join_group(sock, orig_fam, orig_addr) except socket.error: if not self.ignore_unavailable: raise self._sock = sock
Example #8
Source File: configure_spilo.py From spilo with Apache License 2.0 | 6 votes |
def get_listen_ip(): """ Get IP to listen on for things that don't natively support detecting IPv4/IPv6 dualstack """ def has_dual_stack(): if hasattr(socket, 'AF_INET6') and hasattr(socket, 'IPPROTO_IPV6') and hasattr(socket, 'IPV6_V6ONLY'): sock = None try: sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False) import urllib3 return urllib3.util.connection.HAS_IPV6 except socket.error as e: logging.debug('Error when working with ipv6 socket: %s', e) finally: if sock: sock.close() return False info = socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE) # in case dual stack is not supported we want IPv4 to be preferred over IPv6 info.sort(key=lambda x: x[0] == socket.AF_INET, reverse=not has_dual_stack()) return info[0][4][0]
Example #9
Source File: wsgiserver2.py From Hatkey with GNU General Public License v3.0 | 6 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See # https://github.com/cherrypy/cherrypy/issues/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #10
Source File: wsgiserver3.py From Hatkey with GNU General Public License v3.0 | 6 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See # https://github.com/cherrypy/cherrypy/issues/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #11
Source File: relay.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, redirect_address, listen_is_ipv6=False, redirect_is_ipv6=False): if listen_is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if listen_is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__redirect_is_ipv6 = redirect_is_ipv6 self.__redirect_address = redirect_address self.set_socket(s) self.bind(address) self.listen(10) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
Example #12
Source File: tunnels.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator, address, crypto, crypto_configs, conn_timeout=800, is_ipv6=False, over_http=False): self.__crypto_configs = crypto_configs self.__crypto = crypto self.__conn_timeout = conn_timeout self.__over_http = over_http if is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.bind(address) self.listen(10) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
Example #13
Source File: WANd_raw.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, auth_id, remote_info, is_ipv6=False): self.__is_ipv6 = is_ipv6 self.__remote_info = remote_info self.__auth_id = auth_id if is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self.set_socket(s) self.bind(address) self.listen(10) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
Example #14
Source File: wol_handler.py From fdslight with GNU General Public License v2.0 | 6 votes |
def init_func(self, creator_fd, address, wol_bind_ip, key, is_ipv6=False): self.__key = key self.__wol_bind_ip = wol_bind_ip if is_ipv6: fa = socket.AF_INET6 else: fa = socket.AF_INET s = socket.socket(fa, socket.SOCK_STREAM) if is_ipv6: s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.bind(address) self.listen(10) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
Example #15
Source File: wsgiserver3.py From opsbro with MIT License | 6 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See # https://bitbucket.org/cherrypy/cherrypy/issue/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #16
Source File: wsgiserver2.py From opsbro with MIT License | 6 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See # https://bitbucket.org/cherrypy/cherrypy/issue/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #17
Source File: test_socket.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _testOddCmsgSize(self): self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) try: nbytes = self.sendmsgToServer( [MSG], [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, array.array("i", [self.traffic_class]).tobytes() + b"\x00"), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]) except OSError as e: self.assertIsInstance(e.errno, int) nbytes = self.sendmsgToServer( [MSG], [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, array.array("i", [self.traffic_class])), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]) self.assertEqual(nbytes, len(MSG)) # Tests for proper handling of truncated ancillary data
Example #18
Source File: test_socket.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def testSingleCmsgTruncInData(self): # Test truncation of a control message inside its associated # data. The message may be returned with its data truncated, # or not returned at all. self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg( self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) self.assertLessEqual(len(ancdata), 1) if ancdata: cmsg_level, cmsg_type, cmsg_data = ancdata[0] self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) self.assertEqual(cmsg_type, socket.IPV6_HOPLIMIT) self.assertLess(len(cmsg_data), SIZEOF_INT)
Example #19
Source File: multicast_checks.py From rift-python with Apache License 2.0 | 6 votes |
def _create_ipv6_sockets(loopback_enabled): # Open a multicast send socket, with IP_MULTICAST_LOOP enabled or disabled as requested. intf_name = find_ethernet_interface() intf_index = socket.if_nametoindex(intf_name) mcast_address = "ff02::abcd:99" port = 30000 group = (mcast_address, port) txsock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) txsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) txsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF, intf_index) if loopback_enabled: txsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP, 1) else: txsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP, 0) txsock.connect(group) # Open a multicast receive socket and join the group rxsock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) req = struct.pack("=16si", socket.inet_pton(socket.AF_INET6, mcast_address), intf_index) if platform.system() == "Darwin": rxsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, req) else: rxsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_ADD_MEMBERSHIP, req) rxsock.bind(("::", port)) return (txsock, rxsock)
Example #20
Source File: __init__.py From nightmare with GNU General Public License v2.0 | 6 votes |
def bind(self, family, type, proto=0): """Create (or recreate) the actual socket object.""" self.socket = socket.socket(family, type, proto) prevent_socket_inheritance(self.socket) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.nodelay and not isinstance(self.bind_addr, str): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.ssl_adapter is not None: self.socket = self.ssl_adapter.bind(self.socket) # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), # activate dual-stack. See http://www.cherrypy.org/ticket/871. if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')): try: self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) except (AttributeError, socket.error): # Apparently, the socket option is not available in # this machine's TCP stack pass self.socket.bind(self.bind_addr)
Example #21
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 6 votes |
def _testOddCmsgSize(self): self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) try: nbytes = self.sendmsgToServer( [MSG], [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, array.array("i", [self.traffic_class]).tobytes() + b"\x00"), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]) except OSError as e: self.assertIsInstance(e.errno, int) nbytes = self.sendmsgToServer( [MSG], [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, array.array("i", [self.traffic_class])), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]) self.assertEqual(nbytes, len(MSG)) # Tests for proper handling of truncated ancillary data
Example #22
Source File: recipe-578504.py From code with MIT License | 6 votes |
def has_dual_stack(sock=None): """Return True if kernel allows creating a socket which is able to listen for both IPv4 and IPv6 connections. If *sock* is provided the check is made against it. """ try: socket.AF_INET6 socket.IPPROTO_IPV6 socket.IPV6_V6ONLY except AttributeError: return False try: if sock is not None: return not sock.getsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY) else: sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) with contextlib.closing(sock): sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False) return True except socket.error: return False
Example #23
Source File: recipe-442490.py From code with MIT License | 5 votes |
def ipv6Multicast(host='::1', maddr=maddr): haddr = socket.getaddrinfo(host, maddr[1], socket.AF_INET6, socket.SOCK_DGRAM)[0][-1] maddr = socket.getaddrinfo(maddr[0], maddr[1], socket.AF_INET6, socket.SOCK_DGRAM)[0][-1] sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if hasattr(socket, "SO_REUSEPORT"): sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP, 1) sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, 5) ifn = haddr[3] or if_nametoindex('lo0') ifn = struct.pack("I", ifn) sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF, ifn) group = socket.inet_pton(socket.AF_INET6, maddr[0]) + ifn sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group) sock.bind(haddr) sock.setblocking(False) return sock, maddr #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #~ Main #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #24
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def checkTrafficClassAndHopLimit(self, ancbufsize, maxhop=255, ignoreflags=0): # Receive traffic class and hop limit into ancbufsize bytes of # ancillary data space. Check that data is MSG, ancillary # data is not truncated (but ignore any flags in ignoreflags), # and traffic class and hop limit are in range (hop limit no # more than maxhop). self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVTCLASS, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG), ancbufsize) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkunset=socket.MSG_CTRUNC, ignore=ignoreflags) self.assertEqual(len(ancdata), 2) ancmap = self.ancillaryMapping(ancdata) tcdata = ancmap[(socket.IPPROTO_IPV6, socket.IPV6_TCLASS)] self.assertEqual(len(tcdata), SIZEOF_INT) a = array.array("i") a.frombytes(tcdata) self.assertGreaterEqual(a[0], 0) self.assertLessEqual(a[0], 255) hldata = ancmap[(socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT)] self.assertEqual(len(hldata), SIZEOF_INT) a = array.array("i") a.frombytes(hldata) self.assertGreaterEqual(a[0], 0) self.assertLessEqual(a[0], maxhop)
Example #25
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def testSecomdCmsgTruncInData(self): # Test truncation of the second of two control messages inside # its associated data. self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVTCLASS, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg( self.serv_sock, len(MSG), socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) cmsg_types = {socket.IPV6_TCLASS, socket.IPV6_HOPLIMIT} cmsg_level, cmsg_type, cmsg_data = ancdata.pop(0) self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) cmsg_types.remove(cmsg_type) self.assertEqual(len(cmsg_data), SIZEOF_INT) a = array.array("i") a.frombytes(cmsg_data) self.assertGreaterEqual(a[0], 0) self.assertLessEqual(a[0], 255) if ancdata: cmsg_level, cmsg_type, cmsg_data = ancdata.pop(0) self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) cmsg_types.remove(cmsg_type) self.assertLess(len(cmsg_data), SIZEOF_INT) self.assertEqual(ancdata, [])
Example #26
Source File: test__socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_getprotobyname(self): '''Tests _socket.getprotobyname''' #IP and CPython proto_map = { "icmp": _socket.IPPROTO_ICMP, "ip": _socket.IPPROTO_IP, "tcp": _socket.IPPROTO_TCP, "udp": _socket.IPPROTO_UDP, } #supported only by IP if is_cli: proto_map.update( {"dstopts": _socket.IPPROTO_DSTOPTS, "none": _socket.IPPROTO_NONE, "raw": _socket.IPPROTO_RAW, "ipv4": _socket.IPPROTO_IPV4, "ipv6": _socket.IPPROTO_IPV6, "esp": _socket.IPPROTO_ESP, "fragment": _socket.IPPROTO_FRAGMENT, "nd": _socket.IPPROTO_ND, "icmpv6": _socket.IPPROTO_ICMPV6, "routing": _socket.IPPROTO_ROUTING, "pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918 "ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918 }) for proto_name, good_val in proto_map.items(): temp_val = _socket.getprotobyname(proto_name) self.assertEqual(temp_val, good_val) #negative cases bad_list = ["", "blah", "i"] for name in bad_list: self.assertRaises(_socket.error, _socket.getprotobyname, name)
Example #27
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def _testSetTrafficClassAndHopLimit(self): self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) self.assertEqual( self.sendmsgToServer([MSG], [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, array.array("i", [self.traffic_class])), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]), len(MSG))
Example #28
Source File: test_socket.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def checkTruncatedSecondHeader(self, ancbufsize, ignoreflags=0): # Receive traffic class and hop limit into ancbufsize bytes of # ancillary data space, which should be large enough to # contain the first item, but too small to contain the header # of the second. Check that data is MSG, MSG_CTRUNC is set # (unless included in ignoreflags), and only one ancillary # data item is returned. self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVTCLASS, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG), ancbufsize) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC, ignore=ignoreflags) self.assertEqual(len(ancdata), 1) cmsg_level, cmsg_type, cmsg_data = ancdata[0] self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) self.assertIn(cmsg_type, {socket.IPV6_TCLASS, socket.IPV6_HOPLIMIT}) self.assertEqual(len(cmsg_data), SIZEOF_INT) a = array.array("i") a.frombytes(cmsg_data) self.assertGreaterEqual(a[0], 0) self.assertLessEqual(a[0], 255) # Try the above test with various buffer sizes.
Example #29
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def checkTruncatedSecondHeader(self, ancbufsize, ignoreflags=0): # Receive traffic class and hop limit into ancbufsize bytes of # ancillary data space, which should be large enough to # contain the first item, but too small to contain the header # of the second. Check that data is MSG, MSG_CTRUNC is set # (unless included in ignoreflags), and only one ancillary # data item is returned. self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVHOPLIMIT, 1) self.serv_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_RECVTCLASS, 1) self.misc_event.set() msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG), ancbufsize) self.assertEqual(msg, MSG) self.checkRecvmsgAddress(addr, self.cli_addr) self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC, ignore=ignoreflags) self.assertEqual(len(ancdata), 1) cmsg_level, cmsg_type, cmsg_data = ancdata[0] self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) self.assertIn(cmsg_type, {socket.IPV6_TCLASS, socket.IPV6_HOPLIMIT}) self.assertEqual(len(cmsg_data), SIZEOF_INT) a = array.array("i") a.frombytes(cmsg_data) self.assertGreaterEqual(a[0], 0) self.assertLessEqual(a[0], 255) # Try the above test with various buffer sizes.
Example #30
Source File: controller.py From TobiiGlassesPyController with GNU General Public License v3.0 | 5 votes |
def __discover_device__(self): if TOBII_DISCOVERY_ALLOWED == False: logging.error("Device discovery is not available due to a missing dependency (netifaces)") exit(1) logging.debug("Looking for a Tobii Pro Glasses 2 device ...") MULTICAST_ADDR = 'ff02::1' PORT = 13006 for i in netifaces.interfaces(): if netifaces.AF_INET6 in netifaces.ifaddresses(i).keys(): if "%" in netifaces.ifaddresses(i)[netifaces.AF_INET6][0]['addr']: if_name = netifaces.ifaddresses(i)[netifaces.AF_INET6][0]['addr'].split("%")[1] if_idx = socket.getaddrinfo(MULTICAST_ADDR + "%" + if_name, PORT, socket.AF_INET6, socket.SOCK_DGRAM)[0][4][3] s6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) s6.settimeout(30.0) s6.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF, if_idx) s6.bind(('::', PORT)) PORT_OUT = PORT if sys.platform == 'win32' or sys.platform == 'darwin' else PORT + 1 try: discover_json = '{"type":"discover"}' s6.sendto(discover_json.encode('utf-8'), (MULTICAST_ADDR, PORT_OUT)) logging.debug("Discover request sent to %s on interface %s " % ( str((MULTICAST_ADDR, PORT_OUT)),if_name) ) logging.debug("Waiting for a reponse from the device ...") data, address = s6.recvfrom(1024) jdata = json.loads(data.decode('utf-8')) logging.debug("From: " + address[0] + " " + str(data)) logging.debug("Tobii Pro Glasses found with address: [%s]" % address[0]) addr = address[0] if sys.version_info.major == 3 and sys.version_info.minor >= 8: addr = address[0] + '%' + if_name return (jdata, addr) except: logging.debug("No device found on interface %s" % if_name) logging.debug("The discovery process did not find any device!") return (None, None)