• Home
  • Raw
  • Download

Lines Matching +full:ipv4 +full:- +full:single +full:- +full:target

1 :mod:`socket` --- Low-level networking interface
5 :synopsis: Low-level networking interface.
9 --------------
22 call and library interface for sockets to Python's object-oriented style: the
24 the various socket system calls. Parameter types are somewhat higher-level than
40 ---------------
49 - The address of an :const:`AF_UNIX` socket bound to a file system node
52 Linux's abstract namespace is returned as a :term:`bytes-like object` with
56 bytes-like object can be used for either type of address when
60 Previously, :const:`AF_UNIX` socket paths were assumed to use UTF-8
64 Writable :term:`bytes-like object` is now accepted.
68 - A pair ``(host, port)`` is used for the :const:`AF_INET` address family,
70 notation like ``'daring.cwi.nl'`` or an IPv4 address like ``'100.50.200.5'``,
73 - For IPv4 addresses, two special forms are accepted instead of a host
80 - For :const:`AF_INET6` address family, a four-tuple ``(host, port, flowinfo,
92 - :const:`AF_NETLINK` sockets are represented as pairs ``(pid, groups)``.
94 - Linux-only support for TIPC is available using the :const:`AF_TIPC`
95 address family. TIPC is an open, non-IP based networked protocol designed
100 - *addr_type* is one of :const:`TIPC_ADDR_NAMESEQ`, :const:`TIPC_ADDR_NAME`,
102 - *scope* is one of :const:`TIPC_ZONE_SCOPE`, :const:`TIPC_CLUSTER_SCOPE`, and
104 - If *addr_type* is :const:`TIPC_ADDR_NAME`, then *v1* is the server type, *v2* is
113 - A tuple ``(interface, )`` is used for the :const:`AF_CAN` address family,
118 - :const:`CAN_ISOTP` protocol require a tuple ``(interface, rx_addr, tx_addr)``
121 - :const:`CAN_J1939` protocol require a tuple ``(interface, name, pgn, addr)``
122 where additional parameters are 64-bit unsigned integer representing the
123 ECU name, a 32-bit unsigned integer representing the Parameter Group Number
124 (PGN), and an 8-bit integer representing the address.
126 - A string or a tuple ``(id, unit)`` is used for the :const:`SYSPROTO_CONTROL`
128 kernel control using a dynamically-assigned ID. The tuple can be used if ID
134 - :const:`AF_BLUETOOTH` supports the following protocols and address
137 - :const:`BTPROTO_L2CAP` accepts ``(bdaddr, psm)`` where ``bdaddr`` is
140 - :const:`BTPROTO_RFCOMM` accepts ``(bdaddr, channel)`` where ``bdaddr``
143 - :const:`BTPROTO_HCI` accepts ``(device_id,)`` where ``device_id`` is
151 - :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is a
156 - :const:`AF_ALG` is a Linux-only socket based interface to Kernel
160 - *type* is the algorithm type as string, e.g. ``aead``, ``hash``,
163 - *name* is the algorithm name and operation mode as string, e.g.
166 - *feat* and *mask* are unsigned 32bit integers.
172 - :const:`AF_VSOCK` allows communication between virtual machines and
180 - :const:`AF_PACKET` is a low-level interface directly to network devices.
184 - *ifname* - String specifying the device name.
185 - *proto* - An in network-byte-order integer specifying the Ethernet
187 - *pkttype* - Optional integer specifying the packet type:
189 - ``PACKET_HOST`` (the default) - Packet addressed to the local host.
190 - ``PACKET_BROADCAST`` - Physical-layer broadcast packet.
191 - ``PACKET_MULTIHOST`` - Packet sent to a physical-layer multicast address.
192 - ``PACKET_OTHERHOST`` - Packet to some other host that has been caught by
194 - ``PACKET_OUTGOING`` - Packet originating from the local host that is
196 - *hatype* - Optional integer specifying the ARP hardware address type.
197 - *addr* - Optional bytes-like object specifying the hardware physical
200 - :const:`AF_QIPCRTR` is a Linux-only socket based interface for communicating
201 with services running on co-processors in Qualcomm platforms. The address
203 are non-negative integers.
207 - :const:`IPPROTO_UDPLITE` is a variant of UDP which allows you to specify
217 ``socket(AF_INET, SOCK_DGRAM, IPPROTO_UDPLITE)`` for IPv4 or
220 .. availability:: Linux >= 2.6.20, FreeBSD >= 10.1-RELEASE
224 If you use a hostname in the *host* portion of IPv4/v6 socket address, the
227 differently into an actual IPv4/v6 address, depending on the results from DNS
232 and out-of-memory conditions can be raised; starting from Python 3.3, errors
236 Non-blocking mode is supported through :meth:`~socket.setblocking`. A
242 ---------------
261 address-related errors, i.e. for functions that use *h_errno* in the POSIX
274 address-related errors by :func:`getaddrinfo` and :func:`getnameinfo`.
368 On Windows, ``TCP_FASTOPEN``, ``TCP_KEEPCNT`` appear if run-time Windows
374 On Windows, ``TCP_KEEPIDLE``, ``TCP_KEEPINTVL`` appear if run-time Windows
428 CAN_ISOTP, in the CAN protocol family, is the ISO-TP (ISO 15765-2) protocol.
429 ISO-TP constants, documented in the Linux documentation.
548 The following functions all create :ref:`socket objects <socket-objects>`.
564 auto-detected from the specified file descriptor. Auto-detection can be
572 The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
574 .. audit-event:: socket.__new__ self,family,type,protocol socket.socket
584 The returned socket is now non-inheritable.
601 will still create a non-blocking socket on OSes that support
615 The newly created sockets are :ref:`non-inheritable <fd_inheritance>`.
622 The returned sockets are now non-inheritable.
630 Connect to a TCP service listening on the Internet *address* (a 2-tuple
631 ``(host, port)``), and return the socket object. This is a higher-level
632 function than :meth:`socket.connect`: if *host* is a non-numeric hostname,
636 compatible to both IPv4 and IPv6.
643 If supplied, *source_address* must be a 2-tuple ``(host, port)`` for the
652 Convenience function which creates a TCP socket bound to *address* (a 2-tuple
661 be able to accept both IPv4 and IPv6 connections, else it will raise
665 :meth:`socket.getpeername` when an IPv4 connection occurs will be an IPv6
666 address represented as an IPv4-mapped IPv6 address.
691 handle both IPv4 and IPv6 connections.
700 above. The file descriptor should refer to a socket, but this is not checked ---
706 The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
709 The returned socket is now non-inheritable.
731 The :mod:`socket` module also offers various network-related services:
744 Translate the *host*/*port* argument into a sequence of 5-tuples that contain
746 *host* is a domain name, a string representation of an IPv4/v6 address
759 The function returns a list of 5-tuples with the following structure:
768 format depends on the returned *family* (a ``(address, port)`` 2-tuple for
769 :const:`AF_INET`, a ``(address, port, flowinfo, scope_id)`` 4-tuple for
773 .. audit-event:: socket.getaddrinfo host,port,family,type,protocol socket.getaddrinfo
804 Translate a host name to IPv4 address format. The IPv4 address is returned as a
805 string, such as ``'100.50.200.5'``. If the host name is an IPv4 address itself
808 :func:`getaddrinfo` should be used instead for IPv4/v6 dual stack support.
810 .. audit-event:: socket.gethostbyname hostname socket.gethostbyname
815 Translate a host name to IPv4 address format, extended interface. Return a
819 a list of IPv4 addresses for the same interface on the same host (often but not
820 always a single address). :func:`gethostbyname_ex` does not support IPv6 name
821 resolution, and :func:`getaddrinfo` should be used instead for IPv4/v6 dual
824 .. audit-event:: socket.gethostbyname hostname socket.gethostbyname_ex
832 .. audit-event:: socket.gethostname "" socket.gethostname
843 *ipaddrlist* is a list of IPv4/v6 addresses for the same interface on the same
844 host (most likely containing only a single address). To find the fully qualified
846 both IPv4 and IPv6.
848 .. audit-event:: socket.gethostbyaddr ip_address socket.gethostbyaddr
853 Translate a socket address *sockaddr* into a 2-tuple ``(host, port)``. Depending
854 on the settings of *flags*, the result can contain a fully-qualified domain name
863 .. audit-event:: socket.getnameinfo sockaddr socket.getnameinfo
880 .. audit-event:: socket.getservbyname servicename,protocolname socket.getservbyname
889 .. audit-event:: socket.getservbyport port,protocolname socket.getservbyport
894 Convert 32-bit positive integers from network to host byte order. On machines
895 where the host byte order is the same as network byte order, this is a no-op;
896 otherwise, it performs a 4-byte swap operation.
901 Convert 16-bit positive integers from network to host byte order. On machines
902 where the host byte order is the same as network byte order, this is a no-op;
903 otherwise, it performs a 2-byte swap operation.
906 In case *x* does not fit in 16-bit unsigned integer, but does fit in a
907 positive C int, it is silently truncated to 16-bit unsigned integer.
914 Convert 32-bit positive integers from host to network byte order. On machines
915 where the host byte order is the same as network byte order, this is a no-op;
916 otherwise, it performs a 4-byte swap operation.
921 Convert 16-bit positive integers from host to network byte order. On machines
922 where the host byte order is the same as network byte order, this is a no-op;
923 otherwise, it performs a 2-byte swap operation.
926 In case *x* does not fit in 16-bit unsigned integer, but does fit in a
927 positive C int, it is silently truncated to 16-bit unsigned integer.
934 Convert an IPv4 address from dotted-quad string format (for example,
935 '123.45.67.89') to 32-bit packed binary format, as a bytes object four characters in
938 for the 32-bit packed binary this function returns.
943 If the IPv4 address string passed to this function is invalid,
948 instead for IPv4/v6 dual stack support.
953 Convert a 32-bit packed IPv4 address (a :term:`bytes-like object` four
954 bytes in length) to its standard dotted-quad string representation (for example,
957 is the C type for the 32-bit packed binary data this function takes as an
962 support IPv6, and :func:`inet_ntop` should be used instead for IPv4/v6 dual
966 Writable :term:`bytes-like object` is now accepted.
971 Convert an IP address from its family-specific string format to a packed,
990 Convert a packed IP address (a :term:`bytes-like object` of some number of
991 bytes) to its standard, family-specific string representation (for
1008 Writable :term:`bytes-like object` is now accepted.
1013 non-Unix platforms? The old (obsolete?) 4.2BSD form of the
1022 receive a single item of ancillary data, but :rfc:`3542` requires
1074 .. audit-event:: socket.sethostname name socket.sethostname
1099 * UUID: ``{FB605B73-AAC2-49A6-9A2F-25416AEA0573}``
1102 * description: ``Hyper-V Virtual Ethernet Adapter``
1142 .. _socket-objects:
1145 --------------
1163 The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
1166 The socket is now non-inheritable.
1177 of *address* depends on the address family --- see above.)
1179 .. audit-event:: socket.bind self,address socket.socket.bind
1189 Sockets are automatically closed when they are garbage-collected, but
1208 address family --- see above.)
1213 a timeout. For non-blocking sockets, the method raises an
1217 .. audit-event:: socket.connect self,address socket.socket.connect
1229 exception for errors returned by the C-level :c:func:`connect` call (other
1235 .. audit-event:: socket.connect self,address socket.socket.connect_ex
1250 The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
1253 The socket is now non-inheritable.
1258 Return the socket's file descriptor (a small integer), or -1 on failure. This
1277 find out the port number of a remote IPv4/v6 socket, for instance. (The format
1278 of the address returned depends on the address family --- see above.) On some
1285 an IPv4/v6 socket, for instance. (The format of the address returned depends on
1286 the address family --- see above.)
1297 contents of the buffer (see the optional built-in module :mod:`struct` for a way
1304 non-blocking.
1324 <https://msdn.microsoft.com/en-us/library/ms741621%28VS.85%29.aspx>`_ for more
1349 .. index:: single: I/O control; buffering
1353 interpreted the same way as by the built-in :func:`open` function, except
1366 On Windows, the file-like object created by :meth:`makefile` cannot be
1395 to zero. (The format of *address* depends on the address family --- see above.)
1419 The return value is a 4-tuple: ``(data, ancdata, msg_flags,
1421 non-ancillary data received. The *ancdata* item is a list of zero
1425 protocol-specific type respectively, and *cmsg_data* is a
1465 fds.frombytes(cmsg_data[:len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
1481 :meth:`recvmsg` would, but scatter the non-ancillary data into a
1485 filled with successive chunks of the non-ancillary data until it
1491 The return value is a 4-tuple: ``(nbytes, ancdata, msg_flags,
1493 non-ancillary data written into the buffers, and *ancdata*,
1500 >>> b1 = bytearray(b'----')
1502 >>> b3 = bytearray(b'--------------')
1508 [bytearray(b'Mary'), bytearray(b'01 had a 9'), bytearray(b'little lamb---')]
1522 depends on the address family --- see above.)
1541 information on this topic, consult the :ref:`socket-howto`.
1574 bytes sent. (The format of *address* depends on the address family --- see
1577 .. audit-event:: socket.sendto self,address socket.socket.sendto
1588 non-ancillary data from a series of buffers and concatenating it
1589 into a single message. The *buffers* argument specifies the
1590 non-ancillary data as an iterable of
1591 :term:`bytes-like objects <bytes-like object>`
1598 protocol-specific type respectively, and *cmsg_data* is a
1599 bytes-like object holding the associated data. Note that
1605 number of bytes of non-ancillary data sent.
1618 .. audit-event:: socket.sendmsg self,address socket.socket.sendmsg
1661 Send a file until EOF is reached by using high-performance
1671 Non-blocking sockets are not supported.
1685 Set blocking or non-blocking mode of the socket: if *flag* is false, the
1686 socket is set to non-blocking, else to blocking mode.
1703 If a non-zero value is given, subsequent socket operations will raise a
1706 non-blocking mode. If ``None`` is given, the socket is put in blocking mode.
1708 For further information, please consult the :ref:`notes on socket timeouts <socket-timeouts>`.
1726 ``None`` or a :term:`bytes-like object` representing a buffer. In the later
1728 proper bits (see the optional built-in module :mod:`struct` for a way to
1735 Writable :term:`bytes-like object` is now accepted.
1751 Duplicate a socket and prepare it for sharing with a target process. The
1752 target process must be provided with *process_id*. The resulting bytes object
1753 can then be passed to the target process using some form of interprocess
1756 the operating system has already duplicated it for the target process.
1766 Socket objects also have these (read-only) attributes that correspond to the
1786 .. _socket-timeouts:
1789 ------------------------
1791 A socket object can be in one of three modes: blocking, non-blocking, or
1798 * In *non-blocking mode*, operations fail (with an error that is unfortunately
1799 system-dependent) if they cannot be completed immediately: functions from the
1809 in non-blocking mode. Also, the blocking and timeout modes are shared between
1834 * if the listening socket is in *non-blocking mode*, whether the socket
1835 returned by :meth:`~socket.accept` is in blocking or non-blocking mode
1836 is operating system-dependent. If you want to ensure cross-platform
1840 .. _socket-example:
1843 -------
1855 The first two examples support IPv4 only. ::
1861 PORT = 50007 # Arbitrary non-privileged port
1886 The next two examples are identical to the above two, but support both IPv4 and
1888 should listen to both instead). On most of IPv6-ready systems, IPv6 will take
1889 precedence and the server may not accept IPv4 traffic. The client side will try
1898 PORT = 50007 # Arbitrary non-privileged port
2056 - *An Introductory 4.3BSD Interprocess Communication Tutorial*, by Stuart Sechrest
2058 - *An Advanced 4.3BSD Interprocess Communication Tutorial*, by Samuel J. Leffler et
2062 PS1:7 and PS1:8). The platform-specific reference material for the various
2063 socket-related system calls are also a valuable source of information on the
2065 see the WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers may