Python errno.EAFNOSUPPORT Examples
The following are 23
code examples of errno.EAFNOSUPPORT().
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
errno
, or try the search function
.
Example #1
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def inet_pton(family, ip_string): if family == AF_INET: if not is_ipv4_address(ip_string): raise error("illegal IP address string passed to inet_pton") elif family == AF_INET6: if not is_ipv6_address(ip_string): raise error("illegal IP address string passed to inet_pton") else: raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol") ia = java.net.InetAddress.getByName(ip_string) bytes = [] for byte in ia.getAddress(): if byte < 0: bytes.append(byte+256) else: bytes.append(byte) return "".join([chr(byte) for byte in bytes])
Example #2
Source File: stream.py From ryu with Apache License 2.0 | 6 votes |
def open(name, dscp=DSCP_DEFAULT): """Attempts to connect a stream to a remote peer. 'name' is a connection name in the form "TYPE:ARGS", where TYPE is an active stream class's name and ARGS are stream class-specific. Currently the only supported TYPEs are "unix" and "tcp". Returns (error, stream): on success 'error' is 0 and 'stream' is the new Stream, on failure 'error' is a positive errno value and 'stream' is None. Never returns errno.EAGAIN or errno.EINPROGRESS. Instead, returns 0 and a new Stream. The connect() method can be used to check for successful connection completion.""" cls = Stream._find_method(name) if not cls: return errno.EAFNOSUPPORT, None suffix = name.split(":", 1)[1] error, sock = cls._open(suffix, dscp) if error: return error, None else: status = ovs.socket_util.check_connection_completion(sock) return 0, Stream(sock, name, status)
Example #3
Source File: stream.py From ryu with Apache License 2.0 | 6 votes |
def open(name): """Attempts to start listening for remote stream connections. 'name' is a connection name in the form "TYPE:ARGS", where TYPE is an passive stream class's name and ARGS are stream class-specific. Currently the only supported TYPE is "punix". Returns (error, pstream): on success 'error' is 0 and 'pstream' is the new PassiveStream, on failure 'error' is a positive errno value and 'pstream' is None.""" if not PassiveStream.is_valid_name(name): return errno.EAFNOSUPPORT, None bind_path = name[6:] error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, True, bind_path, None) if error: return error, None try: sock.listen(10) except socket.error, e: vlog.err("%s: listen: %s" % (name, os.strerror(e.error))) sock.close() return e.error, None
Example #4
Source File: utils.py From masakari with Apache License 2.0 | 6 votes |
def is_ipv6_supported(): has_ipv6_support = socket.has_ipv6 try: s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.close() except socket.error as e: if e.errno == errno.EAFNOSUPPORT: has_ipv6_support = False else: raise # check if there is at least one interface with ipv6 if has_ipv6_support and sys.platform.startswith('linux'): try: with open('/proc/net/if_inet6') as f: if not f.read(): has_ipv6_support = False except IOError: has_ipv6_support = False return has_ipv6_support
Example #5
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def inet_pton(family, ip_string): if family == AF_INET: if not is_ipv4_address(ip_string): raise error("illegal IP address string passed to inet_pton") elif family == AF_INET6: if not is_ipv6_address(ip_string): raise error("illegal IP address string passed to inet_pton") else: raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol") ia = java.net.InetAddress.getByName(ip_string) bytes = [] for byte in ia.getAddress(): if byte < 0: bytes.append(byte+256) else: bytes.append(byte) return "".join([chr(byte) for byte in bytes])
Example #6
Source File: _remote_socket.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _create=False): if family not in (AF_INET, AF_INET6): raise error(errno.EAFNOSUPPORT, os.strerror(errno.EAFNOSUPPORT)) if type not in (SOCK_STREAM, SOCK_DGRAM): raise error(errno.EPROTONOSUPPORT, os.strerror(errno.EPROTONOSUPPORT)) if proto: if ((proto not in (IPPROTO_TCP, IPPROTO_UDP)) or (proto == IPPROTO_TCP and type != SOCK_STREAM) or (proto == IPPROTO_UDP and type != SOCK_DGRAM)): raise error(errno.EPROTONOSUPPORT, os.strerror(errno.EPROTONOSUPPORT)) self.family = family self.type = type self.proto = proto self._created = False self._fileno = None self._serialized = False self.settimeout(getdefaulttimeout()) self._Clear() if _create: self._CreateSocket()
Example #7
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def inet_pton(family, ip_string): if family == AF_INET: if not is_ipv4_address(ip_string): raise error("illegal IP address string passed to inet_pton") elif family == AF_INET6: if not is_ipv6_address(ip_string): raise error("illegal IP address string passed to inet_pton") else: raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol") ia = java.net.InetAddress.getByName(ip_string) bytes = [] for byte in ia.getAddress(): if byte < 0: bytes.append(byte+256) else: bytes.append(byte) return "".join([chr(byte) for byte in bytes])
Example #8
Source File: socket.py From medicare-demo with Apache License 2.0 | 6 votes |
def inet_pton(family, ip_string): try: if family == AF_INET: if not is_ipv4_address(ip_string): raise error("illegal IP address string passed to inet_pton") elif family == AF_INET6: if not is_ipv6_address(ip_string): raise error("illegal IP address string passed to inet_pton") else: raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol") ia = java.net.InetAddress.getByName(ip_string) bytes = [] for byte in ia.getAddress(): if byte < 0: bytes.append(byte+256) else: bytes.append(byte) return "".join([chr(byte) for byte in bytes]) except java.lang.Exception, jlx: raise _map_exception(jlx)
Example #9
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def inet_pton(family, ip_string): if family == AF_INET: if not is_ipv4_address(ip_string): raise error("illegal IP address string passed to inet_pton") elif family == AF_INET6: if not is_ipv6_address(ip_string): raise error("illegal IP address string passed to inet_pton") else: raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol") ia = java.net.InetAddress.getByName(ip_string) bytes = [] for byte in ia.getAddress(): if byte < 0: bytes.append(byte+256) else: bytes.append(byte) return "".join([chr(byte) for byte in bytes])
Example #10
Source File: test_socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_inet_pton_exceptions(self): if not hasattr(socket, 'inet_pton'): return # No inet_pton() on this platform try: socket.inet_pton(socket.AF_UNSPEC, "doesntmatter") except socket.error, se: self.failUnlessEqual(se[0], errno.EAFNOSUPPORT)
Example #11
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def java_net_socketexception_handler(exc): if exc.message.startswith("Address family not supported by protocol family"): return _add_exception_attrs( error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6_address_support')) if exc.message.startswith('Address already in use'): return error(errno.EADDRINUSE, 'Address already in use') return _unmapped_exception(exc)
Example #12
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def java_net_socketexception_handler(exc): if exc.message.startswith("Address family not supported by protocol family"): return _add_exception_attrs( error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6_address_support')) if exc.message.startswith('Address already in use'): return error(errno.EADDRINUSE, 'Address already in use') return _unmapped_exception(exc)
Example #13
Source File: test_socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_inet_pton_exceptions(self): if not hasattr(socket, 'inet_pton'): return # No inet_pton() on this platform try: socket.inet_pton(socket.AF_UNSPEC, "doesntmatter") except socket.error, se: self.failUnlessEqual(se[0], errno.EAFNOSUPPORT)
Example #14
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def java_net_socketexception_handler(exc): if exc.message.startswith("Address family not supported by protocol family"): return _add_exception_attrs( error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6_address_support')) if exc.message.startswith('Address already in use'): return error(errno.EADDRINUSE, 'Address already in use') return _unmapped_exception(exc)
Example #15
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def java_net_socketexception_handler(exc): if exc.message.startswith("Address family not supported by protocol family"): return _add_exception_attrs( error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6_address_support')) if exc.message.startswith('Address already in use'): return error(errno.EADDRINUSE, 'Address already in use') return _unmapped_exception(exc)
Example #16
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_inet_pton_exceptions(self): if not hasattr(socket, 'inet_pton'): return # No inet_pton() on this platform try: socket.inet_pton(socket.AF_UNSPEC, "doesntmatter") except socket.error, se: self.failUnlessEqual(se[0], errno.EAFNOSUPPORT)
Example #17
Source File: socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def java_net_socketexception_handler(exc): if exc.message.startswith("Address family not supported by protocol family"): return error(errno.EAFNOSUPPORT, 'Address family not supported by protocol family: See http://wiki.python.org/jython/NewSocketModule#IPV6addresssupport') return _unmapped_exception(exc)
Example #18
Source File: error.py From libnl with GNU Lesser General Public License v2.1 | 5 votes |
def nl_syserr2nlerr(error_): """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84.""" error_ = abs(error_) legend = { errno.EBADF: libnl.errno_.NLE_BAD_SOCK, errno.EADDRINUSE: libnl.errno_.NLE_EXIST, errno.EEXIST: libnl.errno_.NLE_EXIST, errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR, errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND, errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND, errno.EINTR: libnl.errno_.NLE_INTR, errno.EAGAIN: libnl.errno_.NLE_AGAIN, errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK, errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL, errno.EFAULT: libnl.errno_.NLE_INVAL, errno.EACCES: libnl.errno_.NLE_NOACCESS, errno.EINVAL: libnl.errno_.NLE_INVAL, errno.ENOBUFS: libnl.errno_.NLE_NOMEM, errno.ENOMEM: libnl.errno_.NLE_NOMEM, errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT, errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH, errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP, errno.EPERM: libnl.errno_.NLE_PERM, errno.EBUSY: libnl.errno_.NLE_BUSY, errno.ERANGE: libnl.errno_.NLE_RANGE, errno.ENODEV: libnl.errno_.NLE_NODEV, } return int(legend.get(error_, libnl.errno_.NLE_FAILURE))
Example #19
Source File: program.py From tensorboard with Apache License 2.0 | 5 votes |
def server_bind(self): """Override to enable IPV4 mapping for IPV6 sockets when desired. The main use case for this is so that when no host is specified, TensorBoard can listen on all interfaces for both IPv4 and IPv6 connections, rather than having to choose v4 or v6 and hope the browser didn't choose the other one. """ socket_is_v6 = ( hasattr(socket, "AF_INET6") and self.socket.family == socket.AF_INET6 ) has_v6only_option = hasattr(socket, "IPPROTO_IPV6") and hasattr( socket, "IPV6_V6ONLY" ) if self._auto_wildcard and socket_is_v6 and has_v6only_option: try: self.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0 ) except socket.error as e: # Log a warning on failure to dual-bind, except for EAFNOSUPPORT # since that's expected if IPv4 isn't supported at all (IPv6-only). if ( hasattr(errno, "EAFNOSUPPORT") and e.errno != errno.EAFNOSUPPORT ): logger.warning( "Failed to dual-bind to IPv4 wildcard: %s", str(e) ) super(WerkzeugServer, self).server_bind()
Example #20
Source File: _remote_socket_addr.py From python-compat-runtime with Apache License 2.0 | 4 votes |
def inet_pton(af, ip): """inet_pton(af, ip) -> packed IP address string Convert an IP address from string format to a packed string suitable for use with low-level network functions. """ if not isinstance(af, (int, long)): raise TypeError('an integer is required') if not isinstance(ip, basestring): raise TypeError('inet_pton() argument 2 must be string, not %s' % _TypeName(ip)) if af == AF_INET: parts = ip.split('.') if len(parts) != 4: raise error('illegal IP address string passed to inet_pton') ret = 0 bits = 32 for part in parts: if not re.match(r'^(0|[1-9]\d*)$', part) or int(part) > 0xff: raise error('illegal IP address string passed to inet_pton') bits -= 8 ret |= ((int(part) & 0xff) << bits) return struct.pack('!L', ret) elif af == AF_INET6: parts = ip.split(':') if '.' in parts[-1]: ipv4_shorts = struct.unpack('!2H', inet_pton(AF_INET, parts[-1])) parts[-1:] = [hex(n)[2:] for n in ipv4_shorts] if '' in parts: if len(parts) == 1 or len(parts) >= 8: raise error('illegal IP address string passed to inet_pton') idx = parts.index('') count = parts.count('') pad = ['0']*(count+(8-len(parts))) if count == len(parts) == 3: parts = pad elif count == 2 and parts[0:2] == ['', '']: parts[0:2] = pad elif count == 2 and parts[-2:] == ['', '']: parts[-2:] = pad elif count == 1: parts[idx:idx+1] = pad else: raise error('illegal IP address string passed to inet_pton') if (len(parts) != 8 or [x for x in parts if not re.match(r'^[0-9A-Fa-f]{1,4}$', x)]): raise error('illegal IP address string passed to inet_pton') return struct.pack('!8H', *[int(x, 16) for x in parts]) else: raise error(errno.EAFNOSUPPORT, os.strerror(errno.EAFNOSUPPORT))
Example #21
Source File: program.py From tensorboard with Apache License 2.0 | 4 votes |
def __init__(self, wsgi_app, flags): self._flags = flags host = flags.host port = flags.port self._auto_wildcard = flags.bind_all if self._auto_wildcard: # Serve on all interfaces, and attempt to serve both IPv4 and IPv6 # traffic through one socket. host = self._get_wildcard_address(port) elif host is None: host = "localhost" self._host = host self._url = None # Will be set by get_url() below self._fix_werkzeug_logging() try: super(WerkzeugServer, self).__init__(host, port, wsgi_app) except socket.error as e: if hasattr(errno, "EACCES") and e.errno == errno.EACCES: raise TensorBoardServerException( "TensorBoard must be run as superuser to bind to port %d" % port ) elif hasattr(errno, "EADDRINUSE") and e.errno == errno.EADDRINUSE: if port == 0: raise TensorBoardServerException( "TensorBoard unable to find any open port" ) else: raise TensorBoardPortInUseError( "TensorBoard could not bind to port %d, it was already in use" % port ) elif ( hasattr(errno, "EADDRNOTAVAIL") and e.errno == errno.EADDRNOTAVAIL ): raise TensorBoardServerException( "TensorBoard could not bind to unavailable address %s" % host ) elif ( hasattr(errno, "EAFNOSUPPORT") and e.errno == errno.EAFNOSUPPORT ): raise TensorBoardServerException( "Tensorboard could not bind to unsupported address family %s" % host ) # Raise the raw exception if it wasn't identifiable as a user error. raise
Example #22
Source File: netutil.py From viewfinder with Apache License 2.0 | 4 votes |
def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None): """Creates listening sockets bound to the given port and address. Returns a list of socket objects (multiple sockets are returned if the given address maps to multiple IP addresses, which is most common for mixed IPv4 and IPv6 use). Address may be either an IP address or hostname. If it's a hostname, the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either `socket.AF_INET` or `socket.AF_INET6` to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available. The ``backlog`` argument has the same meaning as for `socket.listen() <socket.socket.listen>`. ``flags`` is a bitmask of AI_* flags to `~socket.getaddrinfo`, like ``socket.AI_PASSIVE | socket.AI_NUMERICHOST``. """ sockets = [] if address == "": address = None if not socket.has_ipv6 and family == socket.AF_UNSPEC: # Python can be compiled with --disable-ipv6, which causes # operations on AF_INET6 sockets to fail, but does not # automatically exclude those results from getaddrinfo # results. # http://bugs.python.org/issue16208 family = socket.AF_INET if flags is None: flags = socket.AI_PASSIVE for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_STREAM, 0, flags)): af, socktype, proto, canonname, sockaddr = res try: sock = socket.socket(af, socktype, proto) except socket.error as e: if e.args[0] == errno.EAFNOSUPPORT: continue raise set_close_exec(sock.fileno()) if os.name != 'nt': sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if af == socket.AF_INET6: # On linux, ipv6 sockets accept ipv4 too by default, # but this makes it impossible to bind to both # 0.0.0.0 in ipv4 and :: in ipv6. On other systems, # separate sockets *must* be used to listen for both ipv4 # and ipv6. For consistency, always disable ipv4 on our # ipv6 sockets and use a separate ipv4 socket when needed. # # Python 2.x on windows doesn't have IPPROTO_IPV6. if hasattr(socket, "IPPROTO_IPV6"): sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) sock.setblocking(0) sock.bind(sockaddr) sock.listen(backlog) sockets.append(sock) return sockets
Example #23
Source File: netutil.py From viewfinder with Apache License 2.0 | 4 votes |
def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None): """Creates listening sockets bound to the given port and address. Returns a list of socket objects (multiple sockets are returned if the given address maps to multiple IP addresses, which is most common for mixed IPv4 and IPv6 use). Address may be either an IP address or hostname. If it's a hostname, the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either `socket.AF_INET` or `socket.AF_INET6` to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available. The ``backlog`` argument has the same meaning as for `socket.listen() <socket.socket.listen>`. ``flags`` is a bitmask of AI_* flags to `~socket.getaddrinfo`, like ``socket.AI_PASSIVE | socket.AI_NUMERICHOST``. """ sockets = [] if address == "": address = None if not socket.has_ipv6 and family == socket.AF_UNSPEC: # Python can be compiled with --disable-ipv6, which causes # operations on AF_INET6 sockets to fail, but does not # automatically exclude those results from getaddrinfo # results. # http://bugs.python.org/issue16208 family = socket.AF_INET if flags is None: flags = socket.AI_PASSIVE for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_STREAM, 0, flags)): af, socktype, proto, canonname, sockaddr = res try: sock = socket.socket(af, socktype, proto) except socket.error as e: if e.args[0] == errno.EAFNOSUPPORT: continue raise set_close_exec(sock.fileno()) if os.name != 'nt': sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if af == socket.AF_INET6: # On linux, ipv6 sockets accept ipv4 too by default, # but this makes it impossible to bind to both # 0.0.0.0 in ipv4 and :: in ipv6. On other systems, # separate sockets *must* be used to listen for both ipv4 # and ipv6. For consistency, always disable ipv4 on our # ipv6 sockets and use a separate ipv4 socket when needed. # # Python 2.x on windows doesn't have IPPROTO_IPV6. if hasattr(socket, "IPPROTO_IPV6"): sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) sock.setblocking(0) sock.bind(sockaddr) sock.listen(backlog) sockets.append(sock) return sockets