File: | Modules/socketmodule.c |
Location: | line 3410, column 5 |
Description: | Value stored to 'al' is never read |
1 | /* Socket module */ |
2 | |
3 | /* |
4 | |
5 | This module provides an interface to Berkeley socket IPC. |
6 | |
7 | Limitations: |
8 | |
9 | - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a |
10 | portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported |
11 | under Linux. |
12 | - No read/write operations (use sendall/recv or makefile instead). |
13 | - Additional restrictions apply on some non-Unix platforms (compensated |
14 | for by socket.py). |
15 | |
16 | Module interface: |
17 | |
18 | - socket.error: exception raised for socket specific errors |
19 | - socket.gaierror: exception raised for getaddrinfo/getnameinfo errors, |
20 | a subclass of socket.error |
21 | - socket.herror: exception raised for gethostby* errors, |
22 | a subclass of socket.error |
23 | - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') |
24 | - socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...]) |
25 | - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com') |
26 | - socket.getprotobyname(protocolname) --> protocol number |
27 | - socket.getservbyname(servicename[, protocolname]) --> port number |
28 | - socket.getservbyport(portnumber[, protocolname]) --> service name |
29 | - socket.socket([family[, type [, proto, fileno]]]) --> new socket object |
30 | (fileno specifies a pre-existing socket file descriptor) |
31 | - socket.socketpair([family[, type [, proto]]]) --> (socket, socket) |
32 | - socket.ntohs(16 bit value) --> new int object |
33 | - socket.ntohl(32 bit value) --> new int object |
34 | - socket.htons(16 bit value) --> new int object |
35 | - socket.htonl(32 bit value) --> new int object |
36 | - socket.getaddrinfo(host, port [, family, socktype, proto, flags]) |
37 | --> List of (family, socktype, proto, canonname, sockaddr) |
38 | - socket.getnameinfo(sockaddr, flags) --> (host, port) |
39 | - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h> |
40 | - socket.has_ipv6: boolean value indicating if IPv6 is supported |
41 | - socket.inet_aton(IP address) -> 32-bit packed IP representation |
42 | - socket.inet_ntoa(packed IP) -> IP address string |
43 | - socket.getdefaulttimeout() -> None | float |
44 | - socket.setdefaulttimeout(None | float) |
45 | - an Internet socket address is a pair (hostname, port) |
46 | where hostname can be anything recognized by gethostbyname() |
47 | (including the dd.dd.dd.dd notation) and port is in host byte order |
48 | - where a hostname is returned, the dd.dd.dd.dd notation is used |
49 | - a UNIX domain socket address is a string specifying the pathname |
50 | - an AF_PACKET socket address is a tuple containing a string |
51 | specifying the ethernet interface and an integer specifying |
52 | the Ethernet protocol number to be received. For example: |
53 | ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple |
54 | specify packet-type and ha-type/addr. |
55 | - an AF_TIPC socket address is expressed as |
56 | (addr_type, v1, v2, v3 [, scope]); where addr_type can be one of: |
57 | TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, and TIPC_ADDR_ID; |
58 | and scope can be one of: |
59 | TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE. |
60 | The meaning of v1, v2 and v3 depends on the value of addr_type: |
61 | if addr_type is TIPC_ADDR_NAME: |
62 | v1 is the server type |
63 | v2 is the port identifier |
64 | v3 is ignored |
65 | if addr_type is TIPC_ADDR_NAMESEQ: |
66 | v1 is the server type |
67 | v2 is the lower port number |
68 | v3 is the upper port number |
69 | if addr_type is TIPC_ADDR_ID: |
70 | v1 is the node |
71 | v2 is the ref |
72 | v3 is ignored |
73 | |
74 | |
75 | Local naming conventions: |
76 | |
77 | - names starting with sock_ are socket object methods |
78 | - names starting with socket_ are module-level functions |
79 | - names starting with PySocket are exported through socketmodule.h |
80 | |
81 | */ |
82 | |
83 | #ifdef __APPLE__1 |
84 | /* |
85 | * inet_aton is not available on OSX 10.3, yet we want to use a binary |
86 | * that was build on 10.4 or later to work on that release, weak linking |
87 | * comes to the rescue. |
88 | */ |
89 | # pragma weak inet_aton |
90 | #endif |
91 | |
92 | #include "Python.h" |
93 | #include "structmember.h" |
94 | |
95 | #undef MAX |
96 | #define MAX(x, y)((x) < (y) ? (y) : (x)) ((x) < (y) ? (y) : (x)) |
97 | |
98 | /* Socket object documentation */ |
99 | PyDoc_STRVAR(sock_doc,static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
100 | "socket([family[, type[, proto]]]) -> socket object\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
101 | \n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
102 | Open a socket of the given type. The family argument specifies the\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
103 | address family; it defaults to AF_INET. The type argument specifies\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
104 | whether this is a stream (SOCK_STREAM, this is the default)\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
105 | or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
106 | specifying the default protocol. Keyword arguments are accepted.\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
107 | \n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
108 | A socket object represents one endpoint of a network connection.\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
109 | \n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
110 | Methods of socket objects (keyword arguments not allowed):\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
111 | \n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
112 | _accept() -- accept connection, returning new socket fd and client address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
113 | bind(addr) -- bind the socket to a local address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
114 | close() -- close the socket\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
115 | connect(addr) -- connect the socket to a remote address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
116 | connect_ex(addr) -- connect, return an error code instead of an exception\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
117 | _dup() -- return a new socket fd duplicated from fileno()\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
118 | fileno() -- return underlying file descriptor\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
119 | getpeername() -- return remote address [*]\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
120 | getsockname() -- return local address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
121 | getsockopt(level, optname[, buflen]) -- get socket options\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
122 | gettimeout() -- return timeout or None\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
123 | listen(n) -- start listening for incoming connections\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
124 | recv(buflen[, flags]) -- receive data\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
125 | recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
126 | recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
127 | recvfrom_into(buffer[, nbytes, [, flags])\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
128 | -- receive data and sender\'s address (into a buffer)\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
129 | sendall(data[, flags]) -- send all data\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
130 | send(data[, flags]) -- send data, may not send all of it\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
131 | sendto(data[, flags], addr) -- send data to a given address\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
132 | setblocking(0 | 1) -- set or clear the blocking I/O flag\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
133 | setsockopt(level, optname, value) -- set socket options\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
134 | settimeout(None | float) -- set or clear the timeout\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
135 | shutdown(how) -- shut down traffic in one or both directions\n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
136 | \n\static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!" |
137 | [*] not available on all platforms!")static char sock_doc[] = "socket([family[, type[, proto]]]) -> socket object\n\nOpen a socket of the given type. The family argument specifies the\naddress family; it defaults to AF_INET. The type argument specifies\nwhether this is a stream (SOCK_STREAM, this is the default)\nor datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\nspecifying the default protocol. Keyword arguments are accepted.\n\nA socket object represents one endpoint of a network connection.\n\nMethods of socket objects (keyword arguments not allowed):\n\n_accept() -- accept connection, returning new socket fd and client address\nbind(addr) -- bind the socket to a local address\nclose() -- close the socket\nconnect(addr) -- connect the socket to a remote address\nconnect_ex(addr) -- connect, return an error code instead of an exception\n_dup() -- return a new socket fd duplicated from fileno()\nfileno() -- return underlying file descriptor\ngetpeername() -- return remote address [*]\ngetsockname() -- return local address\ngetsockopt(level, optname[, buflen]) -- get socket options\ngettimeout() -- return timeout or None\nlisten(n) -- start listening for incoming connections\nrecv(buflen[, flags]) -- receive data\nrecv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\nrecvfrom(buflen[, flags]) -- receive data and sender\'s address\nrecvfrom_into(buffer[, nbytes, [, flags])\n -- receive data and sender\'s address (into a buffer)\nsendall(data[, flags]) -- send all data\nsend(data[, flags]) -- send data, may not send all of it\nsendto(data[, flags], addr) -- send data to a given address\nsetblocking(0 | 1) -- set or clear the blocking I/O flag\nsetsockopt(level, optname, value) -- set socket options\nsettimeout(None | float) -- set or clear the timeout\nshutdown(how) -- shut down traffic in one or both directions\n\n [*] not available on all platforms!"; |
138 | |
139 | /* XXX This is a terrible mess of platform-dependent preprocessor hacks. |
140 | I hope some day someone can clean this up please... */ |
141 | |
142 | /* Hacks for gethostbyname_r(). On some non-Linux platforms, the configure |
143 | script doesn't get this right, so we hardcode some platform checks below. |
144 | On the other hand, not all Linux versions agree, so there the settings |
145 | computed by the configure script are needed! */ |
146 | |
147 | #ifndef linux |
148 | # undef HAVE_GETHOSTBYNAME_R_3_ARG |
149 | # undef HAVE_GETHOSTBYNAME_R_5_ARG |
150 | # undef HAVE_GETHOSTBYNAME_R_6_ARG |
151 | #endif |
152 | |
153 | #ifndef WITH_THREAD1 |
154 | # undef HAVE_GETHOSTBYNAME_R |
155 | #endif |
156 | |
157 | #ifdef HAVE_GETHOSTBYNAME_R |
158 | # if defined(_AIX) || defined(__osf__) |
159 | # define HAVE_GETHOSTBYNAME_R_3_ARG |
160 | # elif defined(__sun) || defined(__sgi) |
161 | # define HAVE_GETHOSTBYNAME_R_5_ARG |
162 | # elif defined(linux) |
163 | /* Rely on the configure script */ |
164 | # else |
165 | # undef HAVE_GETHOSTBYNAME_R |
166 | # endif |
167 | #endif |
168 | |
169 | #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD1) && \ |
170 | !defined(MS_WINDOWS) |
171 | # define USE_GETHOSTBYNAME_LOCK |
172 | #endif |
173 | |
174 | /* To use __FreeBSD_version */ |
175 | #ifdef HAVE_SYS_PARAM_H1 |
176 | #include <sys/param.h> |
177 | #endif |
178 | /* On systems on which getaddrinfo() is believed to not be thread-safe, |
179 | (this includes the getaddrinfo emulation) protect access with a lock. */ |
180 | #if defined(WITH_THREAD1) && (defined(__APPLE__1) || \ |
181 | (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \ |
182 | defined(__OpenBSD__) || defined(__NetBSD__) || \ |
183 | defined(__VMS) || !defined(HAVE_GETADDRINFO1)) |
184 | #define USE_GETADDRINFO_LOCK |
185 | #endif |
186 | |
187 | #ifdef USE_GETADDRINFO_LOCK |
188 | #define ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); PyThread_acquire_lock(netdb_lock, 1); |
189 | #define RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); PyThread_release_lock(netdb_lock); |
190 | #else |
191 | #define ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); |
192 | #define RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); |
193 | #endif |
194 | |
195 | #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
196 | # include "pythread.h" |
197 | #endif |
198 | |
199 | #if defined(PYCC_VACPP) |
200 | # include <types.h> |
201 | # include <io.h> |
202 | # include <sys/ioctl.h> |
203 | # include <utils.h> |
204 | # include <ctype.h> |
205 | #endif |
206 | |
207 | #if defined(__VMS) |
208 | # include <ioctl.h> |
209 | #endif |
210 | |
211 | #if defined(PYOS_OS2) |
212 | # define INCL_DOS |
213 | # define INCL_DOSERRORS |
214 | # define INCL_NOPMAPI |
215 | # include <os2.h> |
216 | #endif |
217 | |
218 | #if defined(__sgi) && _COMPILER_VERSION>700 && !_SGIAPI |
219 | /* make sure that the reentrant (gethostbyaddr_r etc) |
220 | functions are declared correctly if compiling with |
221 | MIPSPro 7.x in ANSI C mode (default) */ |
222 | |
223 | /* XXX Using _SGIAPI is the wrong thing, |
224 | but I don't know what the right thing is. */ |
225 | #undef _SGIAPI /* to avoid warning */ |
226 | #define _SGIAPI 1 |
227 | |
228 | #undef _XOPEN_SOURCE |
229 | #include <sys/socket.h> |
230 | #include <sys/types.h> |
231 | #include <netinet/in.h> |
232 | #ifdef _SS_ALIGNSIZE(sizeof(__int64_t)) |
233 | #define HAVE_GETADDRINFO1 1 |
234 | #define HAVE_GETNAMEINFO1 1 |
235 | #endif |
236 | |
237 | #define HAVE_INET_PTON1 |
238 | #include <netdb.h> |
239 | #endif |
240 | |
241 | /* Irix 6.5 fails to define this variable at all. This is needed |
242 | for both GCC and SGI's compiler. I'd say that the SGI headers |
243 | are just busted. Same thing for Solaris. */ |
244 | #if (defined(__sgi) || defined(sun)) && !defined(INET_ADDRSTRLEN16) |
245 | #define INET_ADDRSTRLEN16 16 |
246 | #endif |
247 | |
248 | /* Generic includes */ |
249 | #ifdef HAVE_SYS_TYPES_H1 |
250 | #include <sys/types.h> |
251 | #endif |
252 | |
253 | /* Generic socket object definitions and includes */ |
254 | #define PySocket_BUILDING_SOCKET |
255 | #include "socketmodule.h" |
256 | |
257 | /* Addressing includes */ |
258 | |
259 | #ifndef MS_WINDOWS |
260 | |
261 | /* Non-MS WINDOWS includes */ |
262 | # include <netdb.h> |
263 | |
264 | /* Headers needed for inet_ntoa() and inet_addr() */ |
265 | # if defined(PYOS_OS2) && defined(PYCC_VACPP) |
266 | # include <netdb.h> |
267 | typedef size_t socklen_t; |
268 | # else |
269 | # include <arpa/inet.h> |
270 | # endif |
271 | |
272 | # include <fcntl.h> |
273 | |
274 | #else |
275 | |
276 | /* MS_WINDOWS includes */ |
277 | # ifdef HAVE_FCNTL_H1 |
278 | # include <fcntl.h> |
279 | # endif |
280 | |
281 | #endif |
282 | |
283 | #include <stddef.h> |
284 | |
285 | #ifndef offsetof |
286 | # define offsetof(type, member)__builtin_offsetof(type, member) ((size_t)(&((type *)0)->member)) |
287 | #endif |
288 | |
289 | #ifndef O_NONBLOCK0x0004 |
290 | # define O_NONBLOCK0x0004 O_NDELAY0x0004 |
291 | #endif |
292 | |
293 | /* include Python's addrinfo.h unless it causes trouble */ |
294 | #if defined(__sgi) && _COMPILER_VERSION>700 && defined(_SS_ALIGNSIZE(sizeof(__int64_t))) |
295 | /* Do not include addinfo.h on some newer IRIX versions. |
296 | * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21, |
297 | * for example, but not by 6.5.10. |
298 | */ |
299 | #elif defined(_MSC_VER) && _MSC_VER>1201 |
300 | /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and |
301 | * EAI_* constants are defined in (the already included) ws2tcpip.h. |
302 | */ |
303 | #else |
304 | # include "addrinfo.h" |
305 | #endif |
306 | |
307 | #ifndef HAVE_INET_PTON1 |
308 | #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
309 | int inet_pton(int af, const char *src, void *dst); |
310 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); |
311 | #endif |
312 | #endif |
313 | |
314 | #ifdef __APPLE__1 |
315 | /* On OS X, getaddrinfo returns no error indication of lookup |
316 | failure, so we must use the emulation instead of the libinfo |
317 | implementation. Unfortunately, performing an autoconf test |
318 | for this bug would require DNS access for the machine performing |
319 | the configuration, which is not acceptable. Therefore, we |
320 | determine the bug just by checking for __APPLE__. If this bug |
321 | gets ever fixed, perhaps checking for sys/version.h would be |
322 | appropriate, which is 10/0 on the system with the bug. */ |
323 | #ifndef HAVE_GETNAMEINFO1 |
324 | /* This bug seems to be fixed in Jaguar. Ths easiest way I could |
325 | Find to check for Jaguar is that it has getnameinfo(), which |
326 | older releases don't have */ |
327 | #undef HAVE_GETADDRINFO1 |
328 | #endif |
329 | |
330 | #ifdef HAVE_INET_ATON1 |
331 | #define USE_INET_ATON_WEAKLINK |
332 | #endif |
333 | |
334 | #endif |
335 | |
336 | /* I know this is a bad practice, but it is the easiest... */ |
337 | #if !defined(HAVE_GETADDRINFO1) |
338 | /* avoid clashes with the C library definition of the symbol. */ |
339 | #define getaddrinfo fake_getaddrinfo |
340 | #define gai_strerror fake_gai_strerror |
341 | #define freeaddrinfo fake_freeaddrinfo |
342 | #include "getaddrinfo.c" |
343 | #endif |
344 | #if !defined(HAVE_GETNAMEINFO1) |
345 | #define getnameinfo fake_getnameinfo |
346 | #include "getnameinfo.c" |
347 | #endif |
348 | |
349 | #ifdef MS_WINDOWS |
350 | /* On Windows a socket is really a handle not an fd */ |
351 | static SOCKET |
352 | dup_socket(SOCKET handle)dup(SOCKET handle) |
353 | { |
354 | WSAPROTOCOL_INFO info; |
355 | |
356 | if (WSADuplicateSocket(handle, GetCurrentProcessId(), &info)) |
357 | return INVALID_SOCKET(-1); |
358 | |
359 | return WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, |
360 | FROM_PROTOCOL_INFO, &info, 0, 0); |
361 | } |
362 | #define SOCKETCLOSEclose closesocket |
363 | #else |
364 | /* On Unix we can use dup to duplicate the file descriptor of a socket*/ |
365 | #define dup_socket(fd)dup(fd) dup(fd) |
366 | #endif |
367 | |
368 | #ifdef MS_WIN32 |
369 | #define EAFNOSUPPORT47 WSAEAFNOSUPPORT |
370 | #define snprintf _snprintf |
371 | #endif |
372 | |
373 | #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
374 | #define SOCKETCLOSEclose soclose |
375 | #define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */ |
376 | #endif |
377 | |
378 | #ifndef SOCKETCLOSEclose |
379 | #define SOCKETCLOSEclose close |
380 | #endif |
381 | |
382 | #if (defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)) && !defined(__NetBSD__) && !defined(__DragonFly__) |
383 | #define USE_BLUETOOTH 1 |
384 | #if defined(__FreeBSD__) |
385 | #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP |
386 | #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM |
387 | #define BTPROTO_HCI BLUETOOTH_PROTO_HCI |
388 | #define SOL_HCI SOL_HCI_RAW |
389 | #define HCI_FILTER SO_HCI_RAW_FILTER |
390 | #define sockaddr_l2 sockaddr_l2cap |
391 | #define sockaddr_rc sockaddr_rfcomm |
392 | #define hci_dev hci_node |
393 | #define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb) |
394 | #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb) |
395 | #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
396 | #elif defined(__NetBSD__) || defined(__DragonFly__) |
397 | #define sockaddr_l2 sockaddr_bt |
398 | #define sockaddr_rc sockaddr_bt |
399 | #define sockaddr_hci sockaddr_bt |
400 | #define sockaddr_sco sockaddr_bt |
401 | #define SOL_HCI BTPROTO_HCI |
402 | #define HCI_DATA_DIR SO_HCI_DIRECTION |
403 | #define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb) |
404 | #define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb) |
405 | #define _BT_HCI_MEMB(sa, memb) ((sa)->bt_##memb) |
406 | #define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb) |
407 | #else |
408 | #define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb) |
409 | #define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb) |
410 | #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
411 | #define _BT_SCO_MEMB(sa, memb) ((sa)->sco_##memb) |
412 | #endif |
413 | #endif |
414 | |
415 | #ifdef __VMS |
416 | /* TCP/IP Services for VMS uses a maximum send/recv buffer length */ |
417 | #define SEGMENT_SIZE (32 * 1024 -1) |
418 | #endif |
419 | |
420 | #define SAS2SA(x)((struct sockaddr *)(x)) ((struct sockaddr *)(x)) |
421 | |
422 | /* |
423 | * Constants for getnameinfo() |
424 | */ |
425 | #if !defined(NI_MAXHOST1025) |
426 | #define NI_MAXHOST1025 1025 |
427 | #endif |
428 | #if !defined(NI_MAXSERV32) |
429 | #define NI_MAXSERV32 32 |
430 | #endif |
431 | |
432 | #ifndef INVALID_SOCKET(-1) /* MS defines this */ |
433 | #define INVALID_SOCKET(-1) (-1) |
434 | #endif |
435 | |
436 | /* XXX There's a problem here: *static* functions are not supposed to have |
437 | a Py prefix (or use CapitalizedWords). Later... */ |
438 | |
439 | /* Global variable holding the exception type for errors detected |
440 | by this module (but not argument type or memory errors, etc.). */ |
441 | static PyObject *socket_error; |
442 | static PyObject *socket_herror; |
443 | static PyObject *socket_gaierror; |
444 | static PyObject *socket_timeout; |
445 | |
446 | /* A forward reference to the socket type object. |
447 | The sock_type variable contains pointers to various functions, |
448 | some of which call new_sockobject(), which uses sock_type, so |
449 | there has to be a circular reference. */ |
450 | static PyTypeObject sock_type; |
451 | |
452 | #if defined(HAVE_POLL_H1) |
453 | #include <poll.h> |
454 | #elif defined(HAVE_SYS_POLL_H1) |
455 | #include <sys/poll.h> |
456 | #endif |
457 | |
458 | #ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE |
459 | /* Platform can select file descriptors beyond FD_SETSIZE */ |
460 | #define IS_SELECTABLE(s)1 1 |
461 | #elif defined(HAVE_POLL1) |
462 | /* Instead of select(), we'll use poll() since poll() works on any fd. */ |
463 | #define IS_SELECTABLE(s)1 1 |
464 | /* Can we call select() with this socket without a buffer overrun? */ |
465 | #else |
466 | /* POSIX says selecting file descriptors beyond FD_SETSIZE |
467 | has undefined behaviour. If there's no timeout left, we don't have to |
468 | call select, so it's a safe, little white lie. */ |
469 | #define IS_SELECTABLE(s)1 ((s)->sock_fd < FD_SETSIZE1024 || s->sock_timeout <= 0.0) |
470 | #endif |
471 | |
472 | static PyObject* |
473 | select_error(void) |
474 | { |
475 | PyErr_SetString(socket_error, "unable to select on socket"); |
476 | return NULL((void*)0); |
477 | } |
478 | |
479 | #ifdef MS_WINDOWS |
480 | #ifndef WSAEAGAIN |
481 | #define WSAEAGAIN WSAEWOULDBLOCK |
482 | #endif |
483 | #define CHECK_ERRNO(expected)((*__error()) == expected) \ |
484 | (WSAGetLastError() == WSA ## expected) |
485 | #else |
486 | #define CHECK_ERRNO(expected)((*__error()) == expected) \ |
487 | (errno(*__error()) == expected) |
488 | #endif |
489 | |
490 | /* Convenience function to raise an error according to errno |
491 | and return a NULL pointer from a function. */ |
492 | |
493 | static PyObject * |
494 | set_error(void) |
495 | { |
496 | #ifdef MS_WINDOWS |
497 | int err_no = WSAGetLastError(); |
498 | /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which |
499 | recognizes the error codes used by both GetLastError() and |
500 | WSAGetLastError */ |
501 | if (err_no) |
502 | return PyErr_SetExcFromWindowsErr(socket_error, err_no); |
503 | #endif |
504 | |
505 | #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
506 | if (sock_errno() != NO_ERROR) { |
507 | APIRET rc; |
508 | ULONG msglen; |
509 | char outbuf[100]; |
510 | int myerrorcode = sock_errno(); |
511 | |
512 | /* Retrieve socket-related error message from MPTN.MSG file */ |
513 | rc = DosGetMessage(NULL((void*)0), 0, outbuf, sizeof(outbuf), |
514 | myerrorcode - SOCBASEERR + 26, |
515 | "mptn.msg", |
516 | &msglen); |
517 | if (rc == NO_ERROR) { |
518 | PyObject *v; |
519 | |
520 | /* OS/2 doesn't guarantee a terminator */ |
521 | outbuf[msglen] = '\0'; |
522 | if (strlen(outbuf) > 0) { |
523 | /* If non-empty msg, trim CRLF */ |
524 | char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
525 | while (lastc > outbuf && |
526 | isspace(Py_CHARMASK(*lastc))iswspace(btowc(((unsigned char)((*lastc) & 0xff))))) { |
527 | /* Trim trailing whitespace (CRLF) */ |
528 | *lastc-- = '\0'; |
529 | } |
530 | } |
531 | v = Py_BuildValue("(is)", myerrorcode, outbuf); |
532 | if (v != NULL((void*)0)) { |
533 | PyErr_SetObject(socket_error, v); |
534 | Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt != 0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 534 , (PyObject *)(v)); } else _Py_Dealloc((PyObject *)(v)); } while (0); |
535 | } |
536 | return NULL((void*)0); |
537 | } |
538 | } |
539 | #endif |
540 | |
541 | return PyErr_SetFromErrno(socket_error); |
542 | } |
543 | |
544 | |
545 | static PyObject * |
546 | set_herror(int h_error) |
547 | { |
548 | PyObject *v; |
549 | |
550 | #ifdef HAVE_HSTRERROR1 |
551 | v = Py_BuildValue("(is)", h_error, (char *)hstrerror(h_error)); |
552 | #else |
553 | v = Py_BuildValue("(is)", h_error, "host not found"); |
554 | #endif |
555 | if (v != NULL((void*)0)) { |
556 | PyErr_SetObject(socket_herror, v); |
557 | Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt != 0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 557 , (PyObject *)(v)); } else _Py_Dealloc((PyObject *)(v)); } while (0); |
558 | } |
559 | |
560 | return NULL((void*)0); |
561 | } |
562 | |
563 | |
564 | static PyObject * |
565 | set_gaierror(int error) |
566 | { |
567 | PyObject *v; |
568 | |
569 | #ifdef EAI_SYSTEM11 |
570 | /* EAI_SYSTEM is not available on Windows XP. */ |
571 | if (error == EAI_SYSTEM11) |
572 | return set_error(); |
573 | #endif |
574 | |
575 | #ifdef HAVE_GAI_STRERROR1 |
576 | v = Py_BuildValue("(is)", error, gai_strerror(error)); |
577 | #else |
578 | v = Py_BuildValue("(is)", error, "getaddrinfo failed"); |
579 | #endif |
580 | if (v != NULL((void*)0)) { |
581 | PyErr_SetObject(socket_gaierror, v); |
582 | Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt != 0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 582 , (PyObject *)(v)); } else _Py_Dealloc((PyObject *)(v)); } while (0); |
583 | } |
584 | |
585 | return NULL((void*)0); |
586 | } |
587 | |
588 | #ifdef __VMS |
589 | /* Function to send in segments */ |
590 | static int |
591 | sendsegmented(int sock_fd, char *buf, int len, int flags) |
592 | { |
593 | int n = 0; |
594 | int remaining = len; |
595 | |
596 | while (remaining > 0) { |
597 | unsigned int segment; |
598 | |
599 | segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining); |
600 | n = send(sock_fd, buf, segment, flags); |
601 | if (n < 0) { |
602 | return n; |
603 | } |
604 | remaining -= segment; |
605 | buf += segment; |
606 | } /* end while */ |
607 | |
608 | return len; |
609 | } |
610 | #endif |
611 | |
612 | /* Function to perform the setting of socket blocking mode |
613 | internally. block = (1 | 0). */ |
614 | static int |
615 | internal_setblocking(PySocketSockObject *s, int block) |
616 | { |
617 | #ifndef MS_WINDOWS |
618 | int delay_flag; |
619 | #endif |
620 | #ifdef SOCK_NONBLOCK |
621 | if (block) |
622 | s->sock_type &= (~SOCK_NONBLOCK); |
623 | else |
624 | s->sock_type |= SOCK_NONBLOCK; |
625 | #endif |
626 | |
627 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
628 | #ifndef MS_WINDOWS |
629 | #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
630 | block = !block; |
631 | ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); |
632 | #elif defined(__VMS) |
633 | block = !block; |
634 | ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block); |
635 | #else /* !PYOS_OS2 && !__VMS */ |
636 | delay_flag = fcntl(s->sock_fd, F_GETFL3, 0); |
637 | if (block) |
638 | delay_flag &= (~O_NONBLOCK0x0004); |
639 | else |
640 | delay_flag |= O_NONBLOCK0x0004; |
641 | fcntl(s->sock_fd, F_SETFL4, delay_flag); |
642 | #endif /* !PYOS_OS2 */ |
643 | #else /* MS_WINDOWS */ |
644 | block = !block; |
645 | ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); |
646 | #endif /* MS_WINDOWS */ |
647 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
648 | |
649 | /* Since these don't return anything */ |
650 | return 1; |
651 | } |
652 | |
653 | /* Do a select()/poll() on the socket, if necessary (sock_timeout > 0). |
654 | The argument writing indicates the direction. |
655 | This does not raise an exception; we'll let our caller do that |
656 | after they've reacquired the interpreter lock. |
657 | Returns 1 on timeout, -1 on error, 0 otherwise. */ |
658 | static int |
659 | internal_select_ex(PySocketSockObject *s, int writing, double interval) |
660 | { |
661 | int n; |
662 | |
663 | /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
664 | if (s->sock_timeout <= 0.0) |
665 | return 0; |
666 | |
667 | /* Guard against closed socket */ |
668 | if (s->sock_fd < 0) |
669 | return 0; |
670 | |
671 | /* Handling this condition here simplifies the select loops */ |
672 | if (interval < 0.0) |
673 | return 1; |
674 | |
675 | /* Prefer poll, if available, since you can poll() any fd |
676 | * which can't be done with select(). */ |
677 | #ifdef HAVE_POLL1 |
678 | { |
679 | struct pollfd pollfd; |
680 | int timeout; |
681 | |
682 | pollfd.fd = s->sock_fd; |
683 | pollfd.events = writing ? POLLOUT0x0004 : POLLIN0x0001; |
684 | |
685 | /* s->sock_timeout is in seconds, timeout in ms */ |
686 | timeout = (int)(interval * 1000 + 0.5); |
687 | n = poll(&pollfd, 1, timeout); |
688 | } |
689 | #else |
690 | { |
691 | /* Construct the arguments to select */ |
692 | fd_set fds; |
693 | struct timeval tv; |
694 | tv.tv_sec = (int)interval; |
695 | tv.tv_usec = (int)((interval - tv.tv_sec) * 1e6); |
696 | FD_ZERO(&fds)__builtin_bzero(&fds, sizeof(*(&fds))); |
697 | FD_SET(s->sock_fd, &fds)do { int __fd = (s->sock_fd); ((&fds)->fds_bits[__fd /(sizeof(__int32_t) * 8)] |= (1<<(__fd % (sizeof(__int32_t ) * 8)))); } while(0); |
698 | |
699 | /* See if the socket is ready */ |
700 | if (writing) |
701 | n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int)((__builtin_expect(!((SOCKET_T)(int)(s->sock_fd+1) == (s-> sock_fd+1)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 701, "(SOCKET_T)(int)(s->sock_fd+1) == (s->sock_fd+1)" ) : (void)0), (int)(s->sock_fd+1)), |
702 | NULL((void*)0), &fds, NULL((void*)0), &tv); |
703 | else |
704 | n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int)((__builtin_expect(!((SOCKET_T)(int)(s->sock_fd+1) == (s-> sock_fd+1)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 704, "(SOCKET_T)(int)(s->sock_fd+1) == (s->sock_fd+1)" ) : (void)0), (int)(s->sock_fd+1)), |
705 | &fds, NULL((void*)0), NULL((void*)0), &tv); |
706 | } |
707 | #endif |
708 | |
709 | if (n < 0) |
710 | return -1; |
711 | if (n == 0) |
712 | return 1; |
713 | return 0; |
714 | } |
715 | |
716 | static int |
717 | internal_select(PySocketSockObject *s, int writing) |
718 | { |
719 | return internal_select_ex(s, writing, s->sock_timeout); |
720 | } |
721 | |
722 | /* |
723 | Two macros for automatic retry of select() in case of false positives |
724 | (for example, select() could indicate a socket is ready for reading |
725 | but the data then discarded by the OS because of a wrong checksum). |
726 | Here is an example of use: |
727 | |
728 | BEGIN_SELECT_LOOP(s) |
729 | Py_BEGIN_ALLOW_THREADS |
730 | timeout = internal_select_ex(s, 0, interval); |
731 | if (!timeout) |
732 | outlen = recv(s->sock_fd, cbuf, len, flags); |
733 | Py_END_ALLOW_THREADS |
734 | if (timeout == 1) { |
735 | PyErr_SetString(socket_timeout, "timed out"); |
736 | return -1; |
737 | } |
738 | END_SELECT_LOOP(s) |
739 | */ |
740 | |
741 | #define BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; \ |
742 | { \ |
743 | _PyTime_timeval now, deadline = {0, 0}; \ |
744 | double interval = s->sock_timeout; \ |
745 | int has_timeout = s->sock_timeout > 0.0; \ |
746 | if (has_timeout) { \ |
747 | _PyTime_gettimeofday(&now); \ |
748 | deadline = now; \ |
749 | _PyTime_ADD_SECONDS(deadline, s->sock_timeout)do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t) s ->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline .tv_usec %= 1000000; } while (0); \ |
750 | } \ |
751 | while (1) { \ |
752 | errno(*__error()) = 0; \ |
753 | |
754 | #define END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } \ |
755 | if (!has_timeout || \ |
756 | (!CHECK_ERRNO(EWOULDBLOCK)((*__error()) == 35) && !CHECK_ERRNO(EAGAIN)((*__error()) == 35))) \ |
757 | break; \ |
758 | _PyTime_gettimeofday(&now); \ |
759 | interval = _PyTime_INTERVAL(now, deadline)((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); \ |
760 | } \ |
761 | } \ |
762 | |
763 | /* Initialize a new socket object. */ |
764 | |
765 | static double defaulttimeout = -1.0; /* Default timeout for new sockets */ |
766 | |
767 | static void |
768 | init_sockobject(PySocketSockObject *s, |
769 | SOCKET_T fd, int family, int type, int proto) |
770 | { |
771 | s->sock_fd = fd; |
772 | s->sock_family = family; |
773 | s->sock_type = type; |
774 | s->sock_proto = proto; |
775 | |
776 | s->errorhandler = &set_error; |
777 | #ifdef SOCK_NONBLOCK |
778 | if (type & SOCK_NONBLOCK) |
779 | s->sock_timeout = 0.0; |
780 | else |
781 | #endif |
782 | { |
783 | s->sock_timeout = defaulttimeout; |
784 | if (defaulttimeout >= 0.0) |
785 | internal_setblocking(s, 0); |
786 | } |
787 | |
788 | } |
789 | |
790 | |
791 | /* Create a new socket object. |
792 | This just creates the object and initializes it. |
793 | If the creation fails, return NULL and set an exception (implicit |
794 | in NEWOBJ()). */ |
795 | |
796 | static PySocketSockObject * |
797 | new_sockobject(SOCKET_T fd, int family, int type, int proto) |
798 | { |
799 | PySocketSockObject *s; |
800 | s = (PySocketSockObject *) |
801 | PyType_GenericNew(&sock_type, NULL((void*)0), NULL((void*)0)); |
802 | if (s != NULL((void*)0)) |
803 | init_sockobject(s, fd, family, type, proto); |
804 | return s; |
805 | } |
806 | |
807 | |
808 | /* Lock to allow python interpreter to continue, but only allow one |
809 | thread to be in gethostbyname or getaddrinfo */ |
810 | #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
811 | PyThread_type_lock netdb_lock; |
812 | #endif |
813 | |
814 | |
815 | /* Convert a string specifying a host name or one of a few symbolic |
816 | names to a numeric IP address. This usually calls gethostbyname() |
817 | to do the work; the names "" and "<broadcast>" are special. |
818 | Return the length (IPv4 should be 4 bytes), or negative if |
819 | an error occurred; then an exception is raised. */ |
820 | |
821 | static int |
822 | setipaddr(char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int af) |
823 | { |
824 | struct addrinfo hints, *res; |
825 | int error; |
826 | int d1, d2, d3, d4; |
827 | char ch; |
828 | |
829 | memset((void *) addr_ret, '\0', sizeof(*addr_ret))((__builtin_object_size ((void *) addr_ret, 0) != (size_t) -1 ) ? __builtin___memset_chk ((void *) addr_ret, '\0', sizeof(* addr_ret), __builtin_object_size ((void *) addr_ret, 0)) : __inline_memset_chk ((void *) addr_ret, '\0', sizeof(*addr_ret))); |
830 | if (name[0] == '\0') { |
831 | int siz; |
832 | memset(&hints, 0, sizeof(hints))((__builtin_object_size (&hints, 0) != (size_t) -1) ? __builtin___memset_chk (&hints, 0, sizeof(hints), __builtin_object_size (&hints , 0)) : __inline_memset_chk (&hints, 0, sizeof(hints))); |
833 | hints.ai_family = af; |
834 | hints.ai_socktype = SOCK_DGRAM2; /*dummy*/ |
835 | hints.ai_flags = AI_PASSIVE0x00000001; |
836 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
837 | ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); |
838 | error = getaddrinfo(NULL((void*)0), "0", &hints, &res); |
839 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
840 | /* We assume that those thread-unsafe getaddrinfo() versions |
841 | *are* safe regarding their return value, ie. that a |
842 | subsequent call to getaddrinfo() does not destroy the |
843 | outcome of the first call. */ |
844 | RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); |
845 | if (error) { |
846 | set_gaierror(error); |
847 | return -1; |
848 | } |
849 | switch (res->ai_family) { |
850 | case AF_INET2: |
851 | siz = 4; |
852 | break; |
853 | #ifdef ENABLE_IPV61 |
854 | case AF_INET630: |
855 | siz = 16; |
856 | break; |
857 | #endif |
858 | default: |
859 | freeaddrinfo(res); |
860 | PyErr_SetString(socket_error, |
861 | "unsupported address family"); |
862 | return -1; |
863 | } |
864 | if (res->ai_next) { |
865 | freeaddrinfo(res); |
866 | PyErr_SetString(socket_error, |
867 | "wildcard resolved to multiple address"); |
868 | return -1; |
869 | } |
870 | if (res->ai_addrlen < addr_ret_size) |
871 | addr_ret_size = res->ai_addrlen; |
872 | memcpy(addr_ret, res->ai_addr, addr_ret_size)((__builtin_object_size (addr_ret, 0) != (size_t) -1) ? __builtin___memcpy_chk (addr_ret, res->ai_addr, addr_ret_size, __builtin_object_size (addr_ret, 0)) : __inline_memcpy_chk (addr_ret, res->ai_addr , addr_ret_size)); |
873 | freeaddrinfo(res); |
874 | return siz; |
875 | } |
876 | if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) { |
877 | struct sockaddr_in *sin; |
878 | if (af != AF_INET2 && af != AF_UNSPEC0) { |
879 | PyErr_SetString(socket_error, |
880 | "address family mismatched"); |
881 | return -1; |
882 | } |
883 | sin = (struct sockaddr_in *)addr_ret; |
884 | memset((void *) sin, '\0', sizeof(*sin))((__builtin_object_size ((void *) sin, 0) != (size_t) -1) ? __builtin___memset_chk ((void *) sin, '\0', sizeof(*sin), __builtin_object_size ((void *) sin, 0)) : __inline_memset_chk ((void *) sin, '\0', sizeof (*sin))); |
885 | sin->sin_family = AF_INET2; |
886 | #ifdef HAVE_SOCKADDR_SA_LEN1 |
887 | sin->sin_len = sizeof(*sin); |
888 | #endif |
889 | sin->sin_addr.s_addr = INADDR_BROADCAST(u_int32_t)0xffffffff; |
890 | return sizeof(sin->sin_addr); |
891 | } |
892 | if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && |
893 | 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && |
894 | 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { |
895 | struct sockaddr_in *sin; |
896 | sin = (struct sockaddr_in *)addr_ret; |
897 | sin->sin_addr.s_addr = htonl((__builtin_constant_p(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) ? ((__uint32_t )((((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0xff000000) >> 24) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0)) & 0x00ff0000) >> 8) | (((__uint32_t )(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x0000ff00) << 8) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x000000ff) << 24))) : _OSSwapInt32(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0))) |
898 | ((long) d1 << 24) | ((long) d2 << 16) |(__builtin_constant_p(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) ? ((__uint32_t )((((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0xff000000) >> 24) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0)) & 0x00ff0000) >> 8) | (((__uint32_t )(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x0000ff00) << 8) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x000000ff) << 24))) : _OSSwapInt32(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0))) |
899 | ((long) d3 << 8) | ((long) d4 << 0))(__builtin_constant_p(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) ? ((__uint32_t )((((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0xff000000) >> 24) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0)) & 0x00ff0000) >> 8) | (((__uint32_t )(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x0000ff00) << 8) | (((__uint32_t)(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long) d4 << 0)) & 0x000000ff) << 24))) : _OSSwapInt32(((long) d1 << 24) | ((long) d2 << 16) | ((long) d3 << 8) | ((long ) d4 << 0))); |
900 | sin->sin_family = AF_INET2; |
901 | #ifdef HAVE_SOCKADDR_SA_LEN1 |
902 | sin->sin_len = sizeof(*sin); |
903 | #endif |
904 | return 4; |
905 | } |
906 | memset(&hints, 0, sizeof(hints))((__builtin_object_size (&hints, 0) != (size_t) -1) ? __builtin___memset_chk (&hints, 0, sizeof(hints), __builtin_object_size (&hints , 0)) : __inline_memset_chk (&hints, 0, sizeof(hints))); |
907 | hints.ai_family = af; |
908 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
909 | ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); |
910 | error = getaddrinfo(name, NULL((void*)0), &hints, &res); |
911 | #if defined(__digital__) && defined(__unix__) |
912 | if (error == EAI_NONAME8 && af == AF_UNSPEC0) { |
913 | /* On Tru64 V5.1, numeric-to-addr conversion fails |
914 | if no address family is given. Assume IPv4 for now.*/ |
915 | hints.ai_family = AF_INET2; |
916 | error = getaddrinfo(name, NULL((void*)0), &hints, &res); |
917 | } |
918 | #endif |
919 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
920 | RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); /* see comment in setipaddr() */ |
921 | if (error) { |
922 | set_gaierror(error); |
923 | return -1; |
924 | } |
925 | if (res->ai_addrlen < addr_ret_size) |
926 | addr_ret_size = res->ai_addrlen; |
927 | memcpy((char *) addr_ret, res->ai_addr, addr_ret_size)((__builtin_object_size ((char *) addr_ret, 0) != (size_t) -1 ) ? __builtin___memcpy_chk ((char *) addr_ret, res->ai_addr , addr_ret_size, __builtin_object_size ((char *) addr_ret, 0) ) : __inline_memcpy_chk ((char *) addr_ret, res->ai_addr, addr_ret_size )); |
928 | freeaddrinfo(res); |
929 | switch (addr_ret->sa_family) { |
930 | case AF_INET2: |
931 | return 4; |
932 | #ifdef ENABLE_IPV61 |
933 | case AF_INET630: |
934 | return 16; |
935 | #endif |
936 | default: |
937 | PyErr_SetString(socket_error, "unknown address family"); |
938 | return -1; |
939 | } |
940 | } |
941 | |
942 | |
943 | /* Create a string object representing an IP address. |
944 | This is always a string of the form 'dd.dd.dd.dd' (with variable |
945 | size numbers). */ |
946 | |
947 | static PyObject * |
948 | makeipaddr(struct sockaddr *addr, int addrlen) |
949 | { |
950 | char buf[NI_MAXHOST1025]; |
951 | int error; |
952 | |
953 | error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL((void*)0), 0, |
954 | NI_NUMERICHOST0x00000002); |
955 | if (error) { |
956 | set_gaierror(error); |
957 | return NULL((void*)0); |
958 | } |
959 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(buf); |
960 | } |
961 | |
962 | |
963 | #ifdef USE_BLUETOOTH |
964 | /* Convert a string representation of a Bluetooth address into a numeric |
965 | address. Returns the length (6), or raises an exception and returns -1 if |
966 | an error occurred. */ |
967 | |
968 | static int |
969 | setbdaddr(char *name, bdaddr_t *bdaddr) |
970 | { |
971 | unsigned int b0, b1, b2, b3, b4, b5; |
972 | char ch; |
973 | int n; |
974 | |
975 | n = sscanf(name, "%X:%X:%X:%X:%X:%X%c", |
976 | &b5, &b4, &b3, &b2, &b1, &b0, &ch); |
977 | if (n == 6 && (b0 | b1 | b2 | b3 | b4 | b5) < 256) { |
978 | bdaddr->b[0] = b0; |
979 | bdaddr->b[1] = b1; |
980 | bdaddr->b[2] = b2; |
981 | bdaddr->b[3] = b3; |
982 | bdaddr->b[4] = b4; |
983 | bdaddr->b[5] = b5; |
984 | return 6; |
985 | } else { |
986 | PyErr_SetString(socket_error, "bad bluetooth address"); |
987 | return -1; |
988 | } |
989 | } |
990 | |
991 | /* Create a string representation of the Bluetooth address. This is always a |
992 | string of the form 'XX:XX:XX:XX:XX:XX' where XX is a two digit hexadecimal |
993 | value (zero padded if necessary). */ |
994 | |
995 | static PyObject * |
996 | makebdaddr(bdaddr_t *bdaddr) |
997 | { |
998 | char buf[(6 * 2) + 5 + 1]; |
999 | |
1000 | sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",__builtin___sprintf_chk (buf, 0, __builtin_object_size (buf, 2 > 1), "%02X:%02X:%02X:%02X:%02X:%02X", bdaddr->b[5], bdaddr ->b[4], bdaddr->b[3], bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]) |
1001 | bdaddr->b[5], bdaddr->b[4], bdaddr->b[3],__builtin___sprintf_chk (buf, 0, __builtin_object_size (buf, 2 > 1), "%02X:%02X:%02X:%02X:%02X:%02X", bdaddr->b[5], bdaddr ->b[4], bdaddr->b[3], bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]) |
1002 | bdaddr->b[2], bdaddr->b[1], bdaddr->b[0])__builtin___sprintf_chk (buf, 0, __builtin_object_size (buf, 2 > 1), "%02X:%02X:%02X:%02X:%02X:%02X", bdaddr->b[5], bdaddr ->b[4], bdaddr->b[3], bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]); |
1003 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(buf); |
1004 | } |
1005 | #endif |
1006 | |
1007 | |
1008 | /* Create an object representing the given socket address, |
1009 | suitable for passing it back to bind(), connect() etc. |
1010 | The family field of the sockaddr structure is inspected |
1011 | to determine what kind of address it really is. */ |
1012 | |
1013 | /*ARGSUSED*/ |
1014 | static PyObject * |
1015 | makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) |
1016 | { |
1017 | if (addrlen == 0) { |
1018 | /* No address -- may be recvfrom() from known socket */ |
1019 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1020 | return Py_None(&_Py_NoneStruct); |
1021 | } |
1022 | |
1023 | switch (addr->sa_family) { |
1024 | |
1025 | case AF_INET2: |
1026 | { |
1027 | struct sockaddr_in *a; |
1028 | PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
1029 | PyObject *ret = NULL((void*)0); |
1030 | if (addrobj) { |
1031 | a = (struct sockaddr_in *)addr; |
1032 | ret = Py_BuildValue("Oi", addrobj, ntohs(a->sin_port)(__builtin_constant_p(a->sin_port) ? ((__uint16_t)((((__uint16_t )(a->sin_port) & 0xff00) >> 8) | (((__uint16_t)( a->sin_port) & 0x00ff) << 8))) : _OSSwapInt16(a-> sin_port))); |
1033 | Py_DECREF(addrobj)do { if (_Py_RefTotal-- , --((PyObject*)(addrobj))->ob_refcnt != 0) { if (((PyObject*)addrobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1033 , (PyObject *)(addrobj)); } else _Py_Dealloc((PyObject *)(addrobj )); } while (0); |
1034 | } |
1035 | return ret; |
1036 | } |
1037 | |
1038 | #if defined(AF_UNIX1) |
1039 | case AF_UNIX1: |
1040 | { |
1041 | struct sockaddr_un *a = (struct sockaddr_un *) addr; |
1042 | #ifdef linux |
1043 | if (a->sun_path[0] == 0) { /* Linux abstract namespace */ |
1044 | addrlen -= offsetof(struct sockaddr_un, sun_path)__builtin_offsetof(struct sockaddr_un, sun_path); |
1045 | return PyBytes_FromStringAndSize(a->sun_path, addrlen); |
1046 | } |
1047 | else |
1048 | #endif /* linux */ |
1049 | { |
1050 | /* regular NULL-terminated string */ |
1051 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(a->sun_path); |
1052 | } |
1053 | } |
1054 | #endif /* AF_UNIX */ |
1055 | |
1056 | #if defined(AF_NETLINK) |
1057 | case AF_NETLINK: |
1058 | { |
1059 | struct sockaddr_nl *a = (struct sockaddr_nl *) addr; |
1060 | return Py_BuildValue("II", a->nl_pid, a->nl_groups); |
1061 | } |
1062 | #endif /* AF_NETLINK */ |
1063 | |
1064 | #ifdef ENABLE_IPV61 |
1065 | case AF_INET630: |
1066 | { |
1067 | struct sockaddr_in6 *a; |
1068 | PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
1069 | PyObject *ret = NULL((void*)0); |
1070 | if (addrobj) { |
1071 | a = (struct sockaddr_in6 *)addr; |
1072 | ret = Py_BuildValue("Oiii", |
1073 | addrobj, |
1074 | ntohs(a->sin6_port)(__builtin_constant_p(a->sin6_port) ? ((__uint16_t)((((__uint16_t )(a->sin6_port) & 0xff00) >> 8) | (((__uint16_t) (a->sin6_port) & 0x00ff) << 8))) : _OSSwapInt16( a->sin6_port)), |
1075 | a->sin6_flowinfo, |
1076 | a->sin6_scope_id); |
1077 | Py_DECREF(addrobj)do { if (_Py_RefTotal-- , --((PyObject*)(addrobj))->ob_refcnt != 0) { if (((PyObject*)addrobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1077 , (PyObject *)(addrobj)); } else _Py_Dealloc((PyObject *)(addrobj )); } while (0); |
1078 | } |
1079 | return ret; |
1080 | } |
1081 | #endif |
1082 | |
1083 | #ifdef USE_BLUETOOTH |
1084 | case AF_BLUETOOTH: |
1085 | switch (proto) { |
1086 | |
1087 | case BTPROTO_L2CAP: |
1088 | { |
1089 | struct sockaddr_l2 *a = (struct sockaddr_l2 *) addr; |
1090 | PyObject *addrobj = makebdaddr(&_BT_L2_MEMB(a, bdaddr)); |
1091 | PyObject *ret = NULL((void*)0); |
1092 | if (addrobj) { |
1093 | ret = Py_BuildValue("Oi", |
1094 | addrobj, |
1095 | _BT_L2_MEMB(a, psm)); |
1096 | Py_DECREF(addrobj)do { if (_Py_RefTotal-- , --((PyObject*)(addrobj))->ob_refcnt != 0) { if (((PyObject*)addrobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1096 , (PyObject *)(addrobj)); } else _Py_Dealloc((PyObject *)(addrobj )); } while (0); |
1097 | } |
1098 | return ret; |
1099 | } |
1100 | |
1101 | case BTPROTO_RFCOMM: |
1102 | { |
1103 | struct sockaddr_rc *a = (struct sockaddr_rc *) addr; |
1104 | PyObject *addrobj = makebdaddr(&_BT_RC_MEMB(a, bdaddr)); |
1105 | PyObject *ret = NULL((void*)0); |
1106 | if (addrobj) { |
1107 | ret = Py_BuildValue("Oi", |
1108 | addrobj, |
1109 | _BT_RC_MEMB(a, channel)); |
1110 | Py_DECREF(addrobj)do { if (_Py_RefTotal-- , --((PyObject*)(addrobj))->ob_refcnt != 0) { if (((PyObject*)addrobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1110 , (PyObject *)(addrobj)); } else _Py_Dealloc((PyObject *)(addrobj )); } while (0); |
1111 | } |
1112 | return ret; |
1113 | } |
1114 | |
1115 | case BTPROTO_HCI: |
1116 | { |
1117 | struct sockaddr_hci *a = (struct sockaddr_hci *) addr; |
1118 | #if defined(__NetBSD__) || defined(__DragonFly__) |
1119 | return makebdaddr(&_BT_HCI_MEMB(a, bdaddr)); |
1120 | #else |
1121 | PyObject *ret = NULL((void*)0); |
1122 | ret = Py_BuildValue("i", _BT_HCI_MEMB(a, dev)); |
1123 | return ret; |
1124 | #endif |
1125 | } |
1126 | |
1127 | #if !defined(__FreeBSD__) |
1128 | case BTPROTO_SCO: |
1129 | { |
1130 | struct sockaddr_sco *a = (struct sockaddr_sco *) addr; |
1131 | return makebdaddr(&_BT_SCO_MEMB(a, bdaddr)); |
1132 | } |
1133 | #endif |
1134 | |
1135 | default: |
1136 | PyErr_SetString(PyExc_ValueError, |
1137 | "Unknown Bluetooth protocol"); |
1138 | return NULL((void*)0); |
1139 | } |
1140 | #endif |
1141 | |
1142 | #if defined(HAVE_NETPACKET_PACKET_H) && defined(SIOCGIFNAME) |
1143 | case AF_PACKET: |
1144 | { |
1145 | struct sockaddr_ll *a = (struct sockaddr_ll *)addr; |
1146 | char *ifname = ""; |
1147 | struct ifreq ifr; |
1148 | /* need to look up interface name give index */ |
1149 | if (a->sll_ifindex) { |
1150 | ifr.ifr_ifindex = a->sll_ifindex; |
1151 | if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) |
1152 | ifname = ifr.ifr_name; |
1153 | } |
1154 | return Py_BuildValue("shbhy#", |
1155 | ifname, |
1156 | ntohs(a->sll_protocol)(__builtin_constant_p(a->sll_protocol) ? ((__uint16_t)(((( __uint16_t)(a->sll_protocol) & 0xff00) >> 8) | ( ((__uint16_t)(a->sll_protocol) & 0x00ff) << 8))) : _OSSwapInt16(a->sll_protocol)), |
1157 | a->sll_pkttype, |
1158 | a->sll_hatype, |
1159 | a->sll_addr, |
1160 | a->sll_halen); |
1161 | } |
1162 | #endif |
1163 | |
1164 | #ifdef HAVE_LINUX_TIPC_H |
1165 | case AF_TIPC: |
1166 | { |
1167 | struct sockaddr_tipc *a = (struct sockaddr_tipc *) addr; |
1168 | if (a->addrtype == TIPC_ADDR_NAMESEQ) { |
1169 | return Py_BuildValue("IIIII", |
1170 | a->addrtype, |
1171 | a->addr.nameseq.type, |
1172 | a->addr.nameseq.lower, |
1173 | a->addr.nameseq.upper, |
1174 | a->scope); |
1175 | } else if (a->addrtype == TIPC_ADDR_NAME) { |
1176 | return Py_BuildValue("IIIII", |
1177 | a->addrtype, |
1178 | a->addr.name.name.type, |
1179 | a->addr.name.name.instance, |
1180 | a->addr.name.name.instance, |
1181 | a->scope); |
1182 | } else if (a->addrtype == TIPC_ADDR_ID) { |
1183 | return Py_BuildValue("IIIII", |
1184 | a->addrtype, |
1185 | a->addr.id.node, |
1186 | a->addr.id.ref, |
1187 | 0, |
1188 | a->scope); |
1189 | } else { |
1190 | PyErr_SetString(PyExc_ValueError, |
1191 | "Invalid address type"); |
1192 | return NULL((void*)0); |
1193 | } |
1194 | } |
1195 | #endif |
1196 | |
1197 | /* More cases here... */ |
1198 | |
1199 | default: |
1200 | /* If we don't know the address family, don't raise an |
1201 | exception -- return it as an (int, bytes) tuple. */ |
1202 | return Py_BuildValue("iy#", |
1203 | addr->sa_family, |
1204 | addr->sa_data, |
1205 | sizeof(addr->sa_data)); |
1206 | |
1207 | } |
1208 | } |
1209 | |
1210 | |
1211 | /* Parse a socket address argument according to the socket object's |
1212 | address family. Return 1 if the address was in the proper format, |
1213 | 0 of not. The address is returned through addr_ret, its length |
1214 | through len_ret. */ |
1215 | |
1216 | static int |
1217 | getsockaddrarg(PySocketSockObject *s, PyObject *args, |
1218 | struct sockaddr *addr_ret, int *len_ret) |
1219 | { |
1220 | switch (s->sock_family) { |
1221 | |
1222 | #if defined(AF_UNIX1) |
1223 | case AF_UNIX1: |
1224 | { |
1225 | struct sockaddr_un* addr; |
1226 | char *path; |
1227 | int len; |
1228 | if (!PyArg_Parse(args, "s#", &path, &len)) |
1229 | return 0; |
1230 | |
1231 | addr = (struct sockaddr_un*)addr_ret; |
1232 | #ifdef linux |
1233 | if (len > 0 && path[0] == 0) { |
1234 | /* Linux abstract namespace extension */ |
1235 | if (len > sizeof addr->sun_path) { |
1236 | PyErr_SetString(socket_error, |
1237 | "AF_UNIX path too long"); |
1238 | return 0; |
1239 | } |
1240 | } |
1241 | else |
1242 | #endif /* linux */ |
1243 | { |
1244 | /* regular NULL-terminated string */ |
1245 | if (len >= sizeof addr->sun_path) { |
1246 | PyErr_SetString(socket_error, |
1247 | "AF_UNIX path too long"); |
1248 | return 0; |
1249 | } |
1250 | addr->sun_path[len] = 0; |
1251 | } |
1252 | addr->sun_family = s->sock_family; |
1253 | memcpy(addr->sun_path, path, len)((__builtin_object_size (addr->sun_path, 0) != (size_t) -1 ) ? __builtin___memcpy_chk (addr->sun_path, path, len, __builtin_object_size (addr->sun_path, 0)) : __inline_memcpy_chk (addr->sun_path , path, len)); |
1254 | #if defined(PYOS_OS2) |
1255 | *len_ret = sizeof(*addr); |
1256 | #else |
1257 | *len_ret = len + offsetof(struct sockaddr_un, sun_path)__builtin_offsetof(struct sockaddr_un, sun_path); |
1258 | #endif |
1259 | return 1; |
1260 | } |
1261 | #endif /* AF_UNIX */ |
1262 | |
1263 | #if defined(AF_NETLINK) |
1264 | case AF_NETLINK: |
1265 | { |
1266 | struct sockaddr_nl* addr; |
1267 | int pid, groups; |
1268 | addr = (struct sockaddr_nl *)addr_ret; |
1269 | if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<26))) != 0)) { |
1270 | PyErr_Format( |
1271 | PyExc_TypeError, |
1272 | "getsockaddrarg: " |
1273 | "AF_NETLINK address must be tuple, not %.500s", |
1274 | Py_TYPE(args)(((PyObject*)(args))->ob_type)->tp_name); |
1275 | return 0; |
1276 | } |
1277 | if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups)) |
1278 | return 0; |
1279 | addr->nl_family = AF_NETLINK; |
1280 | addr->nl_pid = pid; |
1281 | addr->nl_groups = groups; |
1282 | *len_ret = sizeof(*addr); |
1283 | return 1; |
1284 | } |
1285 | #endif |
1286 | |
1287 | case AF_INET2: |
1288 | { |
1289 | struct sockaddr_in* addr; |
1290 | char *host; |
1291 | int port, result; |
1292 | if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<26))) != 0)) { |
1293 | PyErr_Format( |
1294 | PyExc_TypeError, |
1295 | "getsockaddrarg: " |
1296 | "AF_INET address must be tuple, not %.500s", |
1297 | Py_TYPE(args)(((PyObject*)(args))->ob_type)->tp_name); |
1298 | return 0; |
1299 | } |
1300 | if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", |
1301 | "idna", &host, &port)) |
1302 | return 0; |
1303 | addr=(struct sockaddr_in*)addr_ret; |
1304 | result = setipaddr(host, (struct sockaddr *)addr, |
1305 | sizeof(*addr), AF_INET2); |
1306 | PyMem_Free(host); |
1307 | if (result < 0) |
1308 | return 0; |
1309 | if (port < 0 || port > 0xffff) { |
1310 | PyErr_SetString( |
1311 | PyExc_OverflowError, |
1312 | "getsockaddrarg: port must be 0-65535."); |
1313 | return 0; |
1314 | } |
1315 | addr->sin_family = AF_INET2; |
1316 | addr->sin_port = htons((short)port)(__builtin_constant_p((short)port) ? ((__uint16_t)((((__uint16_t )((short)port) & 0xff00) >> 8) | (((__uint16_t)((short )port) & 0x00ff) << 8))) : _OSSwapInt16((short)port )); |
1317 | *len_ret = sizeof *addr; |
1318 | return 1; |
1319 | } |
1320 | |
1321 | #ifdef ENABLE_IPV61 |
1322 | case AF_INET630: |
1323 | { |
1324 | struct sockaddr_in6* addr; |
1325 | char *host; |
1326 | int port, flowinfo, scope_id, result; |
1327 | flowinfo = scope_id = 0; |
1328 | if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<26))) != 0)) { |
1329 | PyErr_Format( |
1330 | PyExc_TypeError, |
1331 | "getsockaddrarg: " |
1332 | "AF_INET6 address must be tuple, not %.500s", |
1333 | Py_TYPE(args)(((PyObject*)(args))->ob_type)->tp_name); |
1334 | return 0; |
1335 | } |
1336 | if (!PyArg_ParseTuple(args, "eti|ii", |
1337 | "idna", &host, &port, &flowinfo, |
1338 | &scope_id)) { |
1339 | return 0; |
1340 | } |
1341 | addr = (struct sockaddr_in6*)addr_ret; |
1342 | result = setipaddr(host, (struct sockaddr *)addr, |
1343 | sizeof(*addr), AF_INET630); |
1344 | PyMem_Free(host); |
1345 | if (result < 0) |
1346 | return 0; |
1347 | if (port < 0 || port > 0xffff) { |
1348 | PyErr_SetString( |
1349 | PyExc_OverflowError, |
1350 | "getsockaddrarg: port must be 0-65535."); |
1351 | return 0; |
1352 | } |
1353 | addr->sin6_family = s->sock_family; |
1354 | addr->sin6_port = htons((short)port)(__builtin_constant_p((short)port) ? ((__uint16_t)((((__uint16_t )((short)port) & 0xff00) >> 8) | (((__uint16_t)((short )port) & 0x00ff) << 8))) : _OSSwapInt16((short)port )); |
1355 | addr->sin6_flowinfo = flowinfo; |
1356 | addr->sin6_scope_id = scope_id; |
1357 | *len_ret = sizeof *addr; |
1358 | return 1; |
1359 | } |
1360 | #endif |
1361 | |
1362 | #ifdef USE_BLUETOOTH |
1363 | case AF_BLUETOOTH: |
1364 | { |
1365 | switch (s->sock_proto) { |
1366 | case BTPROTO_L2CAP: |
1367 | { |
1368 | struct sockaddr_l2 *addr; |
1369 | char *straddr; |
1370 | |
1371 | addr = (struct sockaddr_l2 *)addr_ret; |
1372 | memset(addr, 0, sizeof(struct sockaddr_l2))((__builtin_object_size (addr, 0) != (size_t) -1) ? __builtin___memset_chk (addr, 0, sizeof(struct sockaddr_l2), __builtin_object_size ( addr, 0)) : __inline_memset_chk (addr, 0, sizeof(struct sockaddr_l2 ))); |
1373 | _BT_L2_MEMB(addr, family) = AF_BLUETOOTH; |
1374 | if (!PyArg_ParseTuple(args, "si", &straddr, |
1375 | &_BT_L2_MEMB(addr, psm))) { |
1376 | PyErr_SetString(socket_error, "getsockaddrarg: " |
1377 | "wrong format"); |
1378 | return 0; |
1379 | } |
1380 | if (setbdaddr(straddr, &_BT_L2_MEMB(addr, bdaddr)) < 0) |
1381 | return 0; |
1382 | |
1383 | *len_ret = sizeof *addr; |
1384 | return 1; |
1385 | } |
1386 | case BTPROTO_RFCOMM: |
1387 | { |
1388 | struct sockaddr_rc *addr; |
1389 | char *straddr; |
1390 | |
1391 | addr = (struct sockaddr_rc *)addr_ret; |
1392 | _BT_RC_MEMB(addr, family) = AF_BLUETOOTH; |
1393 | if (!PyArg_ParseTuple(args, "si", &straddr, |
1394 | &_BT_RC_MEMB(addr, channel))) { |
1395 | PyErr_SetString(socket_error, "getsockaddrarg: " |
1396 | "wrong format"); |
1397 | return 0; |
1398 | } |
1399 | if (setbdaddr(straddr, &_BT_RC_MEMB(addr, bdaddr)) < 0) |
1400 | return 0; |
1401 | |
1402 | *len_ret = sizeof *addr; |
1403 | return 1; |
1404 | } |
1405 | case BTPROTO_HCI: |
1406 | { |
1407 | struct sockaddr_hci *addr = (struct sockaddr_hci *)addr_ret; |
1408 | #if defined(__NetBSD__) || defined(__DragonFly__) |
1409 | char *straddr = PyBytes_AS_STRING(args)((__builtin_expect(!(((((((PyObject*)(args))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1409 , "PyBytes_Check(args)") : (void)0), (((PyBytesObject *)(args ))->ob_sval)); |
1410 | |
1411 | _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH; |
1412 | if (straddr == NULL((void*)0)) { |
1413 | PyErr_SetString(socket_error, "getsockaddrarg: " |
1414 | "wrong format"); |
1415 | return 0; |
1416 | } |
1417 | if (setbdaddr(straddr, &_BT_HCI_MEMB(addr, bdaddr)) < 0) |
1418 | return 0; |
1419 | #else |
1420 | _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH; |
1421 | if (!PyArg_ParseTuple(args, "i", &_BT_HCI_MEMB(addr, dev))) { |
1422 | PyErr_SetString(socket_error, "getsockaddrarg: " |
1423 | "wrong format"); |
1424 | return 0; |
1425 | } |
1426 | #endif |
1427 | *len_ret = sizeof *addr; |
1428 | return 1; |
1429 | } |
1430 | #if !defined(__FreeBSD__) |
1431 | case BTPROTO_SCO: |
1432 | { |
1433 | struct sockaddr_sco *addr; |
1434 | char *straddr; |
1435 | |
1436 | addr = (struct sockaddr_sco *)addr_ret; |
1437 | _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; |
1438 | if (!PyBytes_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<27))) != 0)) { |
1439 | PyErr_SetString(socket_error, "getsockaddrarg: " |
1440 | "wrong format"); |
1441 | return 0; |
1442 | } |
1443 | straddr = PyBytes_AS_STRING(args)((__builtin_expect(!(((((((PyObject*)(args))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1443 , "PyBytes_Check(args)") : (void)0), (((PyBytesObject *)(args ))->ob_sval)); |
1444 | if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0) |
1445 | return 0; |
1446 | |
1447 | *len_ret = sizeof *addr; |
1448 | return 1; |
1449 | } |
1450 | #endif |
1451 | default: |
1452 | PyErr_SetString(socket_error, "getsockaddrarg: unknown Bluetooth protocol"); |
1453 | return 0; |
1454 | } |
1455 | } |
1456 | #endif |
1457 | |
1458 | #if defined(HAVE_NETPACKET_PACKET_H) && defined(SIOCGIFINDEX) |
1459 | case AF_PACKET: |
1460 | { |
1461 | struct sockaddr_ll* addr; |
1462 | struct ifreq ifr; |
1463 | char *interfaceName; |
1464 | int protoNumber; |
1465 | int hatype = 0; |
1466 | int pkttype = 0; |
1467 | char *haddr = NULL((void*)0); |
1468 | unsigned int halen = 0; |
1469 | |
1470 | if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<26))) != 0)) { |
1471 | PyErr_Format( |
1472 | PyExc_TypeError, |
1473 | "getsockaddrarg: " |
1474 | "AF_PACKET address must be tuple, not %.500s", |
1475 | Py_TYPE(args)(((PyObject*)(args))->ob_type)->tp_name); |
1476 | return 0; |
1477 | } |
1478 | if (!PyArg_ParseTuple(args, "si|iiy#", &interfaceName, |
1479 | &protoNumber, &pkttype, &hatype, |
1480 | &haddr, &halen)) |
1481 | return 0; |
1482 | strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name))((__builtin_object_size (ifr.ifr_name, 0) != (size_t) -1) ? __builtin___strncpy_chk (ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name), __builtin_object_size (ifr.ifr_name, 2 > 1)) : __inline_strncpy_chk (ifr.ifr_name , interfaceName, sizeof(ifr.ifr_name))); |
1483 | ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; |
1484 | if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { |
1485 | s->errorhandler(); |
1486 | return 0; |
1487 | } |
1488 | if (halen > 8) { |
1489 | PyErr_SetString(PyExc_ValueError, |
1490 | "Hardware address must be 8 bytes or less"); |
1491 | return 0; |
1492 | } |
1493 | if (protoNumber < 0 || protoNumber > 0xffff) { |
1494 | PyErr_SetString( |
1495 | PyExc_OverflowError, |
1496 | "getsockaddrarg: protoNumber must be 0-65535."); |
1497 | return 0; |
1498 | } |
1499 | addr = (struct sockaddr_ll*)addr_ret; |
1500 | addr->sll_family = AF_PACKET; |
1501 | addr->sll_protocol = htons((short)protoNumber)(__builtin_constant_p((short)protoNumber) ? ((__uint16_t)(((( __uint16_t)((short)protoNumber) & 0xff00) >> 8) | ( ((__uint16_t)((short)protoNumber) & 0x00ff) << 8))) : _OSSwapInt16((short)protoNumber)); |
1502 | addr->sll_ifindex = ifr.ifr_ifindex; |
1503 | addr->sll_pkttype = pkttype; |
1504 | addr->sll_hatype = hatype; |
1505 | if (halen != 0) { |
1506 | memcpy(&addr->sll_addr, haddr, halen)((__builtin_object_size (&addr->sll_addr, 0) != (size_t ) -1) ? __builtin___memcpy_chk (&addr->sll_addr, haddr , halen, __builtin_object_size (&addr->sll_addr, 0)) : __inline_memcpy_chk (&addr->sll_addr, haddr, halen)); |
1507 | } |
1508 | addr->sll_halen = halen; |
1509 | *len_ret = sizeof *addr; |
1510 | return 1; |
1511 | } |
1512 | #endif |
1513 | |
1514 | #ifdef HAVE_LINUX_TIPC_H |
1515 | case AF_TIPC: |
1516 | { |
1517 | unsigned int atype, v1, v2, v3; |
1518 | unsigned int scope = TIPC_CLUSTER_SCOPE; |
1519 | struct sockaddr_tipc *addr; |
1520 | |
1521 | if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L <<26))) != 0)) { |
1522 | PyErr_Format( |
1523 | PyExc_TypeError, |
1524 | "getsockaddrarg: " |
1525 | "AF_TIPC address must be tuple, not %.500s", |
1526 | Py_TYPE(args)(((PyObject*)(args))->ob_type)->tp_name); |
1527 | return 0; |
1528 | } |
1529 | |
1530 | if (!PyArg_ParseTuple(args, |
1531 | "IIII|I;Invalid TIPC address format", |
1532 | &atype, &v1, &v2, &v3, &scope)) |
1533 | return 0; |
1534 | |
1535 | addr = (struct sockaddr_tipc *) addr_ret; |
1536 | memset(addr, 0, sizeof(struct sockaddr_tipc))((__builtin_object_size (addr, 0) != (size_t) -1) ? __builtin___memset_chk (addr, 0, sizeof(struct sockaddr_tipc), __builtin_object_size (addr, 0)) : __inline_memset_chk (addr, 0, sizeof(struct sockaddr_tipc ))); |
1537 | |
1538 | addr->family = AF_TIPC; |
1539 | addr->scope = scope; |
1540 | addr->addrtype = atype; |
1541 | |
1542 | if (atype == TIPC_ADDR_NAMESEQ) { |
1543 | addr->addr.nameseq.type = v1; |
1544 | addr->addr.nameseq.lower = v2; |
1545 | addr->addr.nameseq.upper = v3; |
1546 | } else if (atype == TIPC_ADDR_NAME) { |
1547 | addr->addr.name.name.type = v1; |
1548 | addr->addr.name.name.instance = v2; |
1549 | } else if (atype == TIPC_ADDR_ID) { |
1550 | addr->addr.id.node = v1; |
1551 | addr->addr.id.ref = v2; |
1552 | } else { |
1553 | /* Shouldn't happen */ |
1554 | PyErr_SetString(PyExc_TypeError, "Invalid address type"); |
1555 | return 0; |
1556 | } |
1557 | |
1558 | *len_ret = sizeof(*addr); |
1559 | |
1560 | return 1; |
1561 | } |
1562 | #endif |
1563 | |
1564 | /* More cases here... */ |
1565 | |
1566 | default: |
1567 | PyErr_SetString(socket_error, "getsockaddrarg: bad family"); |
1568 | return 0; |
1569 | |
1570 | } |
1571 | } |
1572 | |
1573 | |
1574 | /* Get the address length according to the socket object's address family. |
1575 | Return 1 if the family is known, 0 otherwise. The length is returned |
1576 | through len_ret. */ |
1577 | |
1578 | static int |
1579 | getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) |
1580 | { |
1581 | switch (s->sock_family) { |
1582 | |
1583 | #if defined(AF_UNIX1) |
1584 | case AF_UNIX1: |
1585 | { |
1586 | *len_ret = sizeof (struct sockaddr_un); |
1587 | return 1; |
1588 | } |
1589 | #endif /* AF_UNIX */ |
1590 | #if defined(AF_NETLINK) |
1591 | case AF_NETLINK: |
1592 | { |
1593 | *len_ret = sizeof (struct sockaddr_nl); |
1594 | return 1; |
1595 | } |
1596 | #endif |
1597 | |
1598 | case AF_INET2: |
1599 | { |
1600 | *len_ret = sizeof (struct sockaddr_in); |
1601 | return 1; |
1602 | } |
1603 | |
1604 | #ifdef ENABLE_IPV61 |
1605 | case AF_INET630: |
1606 | { |
1607 | *len_ret = sizeof (struct sockaddr_in6); |
1608 | return 1; |
1609 | } |
1610 | #endif |
1611 | |
1612 | #ifdef USE_BLUETOOTH |
1613 | case AF_BLUETOOTH: |
1614 | { |
1615 | switch(s->sock_proto) |
1616 | { |
1617 | |
1618 | case BTPROTO_L2CAP: |
1619 | *len_ret = sizeof (struct sockaddr_l2); |
1620 | return 1; |
1621 | case BTPROTO_RFCOMM: |
1622 | *len_ret = sizeof (struct sockaddr_rc); |
1623 | return 1; |
1624 | case BTPROTO_HCI: |
1625 | *len_ret = sizeof (struct sockaddr_hci); |
1626 | return 1; |
1627 | #if !defined(__FreeBSD__) |
1628 | case BTPROTO_SCO: |
1629 | *len_ret = sizeof (struct sockaddr_sco); |
1630 | return 1; |
1631 | #endif |
1632 | default: |
1633 | PyErr_SetString(socket_error, "getsockaddrlen: " |
1634 | "unknown BT protocol"); |
1635 | return 0; |
1636 | |
1637 | } |
1638 | } |
1639 | #endif |
1640 | |
1641 | #ifdef HAVE_NETPACKET_PACKET_H |
1642 | case AF_PACKET: |
1643 | { |
1644 | *len_ret = sizeof (struct sockaddr_ll); |
1645 | return 1; |
1646 | } |
1647 | #endif |
1648 | |
1649 | #ifdef HAVE_LINUX_TIPC_H |
1650 | case AF_TIPC: |
1651 | { |
1652 | *len_ret = sizeof (struct sockaddr_tipc); |
1653 | return 1; |
1654 | } |
1655 | #endif |
1656 | |
1657 | /* More cases here... */ |
1658 | |
1659 | default: |
1660 | PyErr_SetString(socket_error, "getsockaddrlen: bad family"); |
1661 | return 0; |
1662 | |
1663 | } |
1664 | } |
1665 | |
1666 | |
1667 | /* s._accept() -> (fd, address) */ |
1668 | |
1669 | static PyObject * |
1670 | sock_accept(PySocketSockObject *s) |
1671 | { |
1672 | sock_addr_t addrbuf; |
1673 | SOCKET_T newfd = INVALID_SOCKET(-1); |
1674 | socklen_t addrlen; |
1675 | PyObject *sock = NULL((void*)0); |
1676 | PyObject *addr = NULL((void*)0); |
1677 | PyObject *res = NULL((void*)0); |
1678 | int timeout; |
1679 | if (!getsockaddrlen(s, &addrlen)) |
1680 | return NULL((void*)0); |
1681 | memset(&addrbuf, 0, addrlen)((__builtin_object_size (&addrbuf, 0) != (size_t) -1) ? __builtin___memset_chk (&addrbuf, 0, addrlen, __builtin_object_size (&addrbuf , 0)) : __inline_memset_chk (&addrbuf, 0, addrlen)); |
1682 | |
1683 | if (!IS_SELECTABLE(s)1) |
1684 | return select_error(); |
1685 | |
1686 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
1687 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
1688 | timeout = internal_select_ex(s, 0, interval); |
1689 | if (!timeout) { |
1690 | newfd = accept(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen); |
1691 | } |
1692 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
1693 | |
1694 | if (timeout == 1) { |
1695 | PyErr_SetString(socket_timeout, "timed out"); |
1696 | return NULL((void*)0); |
1697 | } |
1698 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
1699 | |
1700 | if (newfd == INVALID_SOCKET(-1)) |
1701 | return s->errorhandler(); |
1702 | |
1703 | sock = PyLong_FromSocket_t(newfd)PyLong_FromLong((SOCKET_T)(newfd)); |
1704 | if (sock == NULL((void*)0)) { |
1705 | SOCKETCLOSEclose(newfd); |
1706 | goto finally; |
1707 | } |
1708 | |
1709 | addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), |
1710 | addrlen, s->sock_proto); |
1711 | if (addr == NULL((void*)0)) |
1712 | goto finally; |
1713 | |
1714 | res = PyTuple_Pack(2, sock, addr); |
1715 | |
1716 | finally: |
1717 | Py_XDECREF(sock)do { if ((sock) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(sock))->ob_refcnt != 0) { if (((PyObject *)sock)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 1717, (PyObject *)(sock)); } else _Py_Dealloc((PyObject *)( sock)); } while (0); } while (0); |
1718 | Py_XDECREF(addr)do { if ((addr) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(addr))->ob_refcnt != 0) { if (((PyObject *)addr)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 1718, (PyObject *)(addr)); } else _Py_Dealloc((PyObject *)( addr)); } while (0); } while (0); |
1719 | return res; |
1720 | } |
1721 | |
1722 | PyDoc_STRVAR(accept_doc,static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)." |
1723 | "_accept() -> (integer, address info)\n\static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)." |
1724 | \n\static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)." |
1725 | Wait for an incoming connection. Return a new socket file descriptor\n\static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)." |
1726 | representing the connection, and the address of the client.\n\static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)." |
1727 | For IP sockets, the address info is a pair (hostaddr, port).")static char accept_doc[] = "_accept() -> (integer, address info)\n\nWait for an incoming connection. Return a new socket file descriptor\nrepresenting the connection, and the address of the client.\nFor IP sockets, the address info is a pair (hostaddr, port)."; |
1728 | |
1729 | /* s.setblocking(flag) method. Argument: |
1730 | False -- non-blocking mode; same as settimeout(0) |
1731 | True -- blocking mode; same as settimeout(None) |
1732 | */ |
1733 | |
1734 | static PyObject * |
1735 | sock_setblocking(PySocketSockObject *s, PyObject *arg) |
1736 | { |
1737 | int block; |
1738 | |
1739 | block = PyLong_AsLong(arg); |
1740 | if (block == -1 && PyErr_Occurred()) |
1741 | return NULL((void*)0); |
1742 | |
1743 | s->sock_timeout = block ? -1.0 : 0.0; |
1744 | internal_setblocking(s, block); |
1745 | |
1746 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1747 | return Py_None(&_Py_NoneStruct); |
1748 | } |
1749 | |
1750 | PyDoc_STRVAR(setblocking_doc,static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)." |
1751 | "setblocking(flag)\n\static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)." |
1752 | \n\static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)." |
1753 | Set the socket to blocking (flag is true) or non-blocking (false).\n\static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)." |
1754 | setblocking(True) is equivalent to settimeout(None);\n\static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)." |
1755 | setblocking(False) is equivalent to settimeout(0.0).")static char setblocking_doc[] = "setblocking(flag)\n\nSet the socket to blocking (flag is true) or non-blocking (false).\nsetblocking(True) is equivalent to settimeout(None);\nsetblocking(False) is equivalent to settimeout(0.0)."; |
1756 | |
1757 | /* s.settimeout(timeout) method. Argument: |
1758 | None -- no timeout, blocking mode; same as setblocking(True) |
1759 | 0.0 -- non-blocking mode; same as setblocking(False) |
1760 | > 0 -- timeout mode; operations time out after timeout seconds |
1761 | < 0 -- illegal; raises an exception |
1762 | */ |
1763 | static PyObject * |
1764 | sock_settimeout(PySocketSockObject *s, PyObject *arg) |
1765 | { |
1766 | double timeout; |
1767 | |
1768 | if (arg == Py_None(&_Py_NoneStruct)) |
1769 | timeout = -1.0; |
1770 | else { |
1771 | timeout = PyFloat_AsDouble(arg); |
1772 | if (timeout < 0.0) { |
1773 | if (!PyErr_Occurred()) |
1774 | PyErr_SetString(PyExc_ValueError, |
1775 | "Timeout value out of range"); |
1776 | return NULL((void*)0); |
1777 | } |
1778 | } |
1779 | |
1780 | s->sock_timeout = timeout; |
1781 | internal_setblocking(s, timeout < 0.0); |
1782 | |
1783 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1784 | return Py_None(&_Py_NoneStruct); |
1785 | } |
1786 | |
1787 | PyDoc_STRVAR(settimeout_doc,static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1788 | "settimeout(timeout)\n\static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1789 | \n\static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1790 | Set a timeout on socket operations. 'timeout' can be a float,\n\static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1791 | giving in seconds, or None. Setting a timeout of None disables\n\static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1792 | the timeout feature and is equivalent to setblocking(1).\n\static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)." |
1793 | Setting a timeout of zero is the same as setblocking(0).")static char settimeout_doc[] = "settimeout(timeout)\n\nSet a timeout on socket operations. 'timeout' can be a float,\ngiving in seconds, or None. Setting a timeout of None disables\nthe timeout feature and is equivalent to setblocking(1).\nSetting a timeout of zero is the same as setblocking(0)."; |
1794 | |
1795 | /* s.gettimeout() method. |
1796 | Returns the timeout associated with a socket. */ |
1797 | static PyObject * |
1798 | sock_gettimeout(PySocketSockObject *s) |
1799 | { |
1800 | if (s->sock_timeout < 0.0) { |
1801 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1802 | return Py_None(&_Py_NoneStruct); |
1803 | } |
1804 | else |
1805 | return PyFloat_FromDouble(s->sock_timeout); |
1806 | } |
1807 | |
1808 | PyDoc_STRVAR(gettimeout_doc,static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled." |
1809 | "gettimeout() -> timeout\n\static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled." |
1810 | \n\static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled." |
1811 | Returns the timeout in floating seconds associated with socket \n\static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled." |
1812 | operations. A timeout of None indicates that timeouts on socket \n\static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled." |
1813 | operations are disabled.")static char gettimeout_doc[] = "gettimeout() -> timeout\n\nReturns the timeout in floating seconds associated with socket \noperations. A timeout of None indicates that timeouts on socket \noperations are disabled."; |
1814 | |
1815 | /* s.setsockopt() method. |
1816 | With an integer third argument, sets an integer option. |
1817 | With a string third argument, sets an option from a buffer; |
1818 | use optional built-in module 'struct' to encode the string. */ |
1819 | |
1820 | static PyObject * |
1821 | sock_setsockopt(PySocketSockObject *s, PyObject *args) |
1822 | { |
1823 | int level; |
1824 | int optname; |
1825 | int res; |
1826 | char *buf; |
1827 | int buflen; |
1828 | int flag; |
1829 | |
1830 | if (PyArg_ParseTuple(args, "iii:setsockopt", |
1831 | &level, &optname, &flag)) { |
1832 | buf = (char *) &flag; |
1833 | buflen = sizeof flag; |
1834 | } |
1835 | else { |
1836 | PyErr_Clear(); |
1837 | if (!PyArg_ParseTuple(args, "iiy#:setsockopt", |
1838 | &level, &optname, &buf, &buflen)) |
1839 | return NULL((void*)0); |
1840 | } |
1841 | res = setsockopt(s->sock_fd, level, optname, (void *)buf, buflen); |
1842 | if (res < 0) |
1843 | return s->errorhandler(); |
1844 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1845 | return Py_None(&_Py_NoneStruct); |
1846 | } |
1847 | |
1848 | PyDoc_STRVAR(setsockopt_doc,static char setsockopt_doc[] = "setsockopt(level, option, value)\n\nSet a socket option. See the Unix manual for level and option.\nThe value argument can either be an integer or a string." |
1849 | "setsockopt(level, option, value)\n\static char setsockopt_doc[] = "setsockopt(level, option, value)\n\nSet a socket option. See the Unix manual for level and option.\nThe value argument can either be an integer or a string." |
1850 | \n\static char setsockopt_doc[] = "setsockopt(level, option, value)\n\nSet a socket option. See the Unix manual for level and option.\nThe value argument can either be an integer or a string." |
1851 | Set a socket option. See the Unix manual for level and option.\n\static char setsockopt_doc[] = "setsockopt(level, option, value)\n\nSet a socket option. See the Unix manual for level and option.\nThe value argument can either be an integer or a string." |
1852 | The value argument can either be an integer or a string.")static char setsockopt_doc[] = "setsockopt(level, option, value)\n\nSet a socket option. See the Unix manual for level and option.\nThe value argument can either be an integer or a string."; |
1853 | |
1854 | |
1855 | /* s.getsockopt() method. |
1856 | With two arguments, retrieves an integer option. |
1857 | With a third integer argument, retrieves a string buffer of that size; |
1858 | use optional built-in module 'struct' to decode the string. */ |
1859 | |
1860 | static PyObject * |
1861 | sock_getsockopt(PySocketSockObject *s, PyObject *args) |
1862 | { |
1863 | int level; |
1864 | int optname; |
1865 | int res; |
1866 | PyObject *buf; |
1867 | socklen_t buflen = 0; |
1868 | |
1869 | if (!PyArg_ParseTuple(args, "ii|i:getsockopt", |
1870 | &level, &optname, &buflen)) |
1871 | return NULL((void*)0); |
1872 | |
1873 | if (buflen == 0) { |
1874 | int flag = 0; |
1875 | socklen_t flagsize = sizeof flag; |
1876 | res = getsockopt(s->sock_fd, level, optname, |
1877 | (void *)&flag, &flagsize); |
1878 | if (res < 0) |
1879 | return s->errorhandler(); |
1880 | return PyLong_FromLong(flag); |
1881 | } |
1882 | #ifdef __VMS |
1883 | /* socklen_t is unsigned so no negative test is needed, |
1884 | test buflen == 0 is previously done */ |
1885 | if (buflen > 1024) { |
1886 | #else |
1887 | if (buflen <= 0 || buflen > 1024) { |
1888 | #endif |
1889 | PyErr_SetString(socket_error, |
1890 | "getsockopt buflen out of range"); |
1891 | return NULL((void*)0); |
1892 | } |
1893 | buf = PyBytes_FromStringAndSize((char *)NULL((void*)0), buflen); |
1894 | if (buf == NULL((void*)0)) |
1895 | return NULL((void*)0); |
1896 | res = getsockopt(s->sock_fd, level, optname, |
1897 | (void *)PyBytes_AS_STRING(buf)((__builtin_expect(!(((((((PyObject*)(buf))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1897 , "PyBytes_Check(buf)") : (void)0), (((PyBytesObject *)(buf)) ->ob_sval)), &buflen); |
1898 | if (res < 0) { |
1899 | Py_DECREF(buf)do { if (_Py_RefTotal-- , --((PyObject*)(buf))->ob_refcnt != 0) { if (((PyObject*)buf)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 1899 , (PyObject *)(buf)); } else _Py_Dealloc((PyObject *)(buf)); } while (0); |
1900 | return s->errorhandler(); |
1901 | } |
1902 | _PyBytes_Resize(&buf, buflen); |
1903 | return buf; |
1904 | } |
1905 | |
1906 | PyDoc_STRVAR(getsockopt_doc,static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer." |
1907 | "getsockopt(level, option[, buffersize]) -> value\n\static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer." |
1908 | \n\static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer." |
1909 | Get a socket option. See the Unix manual for level and option.\n\static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer." |
1910 | If a nonzero buffersize argument is given, the return value is a\n\static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer." |
1911 | string of that length; otherwise it is an integer.")static char getsockopt_doc[] = "getsockopt(level, option[, buffersize]) -> value\n\nGet a socket option. See the Unix manual for level and option.\nIf a nonzero buffersize argument is given, the return value is a\nstring of that length; otherwise it is an integer."; |
1912 | |
1913 | |
1914 | /* s.bind(sockaddr) method */ |
1915 | |
1916 | static PyObject * |
1917 | sock_bind(PySocketSockObject *s, PyObject *addro) |
1918 | { |
1919 | sock_addr_t addrbuf; |
1920 | int addrlen; |
1921 | int res; |
1922 | |
1923 | if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen)) |
1924 | return NULL((void*)0); |
1925 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
1926 | res = bind(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen); |
1927 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
1928 | if (res < 0) |
1929 | return s->errorhandler(); |
1930 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1931 | return Py_None(&_Py_NoneStruct); |
1932 | } |
1933 | |
1934 | PyDoc_STRVAR(bind_doc,static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])" |
1935 | "bind(address)\n\static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])" |
1936 | \n\static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])" |
1937 | Bind the socket to a local address. For IP sockets, the address is a\n\static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])" |
1938 | pair (host, port); the host must refer to the local host. For raw packet\n\static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])" |
1939 | sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])")static char bind_doc[] = "bind(address)\n\nBind the socket to a local address. For IP sockets, the address is a\npair (host, port); the host must refer to the local host. For raw packet\nsockets the address is a tuple (ifname, proto [,pkttype [,hatype]])"; |
1940 | |
1941 | |
1942 | /* s.close() method. |
1943 | Set the file descriptor to -1 so operations tried subsequently |
1944 | will surely fail. */ |
1945 | |
1946 | static PyObject * |
1947 | sock_close(PySocketSockObject *s) |
1948 | { |
1949 | SOCKET_T fd; |
1950 | |
1951 | if ((fd = s->sock_fd) != -1) { |
1952 | s->sock_fd = -1; |
1953 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
1954 | (void) SOCKETCLOSEclose(fd); |
1955 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
1956 | } |
1957 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
1958 | return Py_None(&_Py_NoneStruct); |
1959 | } |
1960 | |
1961 | PyDoc_STRVAR(close_doc,static char close_doc[] = "close()\n\nClose the socket. It cannot be used after this call." |
1962 | "close()\n\static char close_doc[] = "close()\n\nClose the socket. It cannot be used after this call." |
1963 | \n\static char close_doc[] = "close()\n\nClose the socket. It cannot be used after this call." |
1964 | Close the socket. It cannot be used after this call.")static char close_doc[] = "close()\n\nClose the socket. It cannot be used after this call."; |
1965 | |
1966 | static PyObject * |
1967 | sock_detach(PySocketSockObject *s) |
1968 | { |
1969 | SOCKET_T fd = s->sock_fd; |
1970 | s->sock_fd = -1; |
1971 | return PyLong_FromSocket_t(fd)PyLong_FromLong((SOCKET_T)(fd)); |
1972 | } |
1973 | |
1974 | PyDoc_STRVAR(detach_doc,static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned." |
1975 | "detach()\n\static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned." |
1976 | \n\static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned." |
1977 | Close the socket object without closing the underlying file descriptor.\static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned." |
1978 | The object cannot be used after this call, but the file descriptor\static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned." |
1979 | can be reused for other purposes. The file descriptor is returned.")static char detach_doc[] = "detach()\n\nClose the socket object without closing the underlying file descriptor.The object cannot be used after this call, but the file descriptorcan be reused for other purposes. The file descriptor is returned."; |
1980 | |
1981 | static int |
1982 | internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, |
1983 | int *timeoutp) |
1984 | { |
1985 | int res, timeout; |
1986 | |
1987 | timeout = 0; |
1988 | res = connect(s->sock_fd, addr, addrlen); |
1989 | |
1990 | #ifdef MS_WINDOWS |
1991 | |
1992 | if (s->sock_timeout > 0.0) { |
1993 | if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK && |
1994 | IS_SELECTABLE(s)1) { |
1995 | /* This is a mess. Best solution: trust select */ |
1996 | fd_set fds; |
1997 | fd_set fds_exc; |
1998 | struct timeval tv; |
1999 | tv.tv_sec = (int)s->sock_timeout; |
2000 | tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
2001 | FD_ZERO(&fds)__builtin_bzero(&fds, sizeof(*(&fds))); |
2002 | FD_SET(s->sock_fd, &fds)do { int __fd = (s->sock_fd); ((&fds)->fds_bits[__fd /(sizeof(__int32_t) * 8)] |= (1<<(__fd % (sizeof(__int32_t ) * 8)))); } while(0); |
2003 | FD_ZERO(&fds_exc)__builtin_bzero(&fds_exc, sizeof(*(&fds_exc))); |
2004 | FD_SET(s->sock_fd, &fds_exc)do { int __fd = (s->sock_fd); ((&fds_exc)->fds_bits [__fd/(sizeof(__int32_t) * 8)] |= (1<<(__fd % (sizeof(__int32_t ) * 8)))); } while(0); |
2005 | res = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int)((__builtin_expect(!((SOCKET_T)(int)(s->sock_fd+1) == (s-> sock_fd+1)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2005, "(SOCKET_T)(int)(s->sock_fd+1) == (s->sock_fd+1)" ) : (void)0), (int)(s->sock_fd+1)), |
2006 | NULL((void*)0), &fds, &fds_exc, &tv); |
2007 | if (res == 0) { |
2008 | res = WSAEWOULDBLOCK; |
2009 | timeout = 1; |
2010 | } else if (res > 0) { |
2011 | if (FD_ISSET(s->sock_fd, &fds)__darwin_fd_isset((s->sock_fd), (&fds))) |
2012 | /* The socket is in the writable set - this |
2013 | means connected */ |
2014 | res = 0; |
2015 | else { |
2016 | /* As per MS docs, we need to call getsockopt() |
2017 | to get the underlying error */ |
2018 | int res_size = sizeof res; |
2019 | /* It must be in the exception set */ |
2020 | assert(FD_ISSET(s->sock_fd, &fds_exc))(__builtin_expect(!(__darwin_fd_isset((s->sock_fd), (& fds_exc))), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2020, "FD_ISSET(s->sock_fd, &fds_exc)") : (void)0); |
2021 | if (0 == getsockopt(s->sock_fd, SOL_SOCKET0xffff, SO_ERROR0x1007, |
2022 | (char *)&res, &res_size)) |
2023 | /* getsockopt also clears WSAGetLastError, |
2024 | so reset it back. */ |
2025 | WSASetLastError(res); |
2026 | else |
2027 | res = WSAGetLastError(); |
2028 | } |
2029 | } |
2030 | /* else if (res < 0) an error occurred */ |
2031 | } |
2032 | } |
2033 | |
2034 | if (res < 0) |
2035 | res = WSAGetLastError(); |
2036 | |
2037 | #else |
2038 | |
2039 | if (s->sock_timeout > 0.0) { |
2040 | if (res < 0 && errno(*__error()) == EINPROGRESS36 && IS_SELECTABLE(s)1) { |
2041 | timeout = internal_select(s, 1); |
2042 | if (timeout == 0) { |
2043 | /* Bug #1019808: in case of an EINPROGRESS, |
2044 | use getsockopt(SO_ERROR) to get the real |
2045 | error. */ |
2046 | socklen_t res_size = sizeof res; |
2047 | (void)getsockopt(s->sock_fd, SOL_SOCKET0xffff, |
2048 | SO_ERROR0x1007, &res, &res_size); |
2049 | if (res == EISCONN56) |
2050 | res = 0; |
2051 | errno(*__error()) = res; |
2052 | } |
2053 | else if (timeout == -1) { |
2054 | res = errno(*__error()); /* had error */ |
2055 | } |
2056 | else |
2057 | res = EWOULDBLOCK35; /* timed out */ |
2058 | } |
2059 | } |
2060 | |
2061 | if (res < 0) |
2062 | res = errno(*__error()); |
2063 | |
2064 | #endif |
2065 | *timeoutp = timeout; |
2066 | |
2067 | return res; |
2068 | } |
2069 | |
2070 | /* s.connect(sockaddr) method */ |
2071 | |
2072 | static PyObject * |
2073 | sock_connect(PySocketSockObject *s, PyObject *addro) |
2074 | { |
2075 | sock_addr_t addrbuf; |
2076 | int addrlen; |
2077 | int res; |
2078 | int timeout; |
2079 | |
2080 | if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen)) |
2081 | return NULL((void*)0); |
2082 | |
2083 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2084 | res = internal_connect(s, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen, &timeout); |
2085 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2086 | |
2087 | if (timeout == 1) { |
2088 | PyErr_SetString(socket_timeout, "timed out"); |
2089 | return NULL((void*)0); |
2090 | } |
2091 | if (res != 0) |
2092 | return s->errorhandler(); |
2093 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
2094 | return Py_None(&_Py_NoneStruct); |
2095 | } |
2096 | |
2097 | PyDoc_STRVAR(connect_doc,static char connect_doc[] = "connect(address)\n\nConnect the socket to a remote address. For IP sockets, the address\nis a pair (host, port)." |
2098 | "connect(address)\n\static char connect_doc[] = "connect(address)\n\nConnect the socket to a remote address. For IP sockets, the address\nis a pair (host, port)." |
2099 | \n\static char connect_doc[] = "connect(address)\n\nConnect the socket to a remote address. For IP sockets, the address\nis a pair (host, port)." |
2100 | Connect the socket to a remote address. For IP sockets, the address\n\static char connect_doc[] = "connect(address)\n\nConnect the socket to a remote address. For IP sockets, the address\nis a pair (host, port)." |
2101 | is a pair (host, port).")static char connect_doc[] = "connect(address)\n\nConnect the socket to a remote address. For IP sockets, the address\nis a pair (host, port)."; |
2102 | |
2103 | |
2104 | /* s.connect_ex(sockaddr) method */ |
2105 | |
2106 | static PyObject * |
2107 | sock_connect_ex(PySocketSockObject *s, PyObject *addro) |
2108 | { |
2109 | sock_addr_t addrbuf; |
2110 | int addrlen; |
2111 | int res; |
2112 | int timeout; |
2113 | |
2114 | if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen)) |
2115 | return NULL((void*)0); |
2116 | |
2117 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2118 | res = internal_connect(s, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen, &timeout); |
2119 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2120 | |
2121 | /* Signals are not errors (though they may raise exceptions). Adapted |
2122 | from PyErr_SetFromErrnoWithFilenameObject(). */ |
2123 | #ifdef EINTR4 |
2124 | if (res == EINTR4 && PyErr_CheckSignals()) |
2125 | return NULL((void*)0); |
2126 | #endif |
2127 | |
2128 | return PyLong_FromLong((long) res); |
2129 | } |
2130 | |
2131 | PyDoc_STRVAR(connect_ex_doc,static char connect_ex_doc[] = "connect_ex(address) -> errno\n\nThis is like connect(address), but returns an error code (the errno value)\ninstead of raising an exception when an error occurs." |
2132 | "connect_ex(address) -> errno\n\static char connect_ex_doc[] = "connect_ex(address) -> errno\n\nThis is like connect(address), but returns an error code (the errno value)\ninstead of raising an exception when an error occurs." |
2133 | \n\static char connect_ex_doc[] = "connect_ex(address) -> errno\n\nThis is like connect(address), but returns an error code (the errno value)\ninstead of raising an exception when an error occurs." |
2134 | This is like connect(address), but returns an error code (the errno value)\n\static char connect_ex_doc[] = "connect_ex(address) -> errno\n\nThis is like connect(address), but returns an error code (the errno value)\ninstead of raising an exception when an error occurs." |
2135 | instead of raising an exception when an error occurs.")static char connect_ex_doc[] = "connect_ex(address) -> errno\n\nThis is like connect(address), but returns an error code (the errno value)\ninstead of raising an exception when an error occurs."; |
2136 | |
2137 | |
2138 | /* s.fileno() method */ |
2139 | |
2140 | static PyObject * |
2141 | sock_fileno(PySocketSockObject *s) |
2142 | { |
2143 | return PyLong_FromSocket_t(s->sock_fd)PyLong_FromLong((SOCKET_T)(s->sock_fd)); |
2144 | } |
2145 | |
2146 | PyDoc_STRVAR(fileno_doc,static char fileno_doc[] = "fileno() -> integer\n\nReturn the integer file descriptor of the socket." |
2147 | "fileno() -> integer\n\static char fileno_doc[] = "fileno() -> integer\n\nReturn the integer file descriptor of the socket." |
2148 | \n\static char fileno_doc[] = "fileno() -> integer\n\nReturn the integer file descriptor of the socket." |
2149 | Return the integer file descriptor of the socket.")static char fileno_doc[] = "fileno() -> integer\n\nReturn the integer file descriptor of the socket."; |
2150 | |
2151 | |
2152 | /* s.getsockname() method */ |
2153 | |
2154 | static PyObject * |
2155 | sock_getsockname(PySocketSockObject *s) |
2156 | { |
2157 | sock_addr_t addrbuf; |
2158 | int res; |
2159 | socklen_t addrlen; |
2160 | |
2161 | if (!getsockaddrlen(s, &addrlen)) |
2162 | return NULL((void*)0); |
2163 | memset(&addrbuf, 0, addrlen)((__builtin_object_size (&addrbuf, 0) != (size_t) -1) ? __builtin___memset_chk (&addrbuf, 0, addrlen, __builtin_object_size (&addrbuf , 0)) : __inline_memset_chk (&addrbuf, 0, addrlen)); |
2164 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2165 | res = getsockname(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen); |
2166 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2167 | if (res < 0) |
2168 | return s->errorhandler(); |
2169 | return makesockaddr(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen, |
2170 | s->sock_proto); |
2171 | } |
2172 | |
2173 | PyDoc_STRVAR(getsockname_doc,static char getsockname_doc[] = "getsockname() -> address info\n\nReturn the address of the local endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2174 | "getsockname() -> address info\n\static char getsockname_doc[] = "getsockname() -> address info\n\nReturn the address of the local endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2175 | \n\static char getsockname_doc[] = "getsockname() -> address info\n\nReturn the address of the local endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2176 | Return the address of the local endpoint. For IP sockets, the address\n\static char getsockname_doc[] = "getsockname() -> address info\n\nReturn the address of the local endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2177 | info is a pair (hostaddr, port).")static char getsockname_doc[] = "getsockname() -> address info\n\nReturn the address of the local endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)."; |
2178 | |
2179 | |
2180 | #ifdef HAVE_GETPEERNAME1 /* Cray APP doesn't have this :-( */ |
2181 | /* s.getpeername() method */ |
2182 | |
2183 | static PyObject * |
2184 | sock_getpeername(PySocketSockObject *s) |
2185 | { |
2186 | sock_addr_t addrbuf; |
2187 | int res; |
2188 | socklen_t addrlen; |
2189 | |
2190 | if (!getsockaddrlen(s, &addrlen)) |
2191 | return NULL((void*)0); |
2192 | memset(&addrbuf, 0, addrlen)((__builtin_object_size (&addrbuf, 0) != (size_t) -1) ? __builtin___memset_chk (&addrbuf, 0, addrlen, __builtin_object_size (&addrbuf , 0)) : __inline_memset_chk (&addrbuf, 0, addrlen)); |
2193 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2194 | res = getpeername(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen); |
2195 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2196 | if (res < 0) |
2197 | return s->errorhandler(); |
2198 | return makesockaddr(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen, |
2199 | s->sock_proto); |
2200 | } |
2201 | |
2202 | PyDoc_STRVAR(getpeername_doc,static char getpeername_doc[] = "getpeername() -> address info\n\nReturn the address of the remote endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2203 | "getpeername() -> address info\n\static char getpeername_doc[] = "getpeername() -> address info\n\nReturn the address of the remote endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2204 | \n\static char getpeername_doc[] = "getpeername() -> address info\n\nReturn the address of the remote endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2205 | Return the address of the remote endpoint. For IP sockets, the address\n\static char getpeername_doc[] = "getpeername() -> address info\n\nReturn the address of the remote endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)." |
2206 | info is a pair (hostaddr, port).")static char getpeername_doc[] = "getpeername() -> address info\n\nReturn the address of the remote endpoint. For IP sockets, the address\ninfo is a pair (hostaddr, port)."; |
2207 | |
2208 | #endif /* HAVE_GETPEERNAME */ |
2209 | |
2210 | |
2211 | /* s.listen(n) method */ |
2212 | |
2213 | static PyObject * |
2214 | sock_listen(PySocketSockObject *s, PyObject *arg) |
2215 | { |
2216 | int backlog; |
2217 | int res; |
2218 | |
2219 | backlog = PyLong_AsLong(arg); |
2220 | if (backlog == -1 && PyErr_Occurred()) |
2221 | return NULL((void*)0); |
2222 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2223 | if (backlog < 1) |
2224 | backlog = 1; |
2225 | res = listen(s->sock_fd, backlog); |
2226 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2227 | if (res < 0) |
2228 | return s->errorhandler(); |
2229 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
2230 | return Py_None(&_Py_NoneStruct); |
2231 | } |
2232 | |
2233 | PyDoc_STRVAR(listen_doc,static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections." |
2234 | "listen(backlog)\n\static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections." |
2235 | \n\static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections." |
2236 | Enable a server to accept connections. The backlog argument must be at\n\static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections." |
2237 | least 1; it specifies the number of unaccepted connection that the system\n\static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections." |
2238 | will allow before refusing new connections.")static char listen_doc[] = "listen(backlog)\n\nEnable a server to accept connections. The backlog argument must be at\nleast 1; it specifies the number of unaccepted connection that the system\nwill allow before refusing new connections."; |
2239 | |
2240 | |
2241 | /* |
2242 | * This is the guts of the recv() and recv_into() methods, which reads into a |
2243 | * char buffer. If you have any inc/dec ref to do to the objects that contain |
2244 | * the buffer, do it in the caller. This function returns the number of bytes |
2245 | * succesfully read. If there was an error, it returns -1. Note that it is |
2246 | * also possible that we return a number of bytes smaller than the request |
2247 | * bytes. |
2248 | */ |
2249 | |
2250 | static Py_ssize_t |
2251 | sock_recv_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags) |
2252 | { |
2253 | Py_ssize_t outlen = -1; |
2254 | int timeout; |
2255 | #ifdef __VMS |
2256 | int remaining; |
2257 | char *read_buf; |
2258 | #endif |
2259 | |
2260 | if (!IS_SELECTABLE(s)1) { |
2261 | select_error(); |
2262 | return -1; |
2263 | } |
2264 | if (len == 0) { |
2265 | /* If 0 bytes were requested, do nothing. */ |
2266 | return 0; |
2267 | } |
2268 | |
2269 | #ifndef __VMS |
2270 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
2271 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2272 | timeout = internal_select_ex(s, 0, interval); |
2273 | if (!timeout) |
2274 | outlen = recv(s->sock_fd, cbuf, len, flags); |
2275 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2276 | |
2277 | if (timeout == 1) { |
2278 | PyErr_SetString(socket_timeout, "timed out"); |
2279 | return -1; |
2280 | } |
2281 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
2282 | if (outlen < 0) { |
2283 | /* Note: the call to errorhandler() ALWAYS indirectly returned |
2284 | NULL, so ignore its return value */ |
2285 | s->errorhandler(); |
2286 | return -1; |
2287 | } |
2288 | #else |
2289 | read_buf = cbuf; |
2290 | remaining = len; |
2291 | while (remaining != 0) { |
2292 | unsigned int segment; |
2293 | int nread = -1; |
2294 | |
2295 | segment = remaining /SEGMENT_SIZE; |
2296 | if (segment != 0) { |
2297 | segment = SEGMENT_SIZE; |
2298 | } |
2299 | else { |
2300 | segment = remaining; |
2301 | } |
2302 | |
2303 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
2304 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2305 | timeout = internal_select_ex(s, 0, interval); |
2306 | if (!timeout) |
2307 | nread = recv(s->sock_fd, read_buf, segment, flags); |
2308 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2309 | if (timeout == 1) { |
2310 | PyErr_SetString(socket_timeout, "timed out"); |
2311 | return -1; |
2312 | } |
2313 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
2314 | |
2315 | if (nread < 0) { |
2316 | s->errorhandler(); |
2317 | return -1; |
2318 | } |
2319 | if (nread != remaining) { |
2320 | read_buf += nread; |
2321 | break; |
2322 | } |
2323 | |
2324 | remaining -= segment; |
2325 | read_buf += segment; |
2326 | } |
2327 | outlen = read_buf - cbuf; |
2328 | #endif /* !__VMS */ |
2329 | |
2330 | return outlen; |
2331 | } |
2332 | |
2333 | |
2334 | /* s.recv(nbytes [,flags]) method */ |
2335 | |
2336 | static PyObject * |
2337 | sock_recv(PySocketSockObject *s, PyObject *args) |
2338 | { |
2339 | Py_ssize_t recvlen, outlen; |
2340 | int flags = 0; |
2341 | PyObject *buf; |
2342 | |
2343 | if (!PyArg_ParseTuple(args, "n|i:recv", &recvlen, &flags)) |
2344 | return NULL((void*)0); |
2345 | |
2346 | if (recvlen < 0) { |
2347 | PyErr_SetString(PyExc_ValueError, |
2348 | "negative buffersize in recv"); |
2349 | return NULL((void*)0); |
2350 | } |
2351 | |
2352 | /* Allocate a new string. */ |
2353 | buf = PyBytes_FromStringAndSize((char *) 0, recvlen); |
2354 | if (buf == NULL((void*)0)) |
2355 | return NULL((void*)0); |
2356 | |
2357 | /* Call the guts */ |
2358 | outlen = sock_recv_guts(s, PyBytes_AS_STRING(buf)((__builtin_expect(!(((((((PyObject*)(buf))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 2358 , "PyBytes_Check(buf)") : (void)0), (((PyBytesObject *)(buf)) ->ob_sval)), recvlen, flags); |
2359 | if (outlen < 0) { |
2360 | /* An error occurred, release the string and return an |
2361 | error. */ |
2362 | Py_DECREF(buf)do { if (_Py_RefTotal-- , --((PyObject*)(buf))->ob_refcnt != 0) { if (((PyObject*)buf)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 2362 , (PyObject *)(buf)); } else _Py_Dealloc((PyObject *)(buf)); } while (0); |
2363 | return NULL((void*)0); |
2364 | } |
2365 | if (outlen != recvlen) { |
2366 | /* We did not read as many bytes as we anticipated, resize the |
2367 | string if possible and be successful. */ |
2368 | _PyBytes_Resize(&buf, outlen); |
2369 | } |
2370 | |
2371 | return buf; |
2372 | } |
2373 | |
2374 | PyDoc_STRVAR(recv_doc,static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2375 | "recv(buffersize[, flags]) -> data\n\static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2376 | \n\static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2377 | Receive up to buffersize bytes from the socket. For the optional flags\n\static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2378 | argument, see the Unix manual. When no data is available, block until\n\static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2379 | at least one byte is available or until the remote end is closed. When\n\static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string." |
2380 | the remote end is closed and all data is read, return the empty string.")static char recv_doc[] = "recv(buffersize[, flags]) -> data\n\nReceive up to buffersize bytes from the socket. For the optional flags\nargument, see the Unix manual. When no data is available, block until\nat least one byte is available or until the remote end is closed. When\nthe remote end is closed and all data is read, return the empty string."; |
2381 | |
2382 | |
2383 | /* s.recv_into(buffer, [nbytes [,flags]]) method */ |
2384 | |
2385 | static PyObject* |
2386 | sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds) |
2387 | { |
2388 | static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
2389 | |
2390 | int flags = 0; |
2391 | Py_buffer pbuf; |
2392 | char *buf; |
2393 | Py_ssize_t buflen, readlen, recvlen = 0; |
2394 | |
2395 | /* Get the buffer's memory */ |
2396 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recv_into", kwlist, |
2397 | &pbuf, &recvlen, &flags)) |
2398 | return NULL((void*)0); |
2399 | buf = pbuf.buf; |
2400 | buflen = pbuf.len; |
2401 | |
2402 | if (recvlen < 0) { |
2403 | PyBuffer_Release(&pbuf); |
2404 | PyErr_SetString(PyExc_ValueError, |
2405 | "negative buffersize in recv_into"); |
2406 | return NULL((void*)0); |
2407 | } |
2408 | if (recvlen == 0) { |
2409 | /* If nbytes was not specified, use the buffer's length */ |
2410 | recvlen = buflen; |
2411 | } |
2412 | |
2413 | /* Check if the buffer is large enough */ |
2414 | if (buflen < recvlen) { |
2415 | PyBuffer_Release(&pbuf); |
2416 | PyErr_SetString(PyExc_ValueError, |
2417 | "buffer too small for requested bytes"); |
2418 | return NULL((void*)0); |
2419 | } |
2420 | |
2421 | /* Call the guts */ |
2422 | readlen = sock_recv_guts(s, buf, recvlen, flags); |
2423 | if (readlen < 0) { |
2424 | /* Return an error. */ |
2425 | PyBuffer_Release(&pbuf); |
2426 | return NULL((void*)0); |
2427 | } |
2428 | |
2429 | PyBuffer_Release(&pbuf); |
2430 | /* Return the number of bytes read. Note that we do not do anything |
2431 | special here in the case that readlen < recvlen. */ |
2432 | return PyLong_FromSsize_t(readlen); |
2433 | } |
2434 | |
2435 | PyDoc_STRVAR(recv_into_doc,static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2436 | "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2437 | \n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2438 | A version of recv() that stores its data into a buffer rather than creating \n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2439 | a new string. Receive up to buffersize bytes from the socket. If buffersize \n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2440 | is not specified (or 0), receive up to the size available in the given buffer.\n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2441 | \n\static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags." |
2442 | See recv() for documentation about the flags.")static char recv_into_doc[] = "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\nA version of recv() that stores its data into a buffer rather than creating \na new string. Receive up to buffersize bytes from the socket. If buffersize \nis not specified (or 0), receive up to the size available in the given buffer.\n\nSee recv() for documentation about the flags."; |
2443 | |
2444 | |
2445 | /* |
2446 | * This is the guts of the recvfrom() and recvfrom_into() methods, which reads |
2447 | * into a char buffer. If you have any inc/def ref to do to the objects that |
2448 | * contain the buffer, do it in the caller. This function returns the number |
2449 | * of bytes succesfully read. If there was an error, it returns -1. Note |
2450 | * that it is also possible that we return a number of bytes smaller than the |
2451 | * request bytes. |
2452 | * |
2453 | * 'addr' is a return value for the address object. Note that you must decref |
2454 | * it yourself. |
2455 | */ |
2456 | static Py_ssize_t |
2457 | sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags, |
2458 | PyObject** addr) |
2459 | { |
2460 | sock_addr_t addrbuf; |
2461 | int timeout; |
2462 | Py_ssize_t n = -1; |
2463 | socklen_t addrlen; |
2464 | |
2465 | *addr = NULL((void*)0); |
2466 | |
2467 | if (!getsockaddrlen(s, &addrlen)) |
2468 | return -1; |
2469 | |
2470 | if (!IS_SELECTABLE(s)1) { |
2471 | select_error(); |
2472 | return -1; |
2473 | } |
2474 | |
2475 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
2476 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2477 | memset(&addrbuf, 0, addrlen)((__builtin_object_size (&addrbuf, 0) != (size_t) -1) ? __builtin___memset_chk (&addrbuf, 0, addrlen, __builtin_object_size (&addrbuf , 0)) : __inline_memset_chk (&addrbuf, 0, addrlen)); |
2478 | timeout = internal_select_ex(s, 0, interval); |
2479 | if (!timeout) { |
2480 | #ifndef MS_WINDOWS |
2481 | #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
2482 | n = recvfrom(s->sock_fd, cbuf, len, flags, |
2483 | SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen); |
2484 | #else |
2485 | n = recvfrom(s->sock_fd, cbuf, len, flags, |
2486 | (void *) &addrbuf, &addrlen); |
2487 | #endif |
2488 | #else |
2489 | n = recvfrom(s->sock_fd, cbuf, len, flags, |
2490 | SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen); |
2491 | #endif |
2492 | } |
2493 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2494 | |
2495 | if (timeout == 1) { |
2496 | PyErr_SetString(socket_timeout, "timed out"); |
2497 | return -1; |
2498 | } |
2499 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
2500 | if (n < 0) { |
2501 | s->errorhandler(); |
2502 | return -1; |
2503 | } |
2504 | |
2505 | if (!(*addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), |
2506 | addrlen, s->sock_proto))) |
2507 | return -1; |
2508 | |
2509 | return n; |
2510 | } |
2511 | |
2512 | /* s.recvfrom(nbytes [,flags]) method */ |
2513 | |
2514 | static PyObject * |
2515 | sock_recvfrom(PySocketSockObject *s, PyObject *args) |
2516 | { |
2517 | PyObject *buf = NULL((void*)0); |
2518 | PyObject *addr = NULL((void*)0); |
2519 | PyObject *ret = NULL((void*)0); |
2520 | int flags = 0; |
2521 | Py_ssize_t recvlen, outlen; |
2522 | |
2523 | if (!PyArg_ParseTuple(args, "n|i:recvfrom", &recvlen, &flags)) |
2524 | return NULL((void*)0); |
2525 | |
2526 | if (recvlen < 0) { |
2527 | PyErr_SetString(PyExc_ValueError, |
2528 | "negative buffersize in recvfrom"); |
2529 | return NULL((void*)0); |
2530 | } |
2531 | |
2532 | buf = PyBytes_FromStringAndSize((char *) 0, recvlen); |
2533 | if (buf == NULL((void*)0)) |
2534 | return NULL((void*)0); |
2535 | |
2536 | outlen = sock_recvfrom_guts(s, PyBytes_AS_STRING(buf)((__builtin_expect(!(((((((PyObject*)(buf))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 2536 , "PyBytes_Check(buf)") : (void)0), (((PyBytesObject *)(buf)) ->ob_sval)), |
2537 | recvlen, flags, &addr); |
2538 | if (outlen < 0) { |
2539 | goto finally; |
2540 | } |
2541 | |
2542 | if (outlen != recvlen) { |
2543 | /* We did not read as many bytes as we anticipated, resize the |
2544 | string if possible and be succesful. */ |
2545 | if (_PyBytes_Resize(&buf, outlen) < 0) |
2546 | /* Oopsy, not so succesful after all. */ |
2547 | goto finally; |
2548 | } |
2549 | |
2550 | ret = PyTuple_Pack(2, buf, addr); |
2551 | |
2552 | finally: |
2553 | Py_XDECREF(buf)do { if ((buf) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(buf))->ob_refcnt != 0) { if (((PyObject*)buf )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2553, (PyObject *)(buf)); } else _Py_Dealloc((PyObject *)(buf )); } while (0); } while (0); |
2554 | Py_XDECREF(addr)do { if ((addr) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(addr))->ob_refcnt != 0) { if (((PyObject *)addr)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2554, (PyObject *)(addr)); } else _Py_Dealloc((PyObject *)( addr)); } while (0); } while (0); |
2555 | return ret; |
2556 | } |
2557 | |
2558 | PyDoc_STRVAR(recvfrom_doc,static char recvfrom_doc[] = "recvfrom(buffersize[, flags]) -> (data, address info)\n\nLike recv(buffersize, flags) but also return the sender's address info." |
2559 | "recvfrom(buffersize[, flags]) -> (data, address info)\n\static char recvfrom_doc[] = "recvfrom(buffersize[, flags]) -> (data, address info)\n\nLike recv(buffersize, flags) but also return the sender's address info." |
2560 | \n\static char recvfrom_doc[] = "recvfrom(buffersize[, flags]) -> (data, address info)\n\nLike recv(buffersize, flags) but also return the sender's address info." |
2561 | Like recv(buffersize, flags) but also return the sender's address info.")static char recvfrom_doc[] = "recvfrom(buffersize[, flags]) -> (data, address info)\n\nLike recv(buffersize, flags) but also return the sender's address info."; |
2562 | |
2563 | |
2564 | /* s.recvfrom_into(buffer[, nbytes [,flags]]) method */ |
2565 | |
2566 | static PyObject * |
2567 | sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds) |
2568 | { |
2569 | static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
2570 | |
2571 | int flags = 0; |
2572 | Py_buffer pbuf; |
2573 | char *buf; |
2574 | Py_ssize_t readlen, buflen, recvlen = 0; |
2575 | |
2576 | PyObject *addr = NULL((void*)0); |
2577 | |
2578 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recvfrom_into", |
2579 | kwlist, &pbuf, |
2580 | &recvlen, &flags)) |
2581 | return NULL((void*)0); |
2582 | buf = pbuf.buf; |
2583 | buflen = pbuf.len; |
2584 | assert(buf != 0 && buflen > 0)(__builtin_expect(!(buf != 0 && buflen > 0), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2584, "buf != 0 && buflen > 0") : (void)0); |
2585 | |
2586 | if (recvlen < 0) { |
2587 | PyBuffer_Release(&pbuf); |
2588 | PyErr_SetString(PyExc_ValueError, |
2589 | "negative buffersize in recvfrom_into"); |
2590 | return NULL((void*)0); |
2591 | } |
2592 | if (recvlen == 0) { |
2593 | /* If nbytes was not specified, use the buffer's length */ |
2594 | recvlen = buflen; |
2595 | } |
2596 | |
2597 | readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr); |
2598 | if (readlen < 0) { |
2599 | PyBuffer_Release(&pbuf); |
2600 | /* Return an error */ |
2601 | Py_XDECREF(addr)do { if ((addr) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(addr))->ob_refcnt != 0) { if (((PyObject *)addr)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 2601, (PyObject *)(addr)); } else _Py_Dealloc((PyObject *)( addr)); } while (0); } while (0); |
2602 | return NULL((void*)0); |
2603 | } |
2604 | |
2605 | PyBuffer_Release(&pbuf); |
2606 | /* Return the number of bytes read and the address. Note that we do |
2607 | not do anything special here in the case that readlen < recvlen. */ |
2608 | return Py_BuildValue("nN", readlen, addr); |
2609 | } |
2610 | |
2611 | PyDoc_STRVAR(recvfrom_into_doc,static char recvfrom_into_doc[] = "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\nLike recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info." |
2612 | "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\static char recvfrom_into_doc[] = "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\nLike recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info." |
2613 | \n\static char recvfrom_into_doc[] = "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\nLike recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info." |
2614 | Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info.")static char recvfrom_into_doc[] = "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\nLike recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info."; |
2615 | |
2616 | |
2617 | /* s.send(data [,flags]) method */ |
2618 | |
2619 | static PyObject * |
2620 | sock_send(PySocketSockObject *s, PyObject *args) |
2621 | { |
2622 | char *buf; |
2623 | Py_ssize_t len, n = -1; |
2624 | int flags = 0, timeout; |
2625 | Py_buffer pbuf; |
2626 | |
2627 | if (!PyArg_ParseTuple(args, "y*|i:send", &pbuf, &flags)) |
2628 | return NULL((void*)0); |
2629 | |
2630 | if (!IS_SELECTABLE(s)1) { |
2631 | PyBuffer_Release(&pbuf); |
2632 | return select_error(); |
2633 | } |
2634 | buf = pbuf.buf; |
2635 | len = pbuf.len; |
2636 | |
2637 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
2638 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2639 | timeout = internal_select_ex(s, 1, interval); |
2640 | if (!timeout) |
2641 | #ifdef __VMS |
2642 | n = sendsegmented(s->sock_fd, buf, len, flags); |
2643 | #else |
2644 | n = send(s->sock_fd, buf, len, flags); |
2645 | #endif |
2646 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2647 | if (timeout == 1) { |
2648 | PyBuffer_Release(&pbuf); |
2649 | PyErr_SetString(socket_timeout, "timed out"); |
2650 | return NULL((void*)0); |
2651 | } |
2652 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
2653 | |
2654 | PyBuffer_Release(&pbuf); |
2655 | if (n < 0) |
2656 | return s->errorhandler(); |
2657 | return PyLong_FromSsize_t(n); |
2658 | } |
2659 | |
2660 | PyDoc_STRVAR(send_doc,static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy." |
2661 | "send(data[, flags]) -> count\n\static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy." |
2662 | \n\static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy." |
2663 | Send a data string to the socket. For the optional flags\n\static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy." |
2664 | argument, see the Unix manual. Return the number of bytes\n\static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy." |
2665 | sent; this may be less than len(data) if the network is busy.")static char send_doc[] = "send(data[, flags]) -> count\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. Return the number of bytes\nsent; this may be less than len(data) if the network is busy."; |
2666 | |
2667 | |
2668 | /* s.sendall(data [,flags]) method */ |
2669 | |
2670 | static PyObject * |
2671 | sock_sendall(PySocketSockObject *s, PyObject *args) |
2672 | { |
2673 | char *buf; |
2674 | Py_ssize_t len, n = -1; |
2675 | int flags = 0, timeout, saved_errno; |
2676 | Py_buffer pbuf; |
2677 | |
2678 | if (!PyArg_ParseTuple(args, "y*|i:sendall", &pbuf, &flags)) |
2679 | return NULL((void*)0); |
2680 | buf = pbuf.buf; |
2681 | len = pbuf.len; |
2682 | |
2683 | if (!IS_SELECTABLE(s)1) { |
2684 | PyBuffer_Release(&pbuf); |
2685 | return select_error(); |
2686 | } |
2687 | |
2688 | do { |
2689 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2690 | timeout = internal_select(s, 1); |
2691 | n = -1; |
2692 | if (!timeout) { |
2693 | #ifdef __VMS |
2694 | n = sendsegmented(s->sock_fd, buf, len, flags); |
2695 | #else |
2696 | n = send(s->sock_fd, buf, len, flags); |
2697 | #endif |
2698 | } |
2699 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2700 | if (timeout == 1) { |
2701 | PyBuffer_Release(&pbuf); |
2702 | PyErr_SetString(socket_timeout, "timed out"); |
2703 | return NULL((void*)0); |
2704 | } |
2705 | /* PyErr_CheckSignals() might change errno */ |
2706 | saved_errno = errno(*__error()); |
2707 | /* We must run our signal handlers before looping again. |
2708 | send() can return a successful partial write when it is |
2709 | interrupted, so we can't restrict ourselves to EINTR. */ |
2710 | if (PyErr_CheckSignals()) { |
2711 | PyBuffer_Release(&pbuf); |
2712 | return NULL((void*)0); |
2713 | } |
2714 | if (n < 0) { |
2715 | /* If interrupted, try again */ |
2716 | if (saved_errno == EINTR4) |
2717 | continue; |
2718 | else |
2719 | break; |
2720 | } |
2721 | buf += n; |
2722 | len -= n; |
2723 | } while (len > 0); |
2724 | PyBuffer_Release(&pbuf); |
2725 | |
2726 | if (n < 0) |
2727 | return s->errorhandler(); |
2728 | |
2729 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
2730 | return Py_None(&_Py_NoneStruct); |
2731 | } |
2732 | |
2733 | PyDoc_STRVAR(sendall_doc,static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2734 | "sendall(data[, flags])\n\static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2735 | \n\static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2736 | Send a data string to the socket. For the optional flags\n\static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2737 | argument, see the Unix manual. This calls send() repeatedly\n\static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2738 | until all data is sent. If an error occurs, it's impossible\n\static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent." |
2739 | to tell how much data has been sent.")static char sendall_doc[] = "sendall(data[, flags])\n\nSend a data string to the socket. For the optional flags\nargument, see the Unix manual. This calls send() repeatedly\nuntil all data is sent. If an error occurs, it's impossible\nto tell how much data has been sent."; |
2740 | |
2741 | |
2742 | /* s.sendto(data, [flags,] sockaddr) method */ |
2743 | |
2744 | static PyObject * |
2745 | sock_sendto(PySocketSockObject *s, PyObject *args) |
2746 | { |
2747 | Py_buffer pbuf; |
2748 | PyObject *addro; |
2749 | char *buf; |
2750 | Py_ssize_t len; |
2751 | sock_addr_t addrbuf; |
2752 | int addrlen, n = -1, flags, timeout; |
2753 | |
2754 | flags = 0; |
2755 | if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) { |
2756 | PyErr_Clear(); |
2757 | if (!PyArg_ParseTuple(args, "y*iO:sendto", |
2758 | &pbuf, &flags, &addro)) |
2759 | return NULL((void*)0); |
2760 | } |
2761 | buf = pbuf.buf; |
2762 | len = pbuf.len; |
2763 | |
2764 | if (!IS_SELECTABLE(s)1) { |
2765 | PyBuffer_Release(&pbuf); |
2766 | return select_error(); |
2767 | } |
2768 | |
2769 | if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), &addrlen)) { |
2770 | PyBuffer_Release(&pbuf); |
2771 | return NULL((void*)0); |
2772 | } |
2773 | |
2774 | BEGIN_SELECT_LOOP(s){ _PyTime_timeval now, deadline = {0, 0}; double interval = s ->sock_timeout; int has_timeout = s->sock_timeout > 0.0 ; if (has_timeout) { _PyTime_gettimeofday(&now); deadline = now; do { deadline.tv_usec += (long) (((long) s->sock_timeout - s->sock_timeout) * 1000000); deadline.tv_sec += (time_t ) s->sock_timeout + (time_t) (deadline.tv_usec / 1000000); deadline.tv_usec %= 1000000; } while (0); } while (1) { (*__error ()) = 0; |
2775 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2776 | timeout = internal_select_ex(s, 1, interval); |
2777 | if (!timeout) |
2778 | n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), addrlen); |
2779 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2780 | |
2781 | if (timeout == 1) { |
2782 | PyBuffer_Release(&pbuf); |
2783 | PyErr_SetString(socket_timeout, "timed out"); |
2784 | return NULL((void*)0); |
2785 | } |
2786 | END_SELECT_LOOP(s)if (!has_timeout || (!((*__error()) == 35) && !((*__error ()) == 35))) break; _PyTime_gettimeofday(&now); interval = ((deadline.tv_sec - now.tv_sec) + (deadline.tv_usec - now.tv_usec ) * 0.000001); } } |
2787 | PyBuffer_Release(&pbuf); |
2788 | if (n < 0) |
2789 | return s->errorhandler(); |
2790 | return PyLong_FromSsize_t(n); |
2791 | } |
2792 | |
2793 | PyDoc_STRVAR(sendto_doc,static char sendto_doc[] = "sendto(data[, flags], address) -> count\n\nLike send(data, flags) but allows specifying the destination address.\nFor IP sockets, the address is a pair (hostaddr, port)." |
2794 | "sendto(data[, flags], address) -> count\n\static char sendto_doc[] = "sendto(data[, flags], address) -> count\n\nLike send(data, flags) but allows specifying the destination address.\nFor IP sockets, the address is a pair (hostaddr, port)." |
2795 | \n\static char sendto_doc[] = "sendto(data[, flags], address) -> count\n\nLike send(data, flags) but allows specifying the destination address.\nFor IP sockets, the address is a pair (hostaddr, port)." |
2796 | Like send(data, flags) but allows specifying the destination address.\n\static char sendto_doc[] = "sendto(data[, flags], address) -> count\n\nLike send(data, flags) but allows specifying the destination address.\nFor IP sockets, the address is a pair (hostaddr, port)." |
2797 | For IP sockets, the address is a pair (hostaddr, port).")static char sendto_doc[] = "sendto(data[, flags], address) -> count\n\nLike send(data, flags) but allows specifying the destination address.\nFor IP sockets, the address is a pair (hostaddr, port)."; |
2798 | |
2799 | |
2800 | /* s.shutdown(how) method */ |
2801 | |
2802 | static PyObject * |
2803 | sock_shutdown(PySocketSockObject *s, PyObject *arg) |
2804 | { |
2805 | int how; |
2806 | int res; |
2807 | |
2808 | how = PyLong_AsLong(arg); |
2809 | if (how == -1 && PyErr_Occurred()) |
2810 | return NULL((void*)0); |
2811 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
2812 | res = shutdown(s->sock_fd, how); |
2813 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
2814 | if (res < 0) |
2815 | return s->errorhandler(); |
2816 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
2817 | return Py_None(&_Py_NoneStruct); |
2818 | } |
2819 | |
2820 | PyDoc_STRVAR(shutdown_doc,static char shutdown_doc[] = "shutdown(flag)\n\nShut down the reading side of the socket (flag == SHUT_RD), the writing side\nof the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)." |
2821 | "shutdown(flag)\n\static char shutdown_doc[] = "shutdown(flag)\n\nShut down the reading side of the socket (flag == SHUT_RD), the writing side\nof the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)." |
2822 | \n\static char shutdown_doc[] = "shutdown(flag)\n\nShut down the reading side of the socket (flag == SHUT_RD), the writing side\nof the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)." |
2823 | Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\static char shutdown_doc[] = "shutdown(flag)\n\nShut down the reading side of the socket (flag == SHUT_RD), the writing side\nof the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)." |
2824 | of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).")static char shutdown_doc[] = "shutdown(flag)\n\nShut down the reading side of the socket (flag == SHUT_RD), the writing side\nof the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)."; |
2825 | |
2826 | #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
2827 | static PyObject* |
2828 | sock_ioctl(PySocketSockObject *s, PyObject *arg) |
2829 | { |
2830 | unsigned long cmd = SIO_RCVALL; |
2831 | PyObject *argO; |
2832 | DWORD recv; |
2833 | |
2834 | if (!PyArg_ParseTuple(arg, "kO:ioctl", &cmd, &argO)) |
2835 | return NULL((void*)0); |
2836 | |
2837 | switch (cmd) { |
2838 | case SIO_RCVALL: { |
2839 | unsigned int option = RCVALL_ON; |
2840 | if (!PyArg_ParseTuple(arg, "kI:ioctl", &cmd, &option)) |
2841 | return NULL((void*)0); |
2842 | if (WSAIoctl(s->sock_fd, cmd, &option, sizeof(option), |
2843 | NULL((void*)0), 0, &recv, NULL((void*)0), NULL((void*)0)) == SOCKET_ERROR) { |
2844 | return set_error(); |
2845 | } |
2846 | return PyLong_FromUnsignedLong(recv); } |
2847 | case SIO_KEEPALIVE_VALS: { |
2848 | struct tcp_keepalive ka; |
2849 | if (!PyArg_ParseTuple(arg, "k(kkk):ioctl", &cmd, |
2850 | &ka.onoff, &ka.keepalivetime, &ka.keepaliveinterval)) |
2851 | return NULL((void*)0); |
2852 | if (WSAIoctl(s->sock_fd, cmd, &ka, sizeof(ka), |
2853 | NULL((void*)0), 0, &recv, NULL((void*)0), NULL((void*)0)) == SOCKET_ERROR) { |
2854 | return set_error(); |
2855 | } |
2856 | return PyLong_FromUnsignedLong(recv); } |
2857 | default: |
2858 | PyErr_Format(PyExc_ValueError, "invalid ioctl command %d", cmd); |
2859 | return NULL((void*)0); |
2860 | } |
2861 | } |
2862 | PyDoc_STRVAR(sock_ioctl_doc,static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)." |
2863 | "ioctl(cmd, option) -> long\n\static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)." |
2864 | \n\static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)." |
2865 | Control the socket with WSAIoctl syscall. Currently supported 'cmd' values are\n\static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)." |
2866 | SIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\n\static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)." |
2867 | SIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval).")static char sock_ioctl_doc[] = "ioctl(cmd, option) -> long\n\nControl the socket with WSAIoctl syscall. Currently supported 'cmd' values are\nSIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\nSIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)."; |
2868 | |
2869 | #endif |
2870 | |
2871 | /* List of methods for socket objects */ |
2872 | |
2873 | static PyMethodDef sock_methods[] = { |
2874 | {"_accept", (PyCFunction)sock_accept, METH_NOARGS0x0004, |
2875 | accept_doc}, |
2876 | {"bind", (PyCFunction)sock_bind, METH_O0x0008, |
2877 | bind_doc}, |
2878 | {"close", (PyCFunction)sock_close, METH_NOARGS0x0004, |
2879 | close_doc}, |
2880 | {"connect", (PyCFunction)sock_connect, METH_O0x0008, |
2881 | connect_doc}, |
2882 | {"connect_ex", (PyCFunction)sock_connect_ex, METH_O0x0008, |
2883 | connect_ex_doc}, |
2884 | {"detach", (PyCFunction)sock_detach, METH_NOARGS0x0004, |
2885 | detach_doc}, |
2886 | {"fileno", (PyCFunction)sock_fileno, METH_NOARGS0x0004, |
2887 | fileno_doc}, |
2888 | #ifdef HAVE_GETPEERNAME1 |
2889 | {"getpeername", (PyCFunction)sock_getpeername, |
2890 | METH_NOARGS0x0004, getpeername_doc}, |
2891 | #endif |
2892 | {"getsockname", (PyCFunction)sock_getsockname, |
2893 | METH_NOARGS0x0004, getsockname_doc}, |
2894 | {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS0x0001, |
2895 | getsockopt_doc}, |
2896 | #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
2897 | {"ioctl", (PyCFunction)sock_ioctl, METH_VARARGS0x0001, |
2898 | sock_ioctl_doc}, |
2899 | #endif |
2900 | {"listen", (PyCFunction)sock_listen, METH_O0x0008, |
2901 | listen_doc}, |
2902 | {"recv", (PyCFunction)sock_recv, METH_VARARGS0x0001, |
2903 | recv_doc}, |
2904 | {"recv_into", (PyCFunction)sock_recv_into, METH_VARARGS0x0001 | METH_KEYWORDS0x0002, |
2905 | recv_into_doc}, |
2906 | {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS0x0001, |
2907 | recvfrom_doc}, |
2908 | {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS0x0001 | METH_KEYWORDS0x0002, |
2909 | recvfrom_into_doc}, |
2910 | {"send", (PyCFunction)sock_send, METH_VARARGS0x0001, |
2911 | send_doc}, |
2912 | {"sendall", (PyCFunction)sock_sendall, METH_VARARGS0x0001, |
2913 | sendall_doc}, |
2914 | {"sendto", (PyCFunction)sock_sendto, METH_VARARGS0x0001, |
2915 | sendto_doc}, |
2916 | {"setblocking", (PyCFunction)sock_setblocking, METH_O0x0008, |
2917 | setblocking_doc}, |
2918 | {"settimeout", (PyCFunction)sock_settimeout, METH_O0x0008, |
2919 | settimeout_doc}, |
2920 | {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS0x0004, |
2921 | gettimeout_doc}, |
2922 | {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS0x0001, |
2923 | setsockopt_doc}, |
2924 | {"shutdown", (PyCFunction)sock_shutdown, METH_O0x0008, |
2925 | shutdown_doc}, |
2926 | {NULL((void*)0), NULL((void*)0)} /* sentinel */ |
2927 | }; |
2928 | |
2929 | /* SockObject members */ |
2930 | static PyMemberDef sock_memberlist[] = { |
2931 | {"family", T_INT1, offsetof(PySocketSockObject, sock_family)__builtin_offsetof(PySocketSockObject, sock_family), READONLY1, "the socket family"}, |
2932 | {"type", T_INT1, offsetof(PySocketSockObject, sock_type)__builtin_offsetof(PySocketSockObject, sock_type), READONLY1, "the socket type"}, |
2933 | {"proto", T_INT1, offsetof(PySocketSockObject, sock_proto)__builtin_offsetof(PySocketSockObject, sock_proto), READONLY1, "the socket protocol"}, |
2934 | {"timeout", T_DOUBLE4, offsetof(PySocketSockObject, sock_timeout)__builtin_offsetof(PySocketSockObject, sock_timeout), READONLY1, "the socket timeout"}, |
2935 | {0}, |
2936 | }; |
2937 | |
2938 | /* Deallocate a socket object in response to the last Py_DECREF(). |
2939 | First close the file description. */ |
2940 | |
2941 | static void |
2942 | sock_dealloc(PySocketSockObject *s) |
2943 | { |
2944 | if (s->sock_fd != -1) { |
2945 | PyObject *exc, *val, *tb; |
2946 | Py_ssize_t old_refcount = Py_REFCNT(s)(((PyObject*)(s))->ob_refcnt); |
2947 | ++Py_REFCNT(s)(((PyObject*)(s))->ob_refcnt); |
2948 | PyErr_Fetch(&exc, &val, &tb); |
2949 | if (PyErr_WarnFormat(PyExc_ResourceWarning, 1, |
2950 | "unclosed %R", s)) |
2951 | /* Spurious errors can appear at shutdown */ |
2952 | if (PyErr_ExceptionMatches(PyExc_Warning)) |
2953 | PyErr_WriteUnraisable((PyObject *) s); |
2954 | PyErr_Restore(exc, val, tb); |
2955 | (void) SOCKETCLOSEclose(s->sock_fd); |
2956 | Py_REFCNT(s)(((PyObject*)(s))->ob_refcnt) = old_refcount; |
2957 | } |
2958 | Py_TYPE(s)(((PyObject*)(s))->ob_type)->tp_free((PyObject *)s); |
2959 | } |
2960 | |
2961 | |
2962 | static PyObject * |
2963 | sock_repr(PySocketSockObject *s) |
2964 | { |
2965 | #if SIZEOF_SOCKET_T4 > SIZEOF_LONG8 |
2966 | if (s->sock_fd > LONG_MAX9223372036854775807L) { |
2967 | /* this can occur on Win64, and actually there is a special |
2968 | ugly printf formatter for decimal pointer length integer |
2969 | printing, only bother if necessary*/ |
2970 | PyErr_SetString(PyExc_OverflowError, |
2971 | "no printf formatter to display " |
2972 | "the socket descriptor in decimal"); |
2973 | return NULL((void*)0); |
2974 | } |
2975 | #endif |
2976 | return PyUnicode_FromFormatPyUnicodeUCS2_FromFormat( |
2977 | "<socket object, fd=%ld, family=%d, type=%d, proto=%d>", |
2978 | (long)s->sock_fd, s->sock_family, |
2979 | s->sock_type, |
2980 | s->sock_proto); |
2981 | } |
2982 | |
2983 | |
2984 | /* Create a new, uninitialized socket object. */ |
2985 | |
2986 | static PyObject * |
2987 | sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
2988 | { |
2989 | PyObject *new; |
2990 | |
2991 | new = type->tp_alloc(type, 0); |
2992 | if (new != NULL((void*)0)) { |
2993 | ((PySocketSockObject *)new)->sock_fd = -1; |
2994 | ((PySocketSockObject *)new)->sock_timeout = -1.0; |
2995 | ((PySocketSockObject *)new)->errorhandler = &set_error; |
2996 | } |
2997 | return new; |
2998 | } |
2999 | |
3000 | |
3001 | /* Initialize a new socket object. */ |
3002 | |
3003 | /*ARGSUSED*/ |
3004 | static int |
3005 | sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) |
3006 | { |
3007 | PySocketSockObject *s = (PySocketSockObject *)self; |
3008 | PyObject *fdobj = NULL((void*)0); |
3009 | SOCKET_T fd = INVALID_SOCKET(-1); |
3010 | int family = AF_INET2, type = SOCK_STREAM1, proto = 0; |
3011 | static char *keywords[] = {"family", "type", "proto", "fileno", 0}; |
3012 | |
3013 | if (!PyArg_ParseTupleAndKeywords(args, kwds, |
3014 | "|iiiO:socket", keywords, |
3015 | &family, &type, &proto, &fdobj)) |
3016 | return -1; |
3017 | |
3018 | if (fdobj != NULL((void*)0) && fdobj != Py_None(&_Py_NoneStruct)) { |
3019 | fd = PyLong_AsSocket_t(fdobj)(SOCKET_T)PyLong_AsLong(fdobj); |
3020 | if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) |
3021 | return -1; |
3022 | if (fd == INVALID_SOCKET(-1)) { |
3023 | PyErr_SetString(PyExc_ValueError, |
3024 | "can't use invalid socket value"); |
3025 | return -1; |
3026 | } |
3027 | } |
3028 | else { |
3029 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3030 | fd = socket(family, type, proto); |
3031 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3032 | |
3033 | if (fd == INVALID_SOCKET(-1)) { |
3034 | set_error(); |
3035 | return -1; |
3036 | } |
3037 | } |
3038 | init_sockobject(s, fd, family, type, proto); |
3039 | |
3040 | return 0; |
3041 | |
3042 | } |
3043 | |
3044 | |
3045 | /* Type object for socket objects. */ |
3046 | |
3047 | static PyTypeObject sock_type = { |
3048 | PyVarObject_HEAD_INIT(0, 0){ { 0, 0, 1, 0 }, 0 }, /* Must fill in type value later */ |
3049 | "_socket.socket", /* tp_name */ |
3050 | sizeof(PySocketSockObject), /* tp_basicsize */ |
3051 | 0, /* tp_itemsize */ |
3052 | (destructor)sock_dealloc, /* tp_dealloc */ |
3053 | 0, /* tp_print */ |
3054 | 0, /* tp_getattr */ |
3055 | 0, /* tp_setattr */ |
3056 | 0, /* tp_reserved */ |
3057 | (reprfunc)sock_repr, /* tp_repr */ |
3058 | 0, /* tp_as_number */ |
3059 | 0, /* tp_as_sequence */ |
3060 | 0, /* tp_as_mapping */ |
3061 | 0, /* tp_hash */ |
3062 | 0, /* tp_call */ |
3063 | 0, /* tp_str */ |
3064 | PyObject_GenericGetAttr, /* tp_getattro */ |
3065 | 0, /* tp_setattro */ |
3066 | 0, /* tp_as_buffer */ |
3067 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_BASETYPE(1L<<10), /* tp_flags */ |
3068 | sock_doc, /* tp_doc */ |
3069 | 0, /* tp_traverse */ |
3070 | 0, /* tp_clear */ |
3071 | 0, /* tp_richcompare */ |
3072 | 0, /* tp_weaklistoffset */ |
3073 | 0, /* tp_iter */ |
3074 | 0, /* tp_iternext */ |
3075 | sock_methods, /* tp_methods */ |
3076 | sock_memberlist, /* tp_members */ |
3077 | 0, /* tp_getset */ |
3078 | 0, /* tp_base */ |
3079 | 0, /* tp_dict */ |
3080 | 0, /* tp_descr_get */ |
3081 | 0, /* tp_descr_set */ |
3082 | 0, /* tp_dictoffset */ |
3083 | sock_initobj, /* tp_init */ |
3084 | PyType_GenericAlloc, /* tp_alloc */ |
3085 | sock_new, /* tp_new */ |
3086 | PyObject_Del_PyObject_DebugFree, /* tp_free */ |
3087 | }; |
3088 | |
3089 | |
3090 | /* Python interface to gethostname(). */ |
3091 | |
3092 | /*ARGSUSED*/ |
3093 | static PyObject * |
3094 | socket_gethostname(PyObject *self, PyObject *unused) |
3095 | { |
3096 | #ifdef MS_WINDOWS |
3097 | /* Don't use winsock's gethostname, as this returns the ANSI |
3098 | version of the hostname, whereas we need a Unicode string. |
3099 | Otherwise, gethostname apparently also returns the DNS name. */ |
3100 | wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1]; |
3101 | DWORD size = sizeof(buf) / sizeof(wchar_t); |
3102 | PyObject *result; |
3103 | if (!GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) { |
3104 | if (GetLastError() == ERROR_MORE_DATA) { |
3105 | /* MSDN says this may occur "because DNS allows longer names */ |
3106 | if (size == 0) /* XXX: I'm not sure how to handle this */ |
3107 | return PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), 0); |
3108 | result = PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), size - 1); |
3109 | if (!result) |
3110 | return NULL((void*)0); |
3111 | if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, |
3112 | PyUnicode_AS_UNICODE(result)((__builtin_expect(!(((((((PyObject*)(result))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 3112 , "PyUnicode_Check(result)") : (void)0),(((PyUnicodeObject *) (result))->str)), |
3113 | &size)) |
3114 | return result; |
3115 | Py_DECREF(result)do { if (_Py_RefTotal-- , --((PyObject*)(result))->ob_refcnt != 0) { if (((PyObject*)result)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 3115 , (PyObject *)(result)); } else _Py_Dealloc((PyObject *)(result )); } while (0); |
3116 | } |
3117 | return PyErr_SetExcFromWindowsErr(PyExc_WindowsError, GetLastError()); |
3118 | } |
3119 | return PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(buf, size); |
3120 | #else |
3121 | char buf[1024]; |
3122 | int res; |
3123 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3124 | res = gethostname(buf, (int) sizeof buf - 1); |
3125 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3126 | if (res < 0) |
3127 | return set_error(); |
3128 | buf[sizeof buf - 1] = '\0'; |
3129 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(buf); |
3130 | #endif |
3131 | } |
3132 | |
3133 | PyDoc_STRVAR(gethostname_doc,static char gethostname_doc[] = "gethostname() -> string\n\nReturn the current host name." |
3134 | "gethostname() -> string\n\static char gethostname_doc[] = "gethostname() -> string\n\nReturn the current host name." |
3135 | \n\static char gethostname_doc[] = "gethostname() -> string\n\nReturn the current host name." |
3136 | Return the current host name.")static char gethostname_doc[] = "gethostname() -> string\n\nReturn the current host name."; |
3137 | |
3138 | |
3139 | /* Python interface to gethostbyname(name). */ |
3140 | |
3141 | /*ARGSUSED*/ |
3142 | static PyObject * |
3143 | socket_gethostbyname(PyObject *self, PyObject *args) |
3144 | { |
3145 | char *name; |
3146 | sock_addr_t addrbuf; |
3147 | PyObject *ret = NULL((void*)0); |
3148 | |
3149 | if (!PyArg_ParseTuple(args, "et:gethostbyname", "idna", &name)) |
3150 | return NULL((void*)0); |
3151 | if (setipaddr(name, SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), sizeof(addrbuf), AF_INET2) < 0) |
3152 | goto finally; |
3153 | ret = makeipaddr(SAS2SA(&addrbuf)((struct sockaddr *)(&addrbuf)), sizeof(struct sockaddr_in)); |
3154 | finally: |
3155 | PyMem_Free(name); |
3156 | return ret; |
3157 | } |
3158 | |
3159 | PyDoc_STRVAR(gethostbyname_doc,static char gethostbyname_doc[] = "gethostbyname(host) -> address\n\nReturn the IP address (a string of the form '255.255.255.255') for a host." |
3160 | "gethostbyname(host) -> address\n\static char gethostbyname_doc[] = "gethostbyname(host) -> address\n\nReturn the IP address (a string of the form '255.255.255.255') for a host." |
3161 | \n\static char gethostbyname_doc[] = "gethostbyname(host) -> address\n\nReturn the IP address (a string of the form '255.255.255.255') for a host." |
3162 | Return the IP address (a string of the form '255.255.255.255') for a host.")static char gethostbyname_doc[] = "gethostbyname(host) -> address\n\nReturn the IP address (a string of the form '255.255.255.255') for a host."; |
3163 | |
3164 | |
3165 | /* Convenience function common to gethostbyname_ex and gethostbyaddr */ |
3166 | |
3167 | static PyObject * |
3168 | gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af) |
3169 | { |
3170 | char **pch; |
3171 | PyObject *rtn_tuple = (PyObject *)NULL((void*)0); |
3172 | PyObject *name_list = (PyObject *)NULL((void*)0); |
3173 | PyObject *addr_list = (PyObject *)NULL((void*)0); |
3174 | PyObject *tmp; |
3175 | |
3176 | if (h == NULL((void*)0)) { |
3177 | /* Let's get real error message to return */ |
3178 | set_herror(h_errno); |
3179 | return NULL((void*)0); |
3180 | } |
3181 | |
3182 | if (h->h_addrtype != af) { |
3183 | /* Let's get real error message to return */ |
3184 | PyErr_SetString(socket_error, |
3185 | (char *)strerror(EAFNOSUPPORT47)); |
3186 | |
3187 | return NULL((void*)0); |
3188 | } |
3189 | |
3190 | switch (af) { |
3191 | |
3192 | case AF_INET2: |
3193 | if (alen < sizeof(struct sockaddr_in)) |
3194 | return NULL((void*)0); |
3195 | break; |
3196 | |
3197 | #ifdef ENABLE_IPV61 |
3198 | case AF_INET630: |
3199 | if (alen < sizeof(struct sockaddr_in6)) |
3200 | return NULL((void*)0); |
3201 | break; |
3202 | #endif |
3203 | |
3204 | } |
3205 | |
3206 | if ((name_list = PyList_New(0)) == NULL((void*)0)) |
3207 | goto err; |
3208 | |
3209 | if ((addr_list = PyList_New(0)) == NULL((void*)0)) |
3210 | goto err; |
3211 | |
3212 | /* SF #1511317: h_aliases can be NULL */ |
3213 | if (h->h_aliases) { |
3214 | for (pch = h->h_aliases; *pch != NULL((void*)0); pch++) { |
3215 | int status; |
3216 | tmp = PyUnicode_FromStringPyUnicodeUCS2_FromString(*pch); |
3217 | if (tmp == NULL((void*)0)) |
3218 | goto err; |
3219 | |
3220 | status = PyList_Append(name_list, tmp); |
3221 | Py_DECREF(tmp)do { if (_Py_RefTotal-- , --((PyObject*)(tmp))->ob_refcnt != 0) { if (((PyObject*)tmp)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 3221 , (PyObject *)(tmp)); } else _Py_Dealloc((PyObject *)(tmp)); } while (0); |
3222 | |
3223 | if (status) |
3224 | goto err; |
3225 | } |
3226 | } |
3227 | |
3228 | for (pch = h->h_addr_list; *pch != NULL((void*)0); pch++) { |
3229 | int status; |
3230 | |
3231 | switch (af) { |
3232 | |
3233 | case AF_INET2: |
3234 | { |
3235 | struct sockaddr_in sin; |
3236 | memset(&sin, 0, sizeof(sin))((__builtin_object_size (&sin, 0) != (size_t) -1) ? __builtin___memset_chk (&sin, 0, sizeof(sin), __builtin_object_size (&sin, 0 )) : __inline_memset_chk (&sin, 0, sizeof(sin))); |
3237 | sin.sin_family = af; |
3238 | #ifdef HAVE_SOCKADDR_SA_LEN1 |
3239 | sin.sin_len = sizeof(sin); |
3240 | #endif |
3241 | memcpy(&sin.sin_addr, *pch, sizeof(sin.sin_addr))((__builtin_object_size (&sin.sin_addr, 0) != (size_t) -1 ) ? __builtin___memcpy_chk (&sin.sin_addr, *pch, sizeof(sin .sin_addr), __builtin_object_size (&sin.sin_addr, 0)) : __inline_memcpy_chk (&sin.sin_addr, *pch, sizeof(sin.sin_addr))); |
3242 | tmp = makeipaddr((struct sockaddr *)&sin, sizeof(sin)); |
3243 | |
3244 | if (pch == h->h_addr_list && alen >= sizeof(sin)) |
3245 | memcpy((char *) addr, &sin, sizeof(sin))((__builtin_object_size ((char *) addr, 0) != (size_t) -1) ? __builtin___memcpy_chk ((char *) addr, &sin, sizeof(sin), __builtin_object_size ((char *) addr, 0)) : __inline_memcpy_chk ((char *) addr, & sin, sizeof(sin))); |
3246 | break; |
3247 | } |
3248 | |
3249 | #ifdef ENABLE_IPV61 |
3250 | case AF_INET630: |
3251 | { |
3252 | struct sockaddr_in6 sin6; |
3253 | memset(&sin6, 0, sizeof(sin6))((__builtin_object_size (&sin6, 0) != (size_t) -1) ? __builtin___memset_chk (&sin6, 0, sizeof(sin6), __builtin_object_size (&sin6 , 0)) : __inline_memset_chk (&sin6, 0, sizeof(sin6))); |
3254 | sin6.sin6_family = af; |
3255 | #ifdef HAVE_SOCKADDR_SA_LEN1 |
3256 | sin6.sin6_len = sizeof(sin6); |
3257 | #endif |
3258 | memcpy(&sin6.sin6_addr, *pch, sizeof(sin6.sin6_addr))((__builtin_object_size (&sin6.sin6_addr, 0) != (size_t) - 1) ? __builtin___memcpy_chk (&sin6.sin6_addr, *pch, sizeof (sin6.sin6_addr), __builtin_object_size (&sin6.sin6_addr, 0)) : __inline_memcpy_chk (&sin6.sin6_addr, *pch, sizeof (sin6.sin6_addr))); |
3259 | tmp = makeipaddr((struct sockaddr *)&sin6, |
3260 | sizeof(sin6)); |
3261 | |
3262 | if (pch == h->h_addr_list && alen >= sizeof(sin6)) |
3263 | memcpy((char *) addr, &sin6, sizeof(sin6))((__builtin_object_size ((char *) addr, 0) != (size_t) -1) ? __builtin___memcpy_chk ((char *) addr, &sin6, sizeof(sin6), __builtin_object_size ((char *) addr, 0)) : __inline_memcpy_chk ((char *) addr, & sin6, sizeof(sin6))); |
3264 | break; |
3265 | } |
3266 | #endif |
3267 | |
3268 | default: /* can't happen */ |
3269 | PyErr_SetString(socket_error, |
3270 | "unsupported address family"); |
3271 | return NULL((void*)0); |
3272 | } |
3273 | |
3274 | if (tmp == NULL((void*)0)) |
3275 | goto err; |
3276 | |
3277 | status = PyList_Append(addr_list, tmp); |
3278 | Py_DECREF(tmp)do { if (_Py_RefTotal-- , --((PyObject*)(tmp))->ob_refcnt != 0) { if (((PyObject*)tmp)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 3278 , (PyObject *)(tmp)); } else _Py_Dealloc((PyObject *)(tmp)); } while (0); |
3279 | |
3280 | if (status) |
3281 | goto err; |
3282 | } |
3283 | |
3284 | rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); |
3285 | |
3286 | err: |
3287 | Py_XDECREF(name_list)do { if ((name_list) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(name_list))->ob_refcnt != 0) { if (((PyObject *)name_list)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 3287, (PyObject *)(name_list)); } else _Py_Dealloc((PyObject *)(name_list)); } while (0); } while (0); |
3288 | Py_XDECREF(addr_list)do { if ((addr_list) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(addr_list))->ob_refcnt != 0) { if (((PyObject *)addr_list)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 3288, (PyObject *)(addr_list)); } else _Py_Dealloc((PyObject *)(addr_list)); } while (0); } while (0); |
3289 | return rtn_tuple; |
3290 | } |
3291 | |
3292 | |
3293 | /* Python interface to gethostbyname_ex(name). */ |
3294 | |
3295 | /*ARGSUSED*/ |
3296 | static PyObject * |
3297 | socket_gethostbyname_ex(PyObject *self, PyObject *args) |
3298 | { |
3299 | char *name; |
3300 | struct hostent *h; |
3301 | #ifdef ENABLE_IPV61 |
3302 | struct sockaddr_storage addr; |
3303 | #else |
3304 | struct sockaddr_in addr; |
3305 | #endif |
3306 | struct sockaddr *sa; |
3307 | PyObject *ret = NULL((void*)0); |
3308 | #ifdef HAVE_GETHOSTBYNAME_R |
3309 | struct hostent hp_allocated; |
3310 | #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
3311 | struct hostent_data data; |
3312 | #else |
3313 | char buf[16384]; |
3314 | int buf_len = (sizeof buf) - 1; |
3315 | int errnop; |
3316 | #endif |
3317 | #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
3318 | int result; |
3319 | #endif |
3320 | #endif /* HAVE_GETHOSTBYNAME_R */ |
3321 | |
3322 | if (!PyArg_ParseTuple(args, "et:gethostbyname_ex", "idna", &name)) |
3323 | return NULL((void*)0); |
3324 | if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), AF_INET2) < 0) |
3325 | goto finally; |
3326 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3327 | #ifdef HAVE_GETHOSTBYNAME_R |
3328 | #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
3329 | result = gethostbyname_r(name, &hp_allocated, buf, buf_len, |
3330 | &h, &errnop); |
3331 | #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
3332 | h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop); |
3333 | #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
3334 | memset((void *) &data, '\0', sizeof(data))((__builtin_object_size ((void *) &data, 0) != (size_t) - 1) ? __builtin___memset_chk ((void *) &data, '\0', sizeof (data), __builtin_object_size ((void *) &data, 0)) : __inline_memset_chk ((void *) &data, '\0', sizeof(data))); |
3335 | result = gethostbyname_r(name, &hp_allocated, &data); |
3336 | h = (result != 0) ? NULL((void*)0) : &hp_allocated; |
3337 | #endif |
3338 | #else /* not HAVE_GETHOSTBYNAME_R */ |
3339 | #ifdef USE_GETHOSTBYNAME_LOCK |
3340 | PyThread_acquire_lock(netdb_lock, 1); |
3341 | #endif |
3342 | h = gethostbyname(name); |
3343 | #endif /* HAVE_GETHOSTBYNAME_R */ |
3344 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3345 | /* Some C libraries would require addr.__ss_family instead of |
3346 | addr.ss_family. |
3347 | Therefore, we cast the sockaddr_storage into sockaddr to |
3348 | access sa_family. */ |
3349 | sa = (struct sockaddr*)&addr; |
3350 | ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), |
3351 | sa->sa_family); |
3352 | #ifdef USE_GETHOSTBYNAME_LOCK |
3353 | PyThread_release_lock(netdb_lock); |
3354 | #endif |
3355 | finally: |
3356 | PyMem_Free(name); |
3357 | return ret; |
3358 | } |
3359 | |
3360 | PyDoc_STRVAR(ghbn_ex_doc,static char ghbn_ex_doc[] = "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3361 | "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\static char ghbn_ex_doc[] = "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3362 | \n\static char ghbn_ex_doc[] = "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3363 | Return the true host name, a list of aliases, and a list of IP addresses,\n\static char ghbn_ex_doc[] = "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3364 | for a host. The host argument is a string giving a host name or IP number.")static char ghbn_ex_doc[] = "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number."; |
3365 | |
3366 | |
3367 | /* Python interface to gethostbyaddr(IP). */ |
3368 | |
3369 | /*ARGSUSED*/ |
3370 | static PyObject * |
3371 | socket_gethostbyaddr(PyObject *self, PyObject *args) |
3372 | { |
3373 | #ifdef ENABLE_IPV61 |
3374 | struct sockaddr_storage addr; |
3375 | #else |
3376 | struct sockaddr_in addr; |
3377 | #endif |
3378 | struct sockaddr *sa = (struct sockaddr *)&addr; |
3379 | char *ip_num; |
3380 | struct hostent *h; |
3381 | PyObject *ret = NULL((void*)0); |
3382 | #ifdef HAVE_GETHOSTBYNAME_R |
3383 | struct hostent hp_allocated; |
3384 | #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
3385 | struct hostent_data data; |
3386 | #else |
3387 | /* glibcs up to 2.10 assume that the buf argument to |
3388 | gethostbyaddr_r is 8-byte aligned, which at least llvm-gcc |
3389 | does not ensure. The attribute below instructs the compiler |
3390 | to maintain this alignment. */ |
3391 | char buf[16384] Py_ALIGNED(8)__attribute__((aligned(8))); |
3392 | int buf_len = (sizeof buf) - 1; |
3393 | int errnop; |
3394 | #endif |
3395 | #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
3396 | int result; |
3397 | #endif |
3398 | #endif /* HAVE_GETHOSTBYNAME_R */ |
3399 | char *ap; |
3400 | int al; |
3401 | int af; |
3402 | |
3403 | if (!PyArg_ParseTuple(args, "et:gethostbyaddr", "idna", &ip_num)) |
3404 | return NULL((void*)0); |
3405 | af = AF_UNSPEC0; |
3406 | if (setipaddr(ip_num, sa, sizeof(addr), af) < 0) |
3407 | goto finally; |
3408 | af = sa->sa_family; |
3409 | ap = NULL((void*)0); |
3410 | al = 0; |
Value stored to 'al' is never read | |
3411 | switch (af) { |
3412 | case AF_INET2: |
3413 | ap = (char *)&((struct sockaddr_in *)sa)->sin_addr; |
3414 | al = sizeof(((struct sockaddr_in *)sa)->sin_addr); |
3415 | break; |
3416 | #ifdef ENABLE_IPV61 |
3417 | case AF_INET630: |
3418 | ap = (char *)&((struct sockaddr_in6 *)sa)->sin6_addr; |
3419 | al = sizeof(((struct sockaddr_in6 *)sa)->sin6_addr); |
3420 | break; |
3421 | #endif |
3422 | default: |
3423 | PyErr_SetString(socket_error, "unsupported address family"); |
3424 | goto finally; |
3425 | } |
3426 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3427 | #ifdef HAVE_GETHOSTBYNAME_R |
3428 | #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
3429 | result = gethostbyaddr_r(ap, al, af, |
3430 | &hp_allocated, buf, buf_len, |
3431 | &h, &errnop); |
3432 | #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
3433 | h = gethostbyaddr_r(ap, al, af, |
3434 | &hp_allocated, buf, buf_len, &errnop); |
3435 | #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
3436 | memset((void *) &data, '\0', sizeof(data))((__builtin_object_size ((void *) &data, 0) != (size_t) - 1) ? __builtin___memset_chk ((void *) &data, '\0', sizeof (data), __builtin_object_size ((void *) &data, 0)) : __inline_memset_chk ((void *) &data, '\0', sizeof(data))); |
3437 | result = gethostbyaddr_r(ap, al, af, &hp_allocated, &data); |
3438 | h = (result != 0) ? NULL((void*)0) : &hp_allocated; |
3439 | #endif |
3440 | #else /* not HAVE_GETHOSTBYNAME_R */ |
3441 | #ifdef USE_GETHOSTBYNAME_LOCK |
3442 | PyThread_acquire_lock(netdb_lock, 1); |
3443 | #endif |
3444 | h = gethostbyaddr(ap, al, af); |
3445 | #endif /* HAVE_GETHOSTBYNAME_R */ |
3446 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3447 | ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), af); |
3448 | #ifdef USE_GETHOSTBYNAME_LOCK |
3449 | PyThread_release_lock(netdb_lock); |
3450 | #endif |
3451 | finally: |
3452 | PyMem_Free(ip_num); |
3453 | return ret; |
3454 | } |
3455 | |
3456 | PyDoc_STRVAR(gethostbyaddr_doc,static char gethostbyaddr_doc[] = "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3457 | "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\static char gethostbyaddr_doc[] = "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3458 | \n\static char gethostbyaddr_doc[] = "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3459 | Return the true host name, a list of aliases, and a list of IP addresses,\n\static char gethostbyaddr_doc[] = "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number." |
3460 | for a host. The host argument is a string giving a host name or IP number.")static char gethostbyaddr_doc[] = "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\nReturn the true host name, a list of aliases, and a list of IP addresses,\nfor a host. The host argument is a string giving a host name or IP number."; |
3461 | |
3462 | |
3463 | /* Python interface to getservbyname(name). |
3464 | This only returns the port number, since the other info is already |
3465 | known or not useful (like the list of aliases). */ |
3466 | |
3467 | /*ARGSUSED*/ |
3468 | static PyObject * |
3469 | socket_getservbyname(PyObject *self, PyObject *args) |
3470 | { |
3471 | char *name, *proto=NULL((void*)0); |
3472 | struct servent *sp; |
3473 | if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)) |
3474 | return NULL((void*)0); |
3475 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3476 | sp = getservbyname(name, proto); |
3477 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3478 | if (sp == NULL((void*)0)) { |
3479 | PyErr_SetString(socket_error, "service/proto not found"); |
3480 | return NULL((void*)0); |
3481 | } |
3482 | return PyLong_FromLong((long) ntohs(sp->s_port)(__builtin_constant_p(sp->s_port) ? ((__uint16_t)((((__uint16_t )(sp->s_port) & 0xff00) >> 8) | (((__uint16_t)(sp ->s_port) & 0x00ff) << 8))) : _OSSwapInt16(sp-> s_port))); |
3483 | } |
3484 | |
3485 | PyDoc_STRVAR(getservbyname_doc,static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3486 | "getservbyname(servicename[, protocolname]) -> integer\n\static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3487 | \n\static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3488 | Return a port number from a service name and protocol name.\n\static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3489 | The optional protocol name, if given, should be 'tcp' or 'udp',\n\static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3490 | otherwise any protocol will match.")static char getservbyname_doc[] = "getservbyname(servicename[, protocolname]) -> integer\n\nReturn a port number from a service name and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match."; |
3491 | |
3492 | |
3493 | /* Python interface to getservbyport(port). |
3494 | This only returns the service name, since the other info is already |
3495 | known or not useful (like the list of aliases). */ |
3496 | |
3497 | /*ARGSUSED*/ |
3498 | static PyObject * |
3499 | socket_getservbyport(PyObject *self, PyObject *args) |
3500 | { |
3501 | int port; |
3502 | char *proto=NULL((void*)0); |
3503 | struct servent *sp; |
3504 | if (!PyArg_ParseTuple(args, "i|s:getservbyport", &port, &proto)) |
3505 | return NULL((void*)0); |
3506 | if (port < 0 || port > 0xffff) { |
3507 | PyErr_SetString( |
3508 | PyExc_OverflowError, |
3509 | "getservbyport: port must be 0-65535."); |
3510 | return NULL((void*)0); |
3511 | } |
3512 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3513 | sp = getservbyport(htons((short)port)(__builtin_constant_p((short)port) ? ((__uint16_t)((((__uint16_t )((short)port) & 0xff00) >> 8) | (((__uint16_t)((short )port) & 0x00ff) << 8))) : _OSSwapInt16((short)port )), proto); |
3514 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3515 | if (sp == NULL((void*)0)) { |
3516 | PyErr_SetString(socket_error, "port/proto not found"); |
3517 | return NULL((void*)0); |
3518 | } |
3519 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(sp->s_name); |
3520 | } |
3521 | |
3522 | PyDoc_STRVAR(getservbyport_doc,static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3523 | "getservbyport(port[, protocolname]) -> string\n\static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3524 | \n\static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3525 | Return the service name from a port number and protocol name.\n\static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3526 | The optional protocol name, if given, should be 'tcp' or 'udp',\n\static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match." |
3527 | otherwise any protocol will match.")static char getservbyport_doc[] = "getservbyport(port[, protocolname]) -> string\n\nReturn the service name from a port number and protocol name.\nThe optional protocol name, if given, should be 'tcp' or 'udp',\notherwise any protocol will match."; |
3528 | |
3529 | /* Python interface to getprotobyname(name). |
3530 | This only returns the protocol number, since the other info is |
3531 | already known or not useful (like the list of aliases). */ |
3532 | |
3533 | /*ARGSUSED*/ |
3534 | static PyObject * |
3535 | socket_getprotobyname(PyObject *self, PyObject *args) |
3536 | { |
3537 | char *name; |
3538 | struct protoent *sp; |
3539 | if (!PyArg_ParseTuple(args, "s:getprotobyname", &name)) |
3540 | return NULL((void*)0); |
3541 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
3542 | sp = getprotobyname(name); |
3543 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
3544 | if (sp == NULL((void*)0)) { |
3545 | PyErr_SetString(socket_error, "protocol not found"); |
3546 | return NULL((void*)0); |
3547 | } |
3548 | return PyLong_FromLong((long) sp->p_proto); |
3549 | } |
3550 | |
3551 | PyDoc_STRVAR(getprotobyname_doc,static char getprotobyname_doc[] = "getprotobyname(name) -> integer\n\nReturn the protocol number for the named protocol. (Rarely used.)" |
3552 | "getprotobyname(name) -> integer\n\static char getprotobyname_doc[] = "getprotobyname(name) -> integer\n\nReturn the protocol number for the named protocol. (Rarely used.)" |
3553 | \n\static char getprotobyname_doc[] = "getprotobyname(name) -> integer\n\nReturn the protocol number for the named protocol. (Rarely used.)" |
3554 | Return the protocol number for the named protocol. (Rarely used.)")static char getprotobyname_doc[] = "getprotobyname(name) -> integer\n\nReturn the protocol number for the named protocol. (Rarely used.)"; |
3555 | |
3556 | |
3557 | #ifndef NO_DUP |
3558 | /* dup() function for socket fds */ |
3559 | |
3560 | static PyObject * |
3561 | socket_dup(PyObject *self, PyObject *fdobj) |
3562 | { |
3563 | SOCKET_T fd, newfd; |
3564 | PyObject *newfdobj; |
3565 | |
3566 | |
3567 | fd = PyLong_AsSocket_t(fdobj)(SOCKET_T)PyLong_AsLong(fdobj); |
3568 | if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) |
3569 | return NULL((void*)0); |
3570 | |
3571 | newfd = dup_socket(fd)dup(fd); |
3572 | if (newfd == INVALID_SOCKET(-1)) |
3573 | return set_error(); |
3574 | |
3575 | newfdobj = PyLong_FromSocket_t(newfd)PyLong_FromLong((SOCKET_T)(newfd)); |
3576 | if (newfdobj == NULL((void*)0)) |
3577 | SOCKETCLOSEclose(newfd); |
3578 | return newfdobj; |
3579 | } |
3580 | |
3581 | PyDoc_STRVAR(dup_doc,static char dup_doc[] = "dup(integer) -> integer\n\nDuplicate an integer socket file descriptor. This is like os.dup(), but for\nsockets; on some platforms os.dup() won't work for socket file descriptors." |
3582 | "dup(integer) -> integer\n\static char dup_doc[] = "dup(integer) -> integer\n\nDuplicate an integer socket file descriptor. This is like os.dup(), but for\nsockets; on some platforms os.dup() won't work for socket file descriptors." |
3583 | \n\static char dup_doc[] = "dup(integer) -> integer\n\nDuplicate an integer socket file descriptor. This is like os.dup(), but for\nsockets; on some platforms os.dup() won't work for socket file descriptors." |
3584 | Duplicate an integer socket file descriptor. This is like os.dup(), but for\n\static char dup_doc[] = "dup(integer) -> integer\n\nDuplicate an integer socket file descriptor. This is like os.dup(), but for\nsockets; on some platforms os.dup() won't work for socket file descriptors." |
3585 | sockets; on some platforms os.dup() won't work for socket file descriptors.")static char dup_doc[] = "dup(integer) -> integer\n\nDuplicate an integer socket file descriptor. This is like os.dup(), but for\nsockets; on some platforms os.dup() won't work for socket file descriptors."; |
3586 | #endif |
3587 | |
3588 | |
3589 | #ifdef HAVE_SOCKETPAIR1 |
3590 | /* Create a pair of sockets using the socketpair() function. |
3591 | Arguments as for socket() except the default family is AF_UNIX if |
3592 | defined on the platform; otherwise, the default is AF_INET. */ |
3593 | |
3594 | /*ARGSUSED*/ |
3595 | static PyObject * |
3596 | socket_socketpair(PyObject *self, PyObject *args) |
3597 | { |
3598 | PySocketSockObject *s0 = NULL((void*)0), *s1 = NULL((void*)0); |
3599 | SOCKET_T sv[2]; |
3600 | int family, type = SOCK_STREAM1, proto = 0; |
3601 | PyObject *res = NULL((void*)0); |
3602 | |
3603 | #if defined(AF_UNIX1) |
3604 | family = AF_UNIX1; |
3605 | #else |
3606 | family = AF_INET2; |
3607 | #endif |
3608 | if (!PyArg_ParseTuple(args, "|iii:socketpair", |
3609 | &family, &type, &proto)) |
3610 | return NULL((void*)0); |
3611 | /* Create a pair of socket fds */ |
3612 | if (socketpair(family, type, proto, sv) < 0) |
3613 | return set_error(); |
3614 | s0 = new_sockobject(sv[0], family, type, proto); |
3615 | if (s0 == NULL((void*)0)) |
3616 | goto finally; |
3617 | s1 = new_sockobject(sv[1], family, type, proto); |
3618 | if (s1 == NULL((void*)0)) |
3619 | goto finally; |
3620 | res = PyTuple_Pack(2, s0, s1); |
3621 | |
3622 | finally: |
3623 | if (res == NULL((void*)0)) { |
3624 | if (s0 == NULL((void*)0)) |
3625 | SOCKETCLOSEclose(sv[0]); |
3626 | if (s1 == NULL((void*)0)) |
3627 | SOCKETCLOSEclose(sv[1]); |
3628 | } |
3629 | Py_XDECREF(s0)do { if ((s0) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(s0))->ob_refcnt != 0) { if (((PyObject*)s0 )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 3629, (PyObject *)(s0)); } else _Py_Dealloc((PyObject *)(s0 )); } while (0); } while (0); |
3630 | Py_XDECREF(s1)do { if ((s1) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(s1))->ob_refcnt != 0) { if (((PyObject*)s1 )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 3630, (PyObject *)(s1)); } else _Py_Dealloc((PyObject *)(s1 )); } while (0); } while (0); |
3631 | return res; |
3632 | } |
3633 | |
3634 | PyDoc_STRVAR(socketpair_doc,static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3635 | "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3636 | \n\static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3637 | Create a pair of socket objects from the sockets returned by the platform\n\static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3638 | socketpair() function.\n\static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3639 | The arguments are the same as for socket() except the default family is\n\static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET." |
3640 | AF_UNIX if defined on the platform; otherwise, the default is AF_INET.")static char socketpair_doc[] = "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\nCreate a pair of socket objects from the sockets returned by the platform\nsocketpair() function.\nThe arguments are the same as for socket() except the default family is\nAF_UNIX if defined on the platform; otherwise, the default is AF_INET."; |
3641 | |
3642 | #endif /* HAVE_SOCKETPAIR */ |
3643 | |
3644 | |
3645 | static PyObject * |
3646 | socket_ntohs(PyObject *self, PyObject *args) |
3647 | { |
3648 | int x1, x2; |
3649 | |
3650 | if (!PyArg_ParseTuple(args, "i:ntohs", &x1)) { |
3651 | return NULL((void*)0); |
3652 | } |
3653 | if (x1 < 0) { |
3654 | PyErr_SetString(PyExc_OverflowError, |
3655 | "can't convert negative number to unsigned long"); |
3656 | return NULL((void*)0); |
3657 | } |
3658 | x2 = (unsigned int)ntohs((unsigned short)x1)(__builtin_constant_p((unsigned short)x1) ? ((__uint16_t)(((( __uint16_t)((unsigned short)x1) & 0xff00) >> 8) | ( ((__uint16_t)((unsigned short)x1) & 0x00ff) << 8))) : _OSSwapInt16((unsigned short)x1)); |
3659 | return PyLong_FromLong(x2); |
3660 | } |
3661 | |
3662 | PyDoc_STRVAR(ntohs_doc,static char ntohs_doc[] = "ntohs(integer) -> integer\n\nConvert a 16-bit integer from network to host byte order." |
3663 | "ntohs(integer) -> integer\n\static char ntohs_doc[] = "ntohs(integer) -> integer\n\nConvert a 16-bit integer from network to host byte order." |
3664 | \n\static char ntohs_doc[] = "ntohs(integer) -> integer\n\nConvert a 16-bit integer from network to host byte order." |
3665 | Convert a 16-bit integer from network to host byte order.")static char ntohs_doc[] = "ntohs(integer) -> integer\n\nConvert a 16-bit integer from network to host byte order."; |
3666 | |
3667 | |
3668 | static PyObject * |
3669 | socket_ntohl(PyObject *self, PyObject *arg) |
3670 | { |
3671 | unsigned long x; |
3672 | |
3673 | if (PyLong_Check(arg)((((((PyObject*)(arg))->ob_type))->tp_flags & ((1L<< 24))) != 0)) { |
3674 | x = PyLong_AsUnsignedLong(arg); |
3675 | if (x == (unsigned long) -1 && PyErr_Occurred()) |
3676 | return NULL((void*)0); |
3677 | #if SIZEOF_LONG8 > 4 |
3678 | { |
3679 | unsigned long y; |
3680 | /* only want the trailing 32 bits */ |
3681 | y = x & 0xFFFFFFFFUL; |
3682 | if (y ^ x) |
3683 | return PyErr_Format(PyExc_OverflowError, |
3684 | "long int larger than 32 bits"); |
3685 | x = y; |
3686 | } |
3687 | #endif |
3688 | } |
3689 | else |
3690 | return PyErr_Format(PyExc_TypeError, |
3691 | "expected int/long, %s found", |
3692 | Py_TYPE(arg)(((PyObject*)(arg))->ob_type)->tp_name); |
3693 | if (x == (unsigned long) -1 && PyErr_Occurred()) |
3694 | return NULL((void*)0); |
3695 | return PyLong_FromUnsignedLong(ntohl(x)(__builtin_constant_p(x) ? ((__uint32_t)((((__uint32_t)(x) & 0xff000000) >> 24) | (((__uint32_t)(x) & 0x00ff0000 ) >> 8) | (((__uint32_t)(x) & 0x0000ff00) << 8 ) | (((__uint32_t)(x) & 0x000000ff) << 24))) : _OSSwapInt32 (x))); |
3696 | } |
3697 | |
3698 | PyDoc_STRVAR(ntohl_doc,static char ntohl_doc[] = "ntohl(integer) -> integer\n\nConvert a 32-bit integer from network to host byte order." |
3699 | "ntohl(integer) -> integer\n\static char ntohl_doc[] = "ntohl(integer) -> integer\n\nConvert a 32-bit integer from network to host byte order." |
3700 | \n\static char ntohl_doc[] = "ntohl(integer) -> integer\n\nConvert a 32-bit integer from network to host byte order." |
3701 | Convert a 32-bit integer from network to host byte order.")static char ntohl_doc[] = "ntohl(integer) -> integer\n\nConvert a 32-bit integer from network to host byte order."; |
3702 | |
3703 | |
3704 | static PyObject * |
3705 | socket_htons(PyObject *self, PyObject *args) |
3706 | { |
3707 | int x1, x2; |
3708 | |
3709 | if (!PyArg_ParseTuple(args, "i:htons", &x1)) { |
3710 | return NULL((void*)0); |
3711 | } |
3712 | if (x1 < 0) { |
3713 | PyErr_SetString(PyExc_OverflowError, |
3714 | "can't convert negative number to unsigned long"); |
3715 | return NULL((void*)0); |
3716 | } |
3717 | x2 = (unsigned int)htons((unsigned short)x1)(__builtin_constant_p((unsigned short)x1) ? ((__uint16_t)(((( __uint16_t)((unsigned short)x1) & 0xff00) >> 8) | ( ((__uint16_t)((unsigned short)x1) & 0x00ff) << 8))) : _OSSwapInt16((unsigned short)x1)); |
3718 | return PyLong_FromLong(x2); |
3719 | } |
3720 | |
3721 | PyDoc_STRVAR(htons_doc,static char htons_doc[] = "htons(integer) -> integer\n\nConvert a 16-bit integer from host to network byte order." |
3722 | "htons(integer) -> integer\n\static char htons_doc[] = "htons(integer) -> integer\n\nConvert a 16-bit integer from host to network byte order." |
3723 | \n\static char htons_doc[] = "htons(integer) -> integer\n\nConvert a 16-bit integer from host to network byte order." |
3724 | Convert a 16-bit integer from host to network byte order.")static char htons_doc[] = "htons(integer) -> integer\n\nConvert a 16-bit integer from host to network byte order."; |
3725 | |
3726 | |
3727 | static PyObject * |
3728 | socket_htonl(PyObject *self, PyObject *arg) |
3729 | { |
3730 | unsigned long x; |
3731 | |
3732 | if (PyLong_Check(arg)((((((PyObject*)(arg))->ob_type))->tp_flags & ((1L<< 24))) != 0)) { |
3733 | x = PyLong_AsUnsignedLong(arg); |
3734 | if (x == (unsigned long) -1 && PyErr_Occurred()) |
3735 | return NULL((void*)0); |
3736 | #if SIZEOF_LONG8 > 4 |
3737 | { |
3738 | unsigned long y; |
3739 | /* only want the trailing 32 bits */ |
3740 | y = x & 0xFFFFFFFFUL; |
3741 | if (y ^ x) |
3742 | return PyErr_Format(PyExc_OverflowError, |
3743 | "long int larger than 32 bits"); |
3744 | x = y; |
3745 | } |
3746 | #endif |
3747 | } |
3748 | else |
3749 | return PyErr_Format(PyExc_TypeError, |
3750 | "expected int/long, %s found", |
3751 | Py_TYPE(arg)(((PyObject*)(arg))->ob_type)->tp_name); |
3752 | return PyLong_FromUnsignedLong(htonl((unsigned long)x)(__builtin_constant_p((unsigned long)x) ? ((__uint32_t)((((__uint32_t )((unsigned long)x) & 0xff000000) >> 24) | (((__uint32_t )((unsigned long)x) & 0x00ff0000) >> 8) | (((__uint32_t )((unsigned long)x) & 0x0000ff00) << 8) | (((__uint32_t )((unsigned long)x) & 0x000000ff) << 24))) : _OSSwapInt32 ((unsigned long)x))); |
3753 | } |
3754 | |
3755 | PyDoc_STRVAR(htonl_doc,static char htonl_doc[] = "htonl(integer) -> integer\n\nConvert a 32-bit integer from host to network byte order." |
3756 | "htonl(integer) -> integer\n\static char htonl_doc[] = "htonl(integer) -> integer\n\nConvert a 32-bit integer from host to network byte order." |
3757 | \n\static char htonl_doc[] = "htonl(integer) -> integer\n\nConvert a 32-bit integer from host to network byte order." |
3758 | Convert a 32-bit integer from host to network byte order.")static char htonl_doc[] = "htonl(integer) -> integer\n\nConvert a 32-bit integer from host to network byte order."; |
3759 | |
3760 | /* socket.inet_aton() and socket.inet_ntoa() functions. */ |
3761 | |
3762 | PyDoc_STRVAR(inet_aton_doc,static char inet_aton_doc[] = "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\nConvert an IP address in string format (123.45.67.89) to the 32-bit packed\nbinary format used in low-level network functions." |
3763 | "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\static char inet_aton_doc[] = "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\nConvert an IP address in string format (123.45.67.89) to the 32-bit packed\nbinary format used in low-level network functions." |
3764 | \n\static char inet_aton_doc[] = "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\nConvert an IP address in string format (123.45.67.89) to the 32-bit packed\nbinary format used in low-level network functions." |
3765 | Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\static char inet_aton_doc[] = "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\nConvert an IP address in string format (123.45.67.89) to the 32-bit packed\nbinary format used in low-level network functions." |
3766 | binary format used in low-level network functions.")static char inet_aton_doc[] = "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\nConvert an IP address in string format (123.45.67.89) to the 32-bit packed\nbinary format used in low-level network functions."; |
3767 | |
3768 | static PyObject* |
3769 | socket_inet_aton(PyObject *self, PyObject *args) |
3770 | { |
3771 | #ifndef INADDR_NONE0xffffffff |
3772 | #define INADDR_NONE0xffffffff (-1) |
3773 | #endif |
3774 | #ifdef HAVE_INET_ATON1 |
3775 | struct in_addr buf; |
3776 | #endif |
3777 | |
3778 | #if !defined(HAVE_INET_ATON1) || defined(USE_INET_ATON_WEAKLINK) |
3779 | #if (SIZEOF_INT4 != 4) |
3780 | #error "Not sure if in_addr_t exists and int is not 32-bits." |
3781 | #endif |
3782 | /* Have to use inet_addr() instead */ |
3783 | unsigned int packed_addr; |
3784 | #endif |
3785 | char *ip_addr; |
3786 | |
3787 | if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) |
3788 | return NULL((void*)0); |
3789 | |
3790 | |
3791 | #ifdef HAVE_INET_ATON1 |
3792 | |
3793 | #ifdef USE_INET_ATON_WEAKLINK |
3794 | if (inet_aton != NULL((void*)0)) { |
3795 | #endif |
3796 | if (inet_aton(ip_addr, &buf)) |
3797 | return PyBytes_FromStringAndSize((char *)(&buf), |
3798 | sizeof(buf)); |
3799 | |
3800 | PyErr_SetString(socket_error, |
3801 | "illegal IP address string passed to inet_aton"); |
3802 | return NULL((void*)0); |
3803 | |
3804 | #ifdef USE_INET_ATON_WEAKLINK |
3805 | } else { |
3806 | #endif |
3807 | |
3808 | #endif |
3809 | |
3810 | #if !defined(HAVE_INET_ATON1) || defined(USE_INET_ATON_WEAKLINK) |
3811 | |
3812 | /* special-case this address as inet_addr might return INADDR_NONE |
3813 | * for this */ |
3814 | if (strcmp(ip_addr, "255.255.255.255") == 0) { |
3815 | packed_addr = 0xFFFFFFFF; |
3816 | } else { |
3817 | |
3818 | packed_addr = inet_addr(ip_addr); |
3819 | |
3820 | if (packed_addr == INADDR_NONE0xffffffff) { /* invalid address */ |
3821 | PyErr_SetString(socket_error, |
3822 | "illegal IP address string passed to inet_aton"); |
3823 | return NULL((void*)0); |
3824 | } |
3825 | } |
3826 | return PyBytes_FromStringAndSize((char *) &packed_addr, |
3827 | sizeof(packed_addr)); |
3828 | |
3829 | #ifdef USE_INET_ATON_WEAKLINK |
3830 | } |
3831 | #endif |
3832 | |
3833 | #endif |
3834 | } |
3835 | |
3836 | PyDoc_STRVAR(inet_ntoa_doc,static char inet_ntoa_doc[] = "inet_ntoa(packed_ip) -> ip_address_string\n\nConvert an IP address from 32-bit packed binary format to string format" |
3837 | "inet_ntoa(packed_ip) -> ip_address_string\n\static char inet_ntoa_doc[] = "inet_ntoa(packed_ip) -> ip_address_string\n\nConvert an IP address from 32-bit packed binary format to string format" |
3838 | \n\static char inet_ntoa_doc[] = "inet_ntoa(packed_ip) -> ip_address_string\n\nConvert an IP address from 32-bit packed binary format to string format" |
3839 | Convert an IP address from 32-bit packed binary format to string format")static char inet_ntoa_doc[] = "inet_ntoa(packed_ip) -> ip_address_string\n\nConvert an IP address from 32-bit packed binary format to string format"; |
3840 | |
3841 | static PyObject* |
3842 | socket_inet_ntoa(PyObject *self, PyObject *args) |
3843 | { |
3844 | char *packed_str; |
3845 | int addr_len; |
3846 | struct in_addr packed_addr; |
3847 | |
3848 | if (!PyArg_ParseTuple(args, "y#:inet_ntoa", &packed_str, &addr_len)) { |
3849 | return NULL((void*)0); |
3850 | } |
3851 | |
3852 | if (addr_len != sizeof(packed_addr)) { |
3853 | PyErr_SetString(socket_error, |
3854 | "packed IP wrong length for inet_ntoa"); |
3855 | return NULL((void*)0); |
3856 | } |
3857 | |
3858 | memcpy(&packed_addr, packed_str, addr_len)((__builtin_object_size (&packed_addr, 0) != (size_t) -1) ? __builtin___memcpy_chk (&packed_addr, packed_str, addr_len , __builtin_object_size (&packed_addr, 0)) : __inline_memcpy_chk (&packed_addr, packed_str, addr_len)); |
3859 | |
3860 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(inet_ntoa(packed_addr)); |
3861 | } |
3862 | |
3863 | #ifdef HAVE_INET_PTON1 |
3864 | |
3865 | PyDoc_STRVAR(inet_pton_doc,static char inet_pton_doc[] = "inet_pton(af, ip) -> packed IP address string\n\nConvert an IP address from string format to a packed string suitable\nfor use with low-level network functions." |
3866 | "inet_pton(af, ip) -> packed IP address string\n\static char inet_pton_doc[] = "inet_pton(af, ip) -> packed IP address string\n\nConvert an IP address from string format to a packed string suitable\nfor use with low-level network functions." |
3867 | \n\static char inet_pton_doc[] = "inet_pton(af, ip) -> packed IP address string\n\nConvert an IP address from string format to a packed string suitable\nfor use with low-level network functions." |
3868 | Convert an IP address from string format to a packed string suitable\n\static char inet_pton_doc[] = "inet_pton(af, ip) -> packed IP address string\n\nConvert an IP address from string format to a packed string suitable\nfor use with low-level network functions." |
3869 | for use with low-level network functions.")static char inet_pton_doc[] = "inet_pton(af, ip) -> packed IP address string\n\nConvert an IP address from string format to a packed string suitable\nfor use with low-level network functions."; |
3870 | |
3871 | static PyObject * |
3872 | socket_inet_pton(PyObject *self, PyObject *args) |
3873 | { |
3874 | int af; |
3875 | char* ip; |
3876 | int retval; |
3877 | #ifdef ENABLE_IPV61 |
3878 | char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))((sizeof(struct in_addr)) < (sizeof(struct in6_addr)) ? (sizeof (struct in6_addr)) : (sizeof(struct in_addr)))]; |
3879 | #else |
3880 | char packed[sizeof(struct in_addr)]; |
3881 | #endif |
3882 | if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) { |
3883 | return NULL((void*)0); |
3884 | } |
3885 | |
3886 | #if !defined(ENABLE_IPV61) && defined(AF_INET630) |
3887 | if(af == AF_INET630) { |
3888 | PyErr_SetString(socket_error, |
3889 | "can't use AF_INET6, IPv6 is disabled"); |
3890 | return NULL((void*)0); |
3891 | } |
3892 | #endif |
3893 | |
3894 | retval = inet_pton(af, ip, packed); |
3895 | if (retval < 0) { |
3896 | PyErr_SetFromErrno(socket_error); |
3897 | return NULL((void*)0); |
3898 | } else if (retval == 0) { |
3899 | PyErr_SetString(socket_error, |
3900 | "illegal IP address string passed to inet_pton"); |
3901 | return NULL((void*)0); |
3902 | } else if (af == AF_INET2) { |
3903 | return PyBytes_FromStringAndSize(packed, |
3904 | sizeof(struct in_addr)); |
3905 | #ifdef ENABLE_IPV61 |
3906 | } else if (af == AF_INET630) { |
3907 | return PyBytes_FromStringAndSize(packed, |
3908 | sizeof(struct in6_addr)); |
3909 | #endif |
3910 | } else { |
3911 | PyErr_SetString(socket_error, "unknown address family"); |
3912 | return NULL((void*)0); |
3913 | } |
3914 | } |
3915 | |
3916 | PyDoc_STRVAR(inet_ntop_doc,static char inet_ntop_doc[] = "inet_ntop(af, packed_ip) -> string formatted IP address\n\nConvert a packed IP address of the given family to string format." |
3917 | "inet_ntop(af, packed_ip) -> string formatted IP address\n\static char inet_ntop_doc[] = "inet_ntop(af, packed_ip) -> string formatted IP address\n\nConvert a packed IP address of the given family to string format." |
3918 | \n\static char inet_ntop_doc[] = "inet_ntop(af, packed_ip) -> string formatted IP address\n\nConvert a packed IP address of the given family to string format." |
3919 | Convert a packed IP address of the given family to string format.")static char inet_ntop_doc[] = "inet_ntop(af, packed_ip) -> string formatted IP address\n\nConvert a packed IP address of the given family to string format."; |
3920 | |
3921 | static PyObject * |
3922 | socket_inet_ntop(PyObject *self, PyObject *args) |
3923 | { |
3924 | int af; |
3925 | char* packed; |
3926 | int len; |
3927 | const char* retval; |
3928 | #ifdef ENABLE_IPV61 |
3929 | char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)((16) < (46) ? (46) : (16)) + 1]; |
3930 | #else |
3931 | char ip[INET_ADDRSTRLEN16 + 1]; |
3932 | #endif |
3933 | |
3934 | /* Guarantee NUL-termination for PyUnicode_FromString() below */ |
3935 | memset((void *) &ip[0], '\0', sizeof(ip))((__builtin_object_size ((void *) &ip[0], 0) != (size_t) - 1) ? __builtin___memset_chk ((void *) &ip[0], '\0', sizeof (ip), __builtin_object_size ((void *) &ip[0], 0)) : __inline_memset_chk ((void *) &ip[0], '\0', sizeof(ip))); |
3936 | |
3937 | if (!PyArg_ParseTuple(args, "iy#:inet_ntop", &af, &packed, &len)) { |
3938 | return NULL((void*)0); |
3939 | } |
3940 | |
3941 | if (af == AF_INET2) { |
3942 | if (len != sizeof(struct in_addr)) { |
3943 | PyErr_SetString(PyExc_ValueError, |
3944 | "invalid length of packed IP address string"); |
3945 | return NULL((void*)0); |
3946 | } |
3947 | #ifdef ENABLE_IPV61 |
3948 | } else if (af == AF_INET630) { |
3949 | if (len != sizeof(struct in6_addr)) { |
3950 | PyErr_SetString(PyExc_ValueError, |
3951 | "invalid length of packed IP address string"); |
3952 | return NULL((void*)0); |
3953 | } |
3954 | #endif |
3955 | } else { |
3956 | PyErr_Format(PyExc_ValueError, |
3957 | "unknown address family %d", af); |
3958 | return NULL((void*)0); |
3959 | } |
3960 | |
3961 | retval = inet_ntop(af, packed, ip, sizeof(ip)); |
3962 | if (!retval) { |
3963 | PyErr_SetFromErrno(socket_error); |
3964 | return NULL((void*)0); |
3965 | } else { |
3966 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(retval); |
3967 | } |
3968 | |
3969 | /* NOTREACHED */ |
3970 | PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop"); |
3971 | return NULL((void*)0); |
3972 | } |
3973 | |
3974 | #endif /* HAVE_INET_PTON */ |
3975 | |
3976 | /* Python interface to getaddrinfo(host, port). */ |
3977 | |
3978 | /*ARGSUSED*/ |
3979 | static PyObject * |
3980 | socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs) |
3981 | { |
3982 | static char* kwnames[] = {"host", "port", "family", "type", "proto", |
3983 | "flags", 0}; |
3984 | struct addrinfo hints, *res; |
3985 | struct addrinfo *res0 = NULL((void*)0); |
3986 | PyObject *hobj = NULL((void*)0); |
3987 | PyObject *pobj = (PyObject *)NULL((void*)0); |
3988 | char pbuf[30]; |
3989 | char *hptr, *pptr; |
3990 | int family, socktype, protocol, flags; |
3991 | int error; |
3992 | PyObject *all = (PyObject *)NULL((void*)0); |
3993 | PyObject *idna = NULL((void*)0); |
3994 | |
3995 | family = socktype = protocol = flags = 0; |
3996 | family = AF_UNSPEC0; |
3997 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iiii:getaddrinfo", |
3998 | kwnames, &hobj, &pobj, &family, &socktype, |
3999 | &protocol, &flags)) { |
4000 | return NULL((void*)0); |
4001 | } |
4002 | if (hobj == Py_None(&_Py_NoneStruct)) { |
4003 | hptr = NULL((void*)0); |
4004 | } else if (PyUnicode_Check(hobj)((((((PyObject*)(hobj))->ob_type))->tp_flags & ((1L <<28))) != 0)) { |
4005 | idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); |
4006 | if (!idna) |
4007 | return NULL((void*)0); |
4008 | assert(PyBytes_Check(idna))(__builtin_expect(!(((((((PyObject*)(idna))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 4008 , "PyBytes_Check(idna)") : (void)0); |
4009 | hptr = PyBytes_AS_STRING(idna)((__builtin_expect(!(((((((PyObject*)(idna))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 4009 , "PyBytes_Check(idna)") : (void)0), (((PyBytesObject *)(idna ))->ob_sval)); |
4010 | } else if (PyBytes_Check(hobj)((((((PyObject*)(hobj))->ob_type))->tp_flags & ((1L <<27))) != 0)) { |
4011 | hptr = PyBytes_AsString(hobj); |
4012 | } else { |
4013 | PyErr_SetString(PyExc_TypeError, |
4014 | "getaddrinfo() argument 1 must be string or None"); |
4015 | return NULL((void*)0); |
4016 | } |
4017 | if (PyLong_CheckExact(pobj)((((PyObject*)(pobj))->ob_type) == &PyLong_Type)) { |
4018 | long value = PyLong_AsLong(pobj); |
4019 | if (value == -1 && PyErr_Occurred()) |
4020 | goto err; |
4021 | PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value); |
4022 | pptr = pbuf; |
4023 | } else if (PyUnicode_Check(pobj)((((((PyObject*)(pobj))->ob_type))->tp_flags & ((1L <<28))) != 0)) { |
4024 | pptr = _PyUnicode_AsString(pobj); |
4025 | if (pptr == NULL((void*)0)) |
4026 | goto err; |
4027 | } else if (PyBytes_Check(pobj)((((((PyObject*)(pobj))->ob_type))->tp_flags & ((1L <<27))) != 0)) { |
4028 | pptr = PyBytes_AS_STRING(pobj)((__builtin_expect(!(((((((PyObject*)(pobj))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 4028 , "PyBytes_Check(pobj)") : (void)0), (((PyBytesObject *)(pobj ))->ob_sval)); |
4029 | } else if (pobj == Py_None(&_Py_NoneStruct)) { |
4030 | pptr = (char *)NULL((void*)0); |
4031 | } else { |
4032 | PyErr_SetString(socket_error, "Int or String expected"); |
4033 | goto err; |
4034 | } |
4035 | memset(&hints, 0, sizeof(hints))((__builtin_object_size (&hints, 0) != (size_t) -1) ? __builtin___memset_chk (&hints, 0, sizeof(hints), __builtin_object_size (&hints , 0)) : __inline_memset_chk (&hints, 0, sizeof(hints))); |
4036 | hints.ai_family = family; |
4037 | hints.ai_socktype = socktype; |
4038 | hints.ai_protocol = protocol; |
4039 | hints.ai_flags = flags; |
4040 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
4041 | ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); |
4042 | error = getaddrinfo(hptr, pptr, &hints, &res0); |
4043 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
4044 | RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); /* see comment in setipaddr() */ |
4045 | if (error) { |
4046 | set_gaierror(error); |
4047 | goto err; |
4048 | } |
4049 | |
4050 | if ((all = PyList_New(0)) == NULL((void*)0)) |
4051 | goto err; |
4052 | for (res = res0; res; res = res->ai_next) { |
4053 | PyObject *single; |
4054 | PyObject *addr = |
4055 | makesockaddr(-1, res->ai_addr, res->ai_addrlen, protocol); |
4056 | if (addr == NULL((void*)0)) |
4057 | goto err; |
4058 | single = Py_BuildValue("iiisO", res->ai_family, |
4059 | res->ai_socktype, res->ai_protocol, |
4060 | res->ai_canonname ? res->ai_canonname : "", |
4061 | addr); |
4062 | Py_DECREF(addr)do { if (_Py_RefTotal-- , --((PyObject*)(addr))->ob_refcnt != 0) { if (((PyObject*)addr)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c", 4062 , (PyObject *)(addr)); } else _Py_Dealloc((PyObject *)(addr)) ; } while (0); |
4063 | if (single == NULL((void*)0)) |
4064 | goto err; |
4065 | |
4066 | if (PyList_Append(all, single)) |
4067 | goto err; |
4068 | Py_XDECREF(single)do { if ((single) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(single))->ob_refcnt != 0) { if (((PyObject *)single)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 4068, (PyObject *)(single)); } else _Py_Dealloc((PyObject * )(single)); } while (0); } while (0); |
4069 | } |
4070 | Py_XDECREF(idna)do { if ((idna) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(idna))->ob_refcnt != 0) { if (((PyObject *)idna)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 4070, (PyObject *)(idna)); } else _Py_Dealloc((PyObject *)( idna)); } while (0); } while (0); |
4071 | if (res0) |
4072 | freeaddrinfo(res0); |
4073 | return all; |
4074 | err: |
4075 | Py_XDECREF(all)do { if ((all) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(all))->ob_refcnt != 0) { if (((PyObject*)all )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 4075, (PyObject *)(all)); } else _Py_Dealloc((PyObject *)(all )); } while (0); } while (0); |
4076 | Py_XDECREF(idna)do { if ((idna) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(idna))->ob_refcnt != 0) { if (((PyObject *)idna)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/socketmodule.c" , 4076, (PyObject *)(idna)); } else _Py_Dealloc((PyObject *)( idna)); } while (0); } while (0); |
4077 | if (res0) |
4078 | freeaddrinfo(res0); |
4079 | return (PyObject *)NULL((void*)0); |
4080 | } |
4081 | |
4082 | PyDoc_STRVAR(getaddrinfo_doc,static char getaddrinfo_doc[] = "getaddrinfo(host, port [, family, socktype, proto, flags])\n -> list of (family, socktype, proto, canonname, sockaddr)\n\nResolve host and port into addrinfo struct." |
4083 | "getaddrinfo(host, port [, family, socktype, proto, flags])\n\static char getaddrinfo_doc[] = "getaddrinfo(host, port [, family, socktype, proto, flags])\n -> list of (family, socktype, proto, canonname, sockaddr)\n\nResolve host and port into addrinfo struct." |
4084 | -> list of (family, socktype, proto, canonname, sockaddr)\n\static char getaddrinfo_doc[] = "getaddrinfo(host, port [, family, socktype, proto, flags])\n -> list of (family, socktype, proto, canonname, sockaddr)\n\nResolve host and port into addrinfo struct." |
4085 | \n\static char getaddrinfo_doc[] = "getaddrinfo(host, port [, family, socktype, proto, flags])\n -> list of (family, socktype, proto, canonname, sockaddr)\n\nResolve host and port into addrinfo struct." |
4086 | Resolve host and port into addrinfo struct.")static char getaddrinfo_doc[] = "getaddrinfo(host, port [, family, socktype, proto, flags])\n -> list of (family, socktype, proto, canonname, sockaddr)\n\nResolve host and port into addrinfo struct."; |
4087 | |
4088 | /* Python interface to getnameinfo(sa, flags). */ |
4089 | |
4090 | /*ARGSUSED*/ |
4091 | static PyObject * |
4092 | socket_getnameinfo(PyObject *self, PyObject *args) |
4093 | { |
4094 | PyObject *sa = (PyObject *)NULL((void*)0); |
4095 | int flags; |
4096 | char *hostp; |
4097 | int port, flowinfo, scope_id; |
4098 | char hbuf[NI_MAXHOST1025], pbuf[NI_MAXSERV32]; |
4099 | struct addrinfo hints, *res = NULL((void*)0); |
4100 | int error; |
4101 | PyObject *ret = (PyObject *)NULL((void*)0); |
4102 | |
4103 | flags = flowinfo = scope_id = 0; |
4104 | if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags)) |
4105 | return NULL((void*)0); |
4106 | if (!PyTuple_Check(sa)((((((PyObject*)(sa))->ob_type))->tp_flags & ((1L<< 26))) != 0)) { |
4107 | PyErr_SetString(PyExc_TypeError, |
4108 | "getnameinfo() argument 1 must be a tuple"); |
4109 | return NULL((void*)0); |
4110 | } |
4111 | if (!PyArg_ParseTuple(sa, "si|ii", |
4112 | &hostp, &port, &flowinfo, &scope_id)) |
4113 | return NULL((void*)0); |
4114 | PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port); |
4115 | memset(&hints, 0, sizeof(hints))((__builtin_object_size (&hints, 0) != (size_t) -1) ? __builtin___memset_chk (&hints, 0, sizeof(hints), __builtin_object_size (&hints , 0)) : __inline_memset_chk (&hints, 0, sizeof(hints))); |
4116 | hints.ai_family = AF_UNSPEC0; |
4117 | hints.ai_socktype = SOCK_DGRAM2; /* make numeric port happy */ |
4118 | hints.ai_flags = AI_NUMERICHOST0x00000004; /* don't do any name resolution */ |
4119 | Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread(); |
4120 | ACQUIRE_GETADDRINFO_LOCKPyThread_acquire_lock(netdb_lock, 1); |
4121 | error = getaddrinfo(hostp, pbuf, &hints, &res); |
4122 | Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); } |
4123 | RELEASE_GETADDRINFO_LOCKPyThread_release_lock(netdb_lock); /* see comment in setipaddr() */ |
4124 | if (error) { |
4125 | set_gaierror(error); |
4126 | goto fail; |
4127 | } |
4128 | if (res->ai_next) { |
4129 | PyErr_SetString(socket_error, |
4130 | "sockaddr resolved to multiple addresses"); |
4131 | goto fail; |
4132 | } |
4133 | switch (res->ai_family) { |
4134 | case AF_INET2: |
4135 | { |
4136 | if (PyTuple_GET_SIZE(sa)(((PyVarObject*)(sa))->ob_size) != 2) { |
4137 | PyErr_SetString(socket_error, |
4138 | "IPv4 sockaddr must be 2 tuple"); |
4139 | goto fail; |
4140 | } |
4141 | break; |
4142 | } |
4143 | #ifdef ENABLE_IPV61 |
4144 | case AF_INET630: |
4145 | { |
4146 | struct sockaddr_in6 *sin6; |
4147 | sin6 = (struct sockaddr_in6 *)res->ai_addr; |
4148 | sin6->sin6_flowinfo = flowinfo; |
4149 | sin6->sin6_scope_id = scope_id; |
4150 | break; |
4151 | } |
4152 | #endif |
4153 | } |
4154 | error = getnameinfo(res->ai_addr, (socklen_t) res->ai_addrlen, |
4155 | hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), flags); |
4156 | if (error) { |
4157 | set_gaierror(error); |
4158 | goto fail; |
4159 | } |
4160 | ret = Py_BuildValue("ss", hbuf, pbuf); |
4161 | |
4162 | fail: |
4163 | if (res) |
4164 | freeaddrinfo(res); |
4165 | return ret; |
4166 | } |
4167 | |
4168 | PyDoc_STRVAR(getnameinfo_doc,static char getnameinfo_doc[] = "getnameinfo(sockaddr, flags) --> (host, port)\n\nGet host and port for a sockaddr." |
4169 | "getnameinfo(sockaddr, flags) --> (host, port)\n\static char getnameinfo_doc[] = "getnameinfo(sockaddr, flags) --> (host, port)\n\nGet host and port for a sockaddr." |
4170 | \n\static char getnameinfo_doc[] = "getnameinfo(sockaddr, flags) --> (host, port)\n\nGet host and port for a sockaddr." |
4171 | Get host and port for a sockaddr.")static char getnameinfo_doc[] = "getnameinfo(sockaddr, flags) --> (host, port)\n\nGet host and port for a sockaddr."; |
4172 | |
4173 | |
4174 | /* Python API to getting and setting the default timeout value. */ |
4175 | |
4176 | static PyObject * |
4177 | socket_getdefaulttimeout(PyObject *self) |
4178 | { |
4179 | if (defaulttimeout < 0.0) { |
4180 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
4181 | return Py_None(&_Py_NoneStruct); |
4182 | } |
4183 | else |
4184 | return PyFloat_FromDouble(defaulttimeout); |
4185 | } |
4186 | |
4187 | PyDoc_STRVAR(getdefaulttimeout_doc,static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4188 | "getdefaulttimeout() -> timeout\n\static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4189 | \n\static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4190 | Returns the default timeout in floating seconds for new socket objects.\n\static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4191 | A value of None indicates that new socket objects have no timeout.\n\static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4192 | When the socket module is first imported, the default is None.")static char getdefaulttimeout_doc[] = "getdefaulttimeout() -> timeout\n\nReturns the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None."; |
4193 | |
4194 | static PyObject * |
4195 | socket_setdefaulttimeout(PyObject *self, PyObject *arg) |
4196 | { |
4197 | double timeout; |
4198 | |
4199 | if (arg == Py_None(&_Py_NoneStruct)) |
4200 | timeout = -1.0; |
4201 | else { |
4202 | timeout = PyFloat_AsDouble(arg); |
4203 | if (timeout < 0.0) { |
4204 | if (!PyErr_Occurred()) |
4205 | PyErr_SetString(PyExc_ValueError, |
4206 | "Timeout value out of range"); |
4207 | return NULL((void*)0); |
4208 | } |
4209 | } |
4210 | |
4211 | defaulttimeout = timeout; |
4212 | |
4213 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); |
4214 | return Py_None(&_Py_NoneStruct); |
4215 | } |
4216 | |
4217 | PyDoc_STRVAR(setdefaulttimeout_doc,static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4218 | "setdefaulttimeout(timeout)\n\static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4219 | \n\static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4220 | Set the default timeout in floating seconds for new socket objects.\n\static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4221 | A value of None indicates that new socket objects have no timeout.\n\static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None." |
4222 | When the socket module is first imported, the default is None.")static char setdefaulttimeout_doc[] = "setdefaulttimeout(timeout)\n\nSet the default timeout in floating seconds for new socket objects.\nA value of None indicates that new socket objects have no timeout.\nWhen the socket module is first imported, the default is None."; |
4223 | |
4224 | |
4225 | /* List of functions exported by this module. */ |
4226 | |
4227 | static PyMethodDef socket_methods[] = { |
4228 | {"gethostbyname", socket_gethostbyname, |
4229 | METH_VARARGS0x0001, gethostbyname_doc}, |
4230 | {"gethostbyname_ex", socket_gethostbyname_ex, |
4231 | METH_VARARGS0x0001, ghbn_ex_doc}, |
4232 | {"gethostbyaddr", socket_gethostbyaddr, |
4233 | METH_VARARGS0x0001, gethostbyaddr_doc}, |
4234 | {"gethostname", socket_gethostname, |
4235 | METH_NOARGS0x0004, gethostname_doc}, |
4236 | {"getservbyname", socket_getservbyname, |
4237 | METH_VARARGS0x0001, getservbyname_doc}, |
4238 | {"getservbyport", socket_getservbyport, |
4239 | METH_VARARGS0x0001, getservbyport_doc}, |
4240 | {"getprotobyname", socket_getprotobyname, |
4241 | METH_VARARGS0x0001, getprotobyname_doc}, |
4242 | #ifndef NO_DUP |
4243 | {"dup", socket_dup, |
4244 | METH_O0x0008, dup_doc}, |
4245 | #endif |
4246 | #ifdef HAVE_SOCKETPAIR1 |
4247 | {"socketpair", socket_socketpair, |
4248 | METH_VARARGS0x0001, socketpair_doc}, |
4249 | #endif |
4250 | {"ntohs", socket_ntohs, |
4251 | METH_VARARGS0x0001, ntohs_doc}, |
4252 | {"ntohl", socket_ntohl, |
4253 | METH_O0x0008, ntohl_doc}, |
4254 | {"htons", socket_htons, |
4255 | METH_VARARGS0x0001, htons_doc}, |
4256 | {"htonl", socket_htonl, |
4257 | METH_O0x0008, htonl_doc}, |
4258 | {"inet_aton", socket_inet_aton, |
4259 | METH_VARARGS0x0001, inet_aton_doc}, |
4260 | {"inet_ntoa", socket_inet_ntoa, |
4261 | METH_VARARGS0x0001, inet_ntoa_doc}, |
4262 | #ifdef HAVE_INET_PTON1 |
4263 | {"inet_pton", socket_inet_pton, |
4264 | METH_VARARGS0x0001, inet_pton_doc}, |
4265 | {"inet_ntop", socket_inet_ntop, |
4266 | METH_VARARGS0x0001, inet_ntop_doc}, |
4267 | #endif |
4268 | {"getaddrinfo", (PyCFunction)socket_getaddrinfo, |
4269 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, getaddrinfo_doc}, |
4270 | {"getnameinfo", socket_getnameinfo, |
4271 | METH_VARARGS0x0001, getnameinfo_doc}, |
4272 | {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout, |
4273 | METH_NOARGS0x0004, getdefaulttimeout_doc}, |
4274 | {"setdefaulttimeout", socket_setdefaulttimeout, |
4275 | METH_O0x0008, setdefaulttimeout_doc}, |
4276 | {NULL((void*)0), NULL((void*)0)} /* Sentinel */ |
4277 | }; |
4278 | |
4279 | |
4280 | #ifdef MS_WINDOWS |
4281 | #define OS_INIT_DEFINED |
4282 | |
4283 | /* Additional initialization and cleanup for Windows */ |
4284 | |
4285 | static void |
4286 | os_cleanup(void) |
4287 | { |
4288 | WSACleanup(); |
4289 | } |
4290 | |
4291 | static int |
4292 | os_init(void) |
4293 | { |
4294 | WSADATA WSAData; |
4295 | int ret; |
4296 | ret = WSAStartup(0x0101, &WSAData); |
4297 | switch (ret) { |
4298 | case 0: /* No error */ |
4299 | Py_AtExit(os_cleanup); |
4300 | return 1; /* Success */ |
4301 | case WSASYSNOTREADY: |
4302 | PyErr_SetString(PyExc_ImportError, |
4303 | "WSAStartup failed: network not ready"); |
4304 | break; |
4305 | case WSAVERNOTSUPPORTED: |
4306 | case WSAEINVAL: |
4307 | PyErr_SetString( |
4308 | PyExc_ImportError, |
4309 | "WSAStartup failed: requested version not supported"); |
4310 | break; |
4311 | default: |
4312 | PyErr_Format(PyExc_ImportError, "WSAStartup failed: error code %d", ret); |
4313 | break; |
4314 | } |
4315 | return 0; /* Failure */ |
4316 | } |
4317 | |
4318 | #endif /* MS_WINDOWS */ |
4319 | |
4320 | |
4321 | #ifdef PYOS_OS2 |
4322 | #define OS_INIT_DEFINED |
4323 | |
4324 | /* Additional initialization for OS/2 */ |
4325 | |
4326 | static int |
4327 | os_init(void) |
4328 | { |
4329 | #ifndef PYCC_GCC |
4330 | int rc = sock_init(); |
4331 | |
4332 | if (rc == 0) { |
4333 | return 1; /* Success */ |
4334 | } |
4335 | |
4336 | PyErr_Format(PyExc_ImportError, "OS/2 TCP/IP Error# %d", sock_errno()); |
4337 | |
4338 | return 0; /* Failure */ |
4339 | #else |
4340 | /* No need to initialise sockets with GCC/EMX */ |
4341 | return 1; /* Success */ |
4342 | #endif |
4343 | } |
4344 | |
4345 | #endif /* PYOS_OS2 */ |
4346 | |
4347 | |
4348 | #ifndef OS_INIT_DEFINED |
4349 | static int |
4350 | os_init(void) |
4351 | { |
4352 | return 1; /* Success */ |
4353 | } |
4354 | #endif |
4355 | |
4356 | |
4357 | /* C API table - always add new things to the end for binary |
4358 | compatibility. */ |
4359 | static |
4360 | PySocketModule_APIObject PySocketModuleAPI = |
4361 | { |
4362 | &sock_type, |
4363 | NULL((void*)0), |
4364 | NULL((void*)0) |
4365 | }; |
4366 | |
4367 | |
4368 | /* Initialize the _socket module. |
4369 | |
4370 | This module is actually called "_socket", and there's a wrapper |
4371 | "socket.py" which implements some additional functionality. |
4372 | The import of "_socket" may fail with an ImportError exception if |
4373 | os-specific initialization fails. On Windows, this does WINSOCK |
4374 | initialization. When WINSOCK is initialized succesfully, a call to |
4375 | WSACleanup() is scheduled to be made at exit time. |
4376 | */ |
4377 | |
4378 | PyDoc_STRVAR(socket_doc,static char socket_doc[] = "Implementation module for socket operations.\n\nSee the socket module for documentation." |
4379 | "Implementation module for socket operations.\n\static char socket_doc[] = "Implementation module for socket operations.\n\nSee the socket module for documentation." |
4380 | \n\static char socket_doc[] = "Implementation module for socket operations.\n\nSee the socket module for documentation." |
4381 | See the socket module for documentation.")static char socket_doc[] = "Implementation module for socket operations.\n\nSee the socket module for documentation."; |
4382 | |
4383 | static struct PyModuleDef socketmodule = { |
4384 | PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void*)0) }, ((void*)0), 0, ((void*)0), }, |
4385 | PySocket_MODULE_NAME"_socket", |
4386 | socket_doc, |
4387 | -1, |
4388 | socket_methods, |
4389 | NULL((void*)0), |
4390 | NULL((void*)0), |
4391 | NULL((void*)0), |
4392 | NULL((void*)0) |
4393 | }; |
4394 | |
4395 | PyMODINIT_FUNCPyObject* |
4396 | PyInit__socket(void) |
4397 | { |
4398 | PyObject *m, *has_ipv6; |
4399 | |
4400 | if (!os_init()) |
4401 | return NULL((void*)0); |
4402 | |
4403 | Py_TYPE(&sock_type)(((PyObject*)(&sock_type))->ob_type) = &PyType_Type; |
4404 | m = PyModule_Create(&socketmodule)PyModule_Create2TraceRefs(&socketmodule, 1013); |
4405 | if (m == NULL((void*)0)) |
4406 | return NULL((void*)0); |
4407 | |
4408 | socket_error = PyErr_NewException("socket.error", |
4409 | PyExc_IOError, NULL((void*)0)); |
4410 | if (socket_error == NULL((void*)0)) |
4411 | return NULL((void*)0); |
4412 | PySocketModuleAPI.error = socket_error; |
4413 | Py_INCREF(socket_error)( _Py_RefTotal++ , ((PyObject*)(socket_error))->ob_refcnt++ ); |
4414 | PyModule_AddObject(m, "error", socket_error); |
4415 | socket_herror = PyErr_NewException("socket.herror", |
4416 | socket_error, NULL((void*)0)); |
4417 | if (socket_herror == NULL((void*)0)) |
4418 | return NULL((void*)0); |
4419 | Py_INCREF(socket_herror)( _Py_RefTotal++ , ((PyObject*)(socket_herror))->ob_refcnt ++); |
4420 | PyModule_AddObject(m, "herror", socket_herror); |
4421 | socket_gaierror = PyErr_NewException("socket.gaierror", socket_error, |
4422 | NULL((void*)0)); |
4423 | if (socket_gaierror == NULL((void*)0)) |
4424 | return NULL((void*)0); |
4425 | Py_INCREF(socket_gaierror)( _Py_RefTotal++ , ((PyObject*)(socket_gaierror))->ob_refcnt ++); |
4426 | PyModule_AddObject(m, "gaierror", socket_gaierror); |
4427 | socket_timeout = PyErr_NewException("socket.timeout", |
4428 | socket_error, NULL((void*)0)); |
4429 | if (socket_timeout == NULL((void*)0)) |
4430 | return NULL((void*)0); |
4431 | PySocketModuleAPI.timeout_error = socket_timeout; |
4432 | Py_INCREF(socket_timeout)( _Py_RefTotal++ , ((PyObject*)(socket_timeout))->ob_refcnt ++); |
4433 | PyModule_AddObject(m, "timeout", socket_timeout); |
4434 | Py_INCREF((PyObject *)&sock_type)( _Py_RefTotal++ , ((PyObject*)((PyObject *)&sock_type))-> ob_refcnt++); |
4435 | if (PyModule_AddObject(m, "SocketType", |
4436 | (PyObject *)&sock_type) != 0) |
4437 | return NULL((void*)0); |
4438 | Py_INCREF((PyObject *)&sock_type)( _Py_RefTotal++ , ((PyObject*)((PyObject *)&sock_type))-> ob_refcnt++); |
4439 | if (PyModule_AddObject(m, "socket", |
4440 | (PyObject *)&sock_type) != 0) |
4441 | return NULL((void*)0); |
4442 | |
4443 | #ifdef ENABLE_IPV61 |
4444 | has_ipv6 = Py_True((PyObject *) &_Py_TrueStruct); |
4445 | #else |
4446 | has_ipv6 = Py_False((PyObject *) &_Py_FalseStruct); |
4447 | #endif |
4448 | Py_INCREF(has_ipv6)( _Py_RefTotal++ , ((PyObject*)(has_ipv6))->ob_refcnt++); |
4449 | PyModule_AddObject(m, "has_ipv6", has_ipv6); |
4450 | |
4451 | /* Export C API */ |
4452 | if (PyModule_AddObject(m, PySocket_CAPI_NAME"CAPI", |
4453 | PyCapsule_New(&PySocketModuleAPI, PySocket_CAPSULE_NAME"_socket" "." "CAPI", NULL((void*)0)) |
4454 | ) != 0) |
4455 | return NULL((void*)0); |
4456 | |
4457 | /* Address families (we only support AF_INET and AF_UNIX) */ |
4458 | #ifdef AF_UNSPEC0 |
4459 | PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC0); |
4460 | #endif |
4461 | PyModule_AddIntConstant(m, "AF_INET", AF_INET2); |
4462 | #ifdef AF_INET630 |
4463 | PyModule_AddIntConstant(m, "AF_INET6", AF_INET630); |
4464 | #endif /* AF_INET6 */ |
4465 | #if defined(AF_UNIX1) |
4466 | PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX1); |
4467 | #endif /* AF_UNIX */ |
4468 | #ifdef AF_AX25 |
4469 | /* Amateur Radio AX.25 */ |
4470 | PyModule_AddIntConstant(m, "AF_AX25", AF_AX25); |
4471 | #endif |
4472 | #ifdef AF_IPX23 |
4473 | PyModule_AddIntConstant(m, "AF_IPX", AF_IPX23); /* Novell IPX */ |
4474 | #endif |
4475 | #ifdef AF_APPLETALK16 |
4476 | /* Appletalk DDP */ |
4477 | PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK16); |
4478 | #endif |
4479 | #ifdef AF_NETROM |
4480 | /* Amateur radio NetROM */ |
4481 | PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM); |
4482 | #endif |
4483 | #ifdef AF_BRIDGE |
4484 | /* Multiprotocol bridge */ |
4485 | PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE); |
4486 | #endif |
4487 | #ifdef AF_ATMPVC |
4488 | /* ATM PVCs */ |
4489 | PyModule_AddIntConstant(m, "AF_ATMPVC", AF_ATMPVC); |
4490 | #endif |
4491 | #ifdef AF_AAL5 |
4492 | /* Reserved for Werner's ATM */ |
4493 | PyModule_AddIntConstant(m, "AF_AAL5", AF_AAL5); |
4494 | #endif |
4495 | #ifdef AF_X25 |
4496 | /* Reserved for X.25 project */ |
4497 | PyModule_AddIntConstant(m, "AF_X25", AF_X25); |
4498 | #endif |
4499 | #ifdef AF_INET630 |
4500 | PyModule_AddIntConstant(m, "AF_INET6", AF_INET630); /* IP version 6 */ |
4501 | #endif |
4502 | #ifdef AF_ROSE |
4503 | /* Amateur Radio X.25 PLP */ |
4504 | PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); |
4505 | #endif |
4506 | #ifdef AF_DECnet12 |
4507 | /* Reserved for DECnet project */ |
4508 | PyModule_AddIntConstant(m, "AF_DECnet", AF_DECnet12); |
4509 | #endif |
4510 | #ifdef AF_NETBEUI |
4511 | /* Reserved for 802.2LLC project */ |
4512 | PyModule_AddIntConstant(m, "AF_NETBEUI", AF_NETBEUI); |
4513 | #endif |
4514 | #ifdef AF_SECURITY |
4515 | /* Security callback pseudo AF */ |
4516 | PyModule_AddIntConstant(m, "AF_SECURITY", AF_SECURITY); |
4517 | #endif |
4518 | #ifdef AF_KEY |
4519 | /* PF_KEY key management API */ |
4520 | PyModule_AddIntConstant(m, "AF_KEY", AF_KEY); |
4521 | #endif |
4522 | #ifdef AF_NETLINK |
4523 | /* */ |
4524 | PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); |
4525 | PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE); |
4526 | #ifdef NETLINK_SKIP |
4527 | PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP); |
4528 | #endif |
4529 | #ifdef NETLINK_W1 |
4530 | PyModule_AddIntConstant(m, "NETLINK_W1", NETLINK_W1); |
4531 | #endif |
4532 | PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK); |
4533 | PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL); |
4534 | #ifdef NETLINK_TCPDIAG |
4535 | PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG); |
4536 | #endif |
4537 | #ifdef NETLINK_NFLOG |
4538 | PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG); |
4539 | #endif |
4540 | #ifdef NETLINK_XFRM |
4541 | PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM); |
4542 | #endif |
4543 | #ifdef NETLINK_ARPD |
4544 | PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD); |
4545 | #endif |
4546 | #ifdef NETLINK_ROUTE6 |
4547 | PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6); |
4548 | #endif |
4549 | PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW); |
4550 | #ifdef NETLINK_DNRTMSG |
4551 | PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG); |
4552 | #endif |
4553 | #ifdef NETLINK_TAPBASE |
4554 | PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE); |
4555 | #endif |
4556 | #endif /* AF_NETLINK */ |
4557 | #ifdef AF_ROUTE17 |
4558 | /* Alias to emulate 4.4BSD */ |
4559 | PyModule_AddIntConstant(m, "AF_ROUTE", AF_ROUTE17); |
4560 | #endif |
4561 | #ifdef AF_ASH |
4562 | /* Ash */ |
4563 | PyModule_AddIntConstant(m, "AF_ASH", AF_ASH); |
4564 | #endif |
4565 | #ifdef AF_ECONET |
4566 | /* Acorn Econet */ |
4567 | PyModule_AddIntConstant(m, "AF_ECONET", AF_ECONET); |
4568 | #endif |
4569 | #ifdef AF_ATMSVC |
4570 | /* ATM SVCs */ |
4571 | PyModule_AddIntConstant(m, "AF_ATMSVC", AF_ATMSVC); |
4572 | #endif |
4573 | #ifdef AF_SNA11 |
4574 | /* Linux SNA Project (nutters!) */ |
4575 | PyModule_AddIntConstant(m, "AF_SNA", AF_SNA11); |
4576 | #endif |
4577 | #ifdef AF_IRDA |
4578 | /* IRDA sockets */ |
4579 | PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA); |
4580 | #endif |
4581 | #ifdef AF_PPPOX |
4582 | /* PPPoX sockets */ |
4583 | PyModule_AddIntConstant(m, "AF_PPPOX", AF_PPPOX); |
4584 | #endif |
4585 | #ifdef AF_WANPIPE |
4586 | /* Wanpipe API Sockets */ |
4587 | PyModule_AddIntConstant(m, "AF_WANPIPE", AF_WANPIPE); |
4588 | #endif |
4589 | #ifdef AF_LLC |
4590 | /* Linux LLC */ |
4591 | PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); |
4592 | #endif |
4593 | |
4594 | #ifdef USE_BLUETOOTH |
4595 | PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); |
4596 | PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); |
4597 | PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI); |
4598 | PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI); |
4599 | #if !defined(__NetBSD__) && !defined(__DragonFly__) |
4600 | PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER); |
4601 | #endif |
4602 | #if !defined(__FreeBSD__) |
4603 | #if !defined(__NetBSD__) && !defined(__DragonFly__) |
4604 | PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP); |
4605 | #endif |
4606 | PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR); |
4607 | PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); |
4608 | #endif |
4609 | PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); |
4610 | PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00"); |
4611 | PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); |
4612 | #endif |
4613 | |
4614 | #ifdef AF_PACKET |
4615 | PyModule_AddIntMacro(m, AF_PACKET)PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); |
4616 | #endif |
4617 | #ifdef PF_PACKET |
4618 | PyModule_AddIntMacro(m, PF_PACKET)PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); |
4619 | #endif |
4620 | #ifdef PACKET_HOST |
4621 | PyModule_AddIntMacro(m, PACKET_HOST)PyModule_AddIntConstant(m, "PACKET_HOST", PACKET_HOST); |
4622 | #endif |
4623 | #ifdef PACKET_BROADCAST |
4624 | PyModule_AddIntMacro(m, PACKET_BROADCAST)PyModule_AddIntConstant(m, "PACKET_BROADCAST", PACKET_BROADCAST ); |
4625 | #endif |
4626 | #ifdef PACKET_MULTICAST |
4627 | PyModule_AddIntMacro(m, PACKET_MULTICAST)PyModule_AddIntConstant(m, "PACKET_MULTICAST", PACKET_MULTICAST ); |
4628 | #endif |
4629 | #ifdef PACKET_OTHERHOST |
4630 | PyModule_AddIntMacro(m, PACKET_OTHERHOST)PyModule_AddIntConstant(m, "PACKET_OTHERHOST", PACKET_OTHERHOST ); |
4631 | #endif |
4632 | #ifdef PACKET_OUTGOING |
4633 | PyModule_AddIntMacro(m, PACKET_OUTGOING)PyModule_AddIntConstant(m, "PACKET_OUTGOING", PACKET_OUTGOING ); |
4634 | #endif |
4635 | #ifdef PACKET_LOOPBACK |
4636 | PyModule_AddIntMacro(m, PACKET_LOOPBACK)PyModule_AddIntConstant(m, "PACKET_LOOPBACK", PACKET_LOOPBACK ); |
4637 | #endif |
4638 | #ifdef PACKET_FASTROUTE |
4639 | PyModule_AddIntMacro(m, PACKET_FASTROUTE)PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE ); |
4640 | #endif |
4641 | |
4642 | #ifdef HAVE_LINUX_TIPC_H |
4643 | PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC); |
4644 | |
4645 | /* for addresses */ |
4646 | PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ); |
4647 | PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME); |
4648 | PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID); |
4649 | |
4650 | PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE); |
4651 | PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE); |
4652 | PyModule_AddIntConstant(m, "TIPC_NODE_SCOPE", TIPC_NODE_SCOPE); |
4653 | |
4654 | /* for setsockopt() */ |
4655 | PyModule_AddIntConstant(m, "SOL_TIPC", SOL_TIPC); |
4656 | PyModule_AddIntConstant(m, "TIPC_IMPORTANCE", TIPC_IMPORTANCE); |
4657 | PyModule_AddIntConstant(m, "TIPC_SRC_DROPPABLE", TIPC_SRC_DROPPABLE); |
4658 | PyModule_AddIntConstant(m, "TIPC_DEST_DROPPABLE", |
4659 | TIPC_DEST_DROPPABLE); |
4660 | PyModule_AddIntConstant(m, "TIPC_CONN_TIMEOUT", TIPC_CONN_TIMEOUT); |
4661 | |
4662 | PyModule_AddIntConstant(m, "TIPC_LOW_IMPORTANCE", |
4663 | TIPC_LOW_IMPORTANCE); |
4664 | PyModule_AddIntConstant(m, "TIPC_MEDIUM_IMPORTANCE", |
4665 | TIPC_MEDIUM_IMPORTANCE); |
4666 | PyModule_AddIntConstant(m, "TIPC_HIGH_IMPORTANCE", |
4667 | TIPC_HIGH_IMPORTANCE); |
4668 | PyModule_AddIntConstant(m, "TIPC_CRITICAL_IMPORTANCE", |
4669 | TIPC_CRITICAL_IMPORTANCE); |
4670 | |
4671 | /* for subscriptions */ |
4672 | PyModule_AddIntConstant(m, "TIPC_SUB_PORTS", TIPC_SUB_PORTS); |
4673 | PyModule_AddIntConstant(m, "TIPC_SUB_SERVICE", TIPC_SUB_SERVICE); |
4674 | #ifdef TIPC_SUB_CANCEL |
4675 | /* doesn't seem to be available everywhere */ |
4676 | PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL); |
4677 | #endif |
4678 | PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER); |
4679 | PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED); |
4680 | PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN); |
4681 | PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT); |
4682 | PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV); |
4683 | PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); |
4684 | #endif |
4685 | |
4686 | /* Socket types */ |
4687 | PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM1); |
4688 | PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM2); |
4689 | /* We have incomplete socket support. */ |
4690 | PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW3); |
4691 | PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET5); |
4692 | #if defined(SOCK_RDM4) |
4693 | PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM4); |
4694 | #endif |
4695 | #ifdef SOCK_CLOEXEC |
4696 | PyModule_AddIntConstant(m, "SOCK_CLOEXEC", SOCK_CLOEXEC); |
4697 | #endif |
4698 | #ifdef SOCK_NONBLOCK |
4699 | PyModule_AddIntConstant(m, "SOCK_NONBLOCK", SOCK_NONBLOCK); |
4700 | #endif |
4701 | |
4702 | #ifdef SO_DEBUG0x0001 |
4703 | PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG0x0001); |
4704 | #endif |
4705 | #ifdef SO_ACCEPTCONN0x0002 |
4706 | PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN0x0002); |
4707 | #endif |
4708 | #ifdef SO_REUSEADDR0x0004 |
4709 | PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR0x0004); |
4710 | #endif |
4711 | #ifdef SO_EXCLUSIVEADDRUSE |
4712 | PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE); |
4713 | #endif |
4714 | |
4715 | #ifdef SO_KEEPALIVE0x0008 |
4716 | PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE0x0008); |
4717 | #endif |
4718 | #ifdef SO_DONTROUTE0x0010 |
4719 | PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE0x0010); |
4720 | #endif |
4721 | #ifdef SO_BROADCAST0x0020 |
4722 | PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST0x0020); |
4723 | #endif |
4724 | #ifdef SO_USELOOPBACK0x0040 |
4725 | PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK0x0040); |
4726 | #endif |
4727 | #ifdef SO_LINGER0x0080 |
4728 | PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER0x0080); |
4729 | #endif |
4730 | #ifdef SO_OOBINLINE0x0100 |
4731 | PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE0x0100); |
4732 | #endif |
4733 | #ifdef SO_REUSEPORT0x0200 |
4734 | PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT0x0200); |
4735 | #endif |
4736 | #ifdef SO_SNDBUF0x1001 |
4737 | PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF0x1001); |
4738 | #endif |
4739 | #ifdef SO_RCVBUF0x1002 |
4740 | PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF0x1002); |
4741 | #endif |
4742 | #ifdef SO_SNDLOWAT0x1003 |
4743 | PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT0x1003); |
4744 | #endif |
4745 | #ifdef SO_RCVLOWAT0x1004 |
4746 | PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT0x1004); |
4747 | #endif |
4748 | #ifdef SO_SNDTIMEO0x1005 |
4749 | PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO0x1005); |
4750 | #endif |
4751 | #ifdef SO_RCVTIMEO0x1006 |
4752 | PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO0x1006); |
4753 | #endif |
4754 | #ifdef SO_ERROR0x1007 |
4755 | PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR0x1007); |
4756 | #endif |
4757 | #ifdef SO_TYPE0x1008 |
4758 | PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE0x1008); |
4759 | #endif |
4760 | #ifdef SO_SETFIB |
4761 | PyModule_AddIntConstant(m, "SO_SETFIB", SO_SETFIB); |
4762 | #endif |
4763 | |
4764 | /* Maximum number of connections for "listen" */ |
4765 | #ifdef SOMAXCONN128 |
4766 | PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN128); |
4767 | #else |
4768 | PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ |
4769 | #endif |
4770 | |
4771 | /* Flags for send, recv */ |
4772 | #ifdef MSG_OOB0x1 |
4773 | PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB0x1); |
4774 | #endif |
4775 | #ifdef MSG_PEEK0x2 |
4776 | PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK0x2); |
4777 | #endif |
4778 | #ifdef MSG_DONTROUTE0x4 |
4779 | PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE0x4); |
4780 | #endif |
4781 | #ifdef MSG_DONTWAIT0x80 |
4782 | PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT0x80); |
4783 | #endif |
4784 | #ifdef MSG_EOR0x8 |
4785 | PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR0x8); |
4786 | #endif |
4787 | #ifdef MSG_TRUNC0x10 |
4788 | PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC0x10); |
4789 | #endif |
4790 | #ifdef MSG_CTRUNC0x20 |
4791 | PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC0x20); |
4792 | #endif |
4793 | #ifdef MSG_WAITALL0x40 |
4794 | PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL0x40); |
4795 | #endif |
4796 | #ifdef MSG_BTAG |
4797 | PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); |
4798 | #endif |
4799 | #ifdef MSG_ETAG |
4800 | PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); |
4801 | #endif |
4802 | |
4803 | /* Protocol level and numbers, usable for [gs]etsockopt */ |
4804 | #ifdef SOL_SOCKET0xffff |
4805 | PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET0xffff); |
4806 | #endif |
4807 | #ifdef SOL_IP |
4808 | PyModule_AddIntConstant(m, "SOL_IP", SOL_IP); |
4809 | #else |
4810 | PyModule_AddIntConstant(m, "SOL_IP", 0); |
4811 | #endif |
4812 | #ifdef SOL_IPX |
4813 | PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX); |
4814 | #endif |
4815 | #ifdef SOL_AX25 |
4816 | PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25); |
4817 | #endif |
4818 | #ifdef SOL_ATALK |
4819 | PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK); |
4820 | #endif |
4821 | #ifdef SOL_NETROM |
4822 | PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM); |
4823 | #endif |
4824 | #ifdef SOL_ROSE |
4825 | PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE); |
4826 | #endif |
4827 | #ifdef SOL_TCP |
4828 | PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP); |
4829 | #else |
4830 | PyModule_AddIntConstant(m, "SOL_TCP", 6); |
4831 | #endif |
4832 | #ifdef SOL_UDP |
4833 | PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP); |
4834 | #else |
4835 | PyModule_AddIntConstant(m, "SOL_UDP", 17); |
4836 | #endif |
4837 | #ifdef IPPROTO_IP0 |
4838 | PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP0); |
4839 | #else |
4840 | PyModule_AddIntConstant(m, "IPPROTO_IP", 0); |
4841 | #endif |
4842 | #ifdef IPPROTO_HOPOPTS0 |
4843 | PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS0); |
4844 | #endif |
4845 | #ifdef IPPROTO_ICMP1 |
4846 | PyModule_AddIntConstant(m, "IPPROTO_ICMP", IPPROTO_ICMP1); |
4847 | #else |
4848 | PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); |
4849 | #endif |
4850 | #ifdef IPPROTO_IGMP2 |
4851 | PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP2); |
4852 | #endif |
4853 | #ifdef IPPROTO_GGP3 |
4854 | PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP3); |
4855 | #endif |
4856 | #ifdef IPPROTO_IPV44 |
4857 | PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV44); |
4858 | #endif |
4859 | #ifdef IPPROTO_IPV641 |
4860 | PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV641); |
4861 | #endif |
4862 | #ifdef IPPROTO_IPIP4 |
4863 | PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP4); |
4864 | #endif |
4865 | #ifdef IPPROTO_TCP6 |
4866 | PyModule_AddIntConstant(m, "IPPROTO_TCP", IPPROTO_TCP6); |
4867 | #else |
4868 | PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); |
4869 | #endif |
4870 | #ifdef IPPROTO_EGP8 |
4871 | PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP8); |
4872 | #endif |
4873 | #ifdef IPPROTO_PUP12 |
4874 | PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP12); |
4875 | #endif |
4876 | #ifdef IPPROTO_UDP17 |
4877 | PyModule_AddIntConstant(m, "IPPROTO_UDP", IPPROTO_UDP17); |
4878 | #else |
4879 | PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); |
4880 | #endif |
4881 | #ifdef IPPROTO_IDP22 |
4882 | PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP22); |
4883 | #endif |
4884 | #ifdef IPPROTO_HELLO63 |
4885 | PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO63); |
4886 | #endif |
4887 | #ifdef IPPROTO_ND77 |
4888 | PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND77); |
4889 | #endif |
4890 | #ifdef IPPROTO_TP29 |
4891 | PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP29); |
4892 | #endif |
4893 | #ifdef IPPROTO_IPV641 |
4894 | PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV641); |
4895 | #endif |
4896 | #ifdef IPPROTO_ROUTING43 |
4897 | PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING43); |
4898 | #endif |
4899 | #ifdef IPPROTO_FRAGMENT44 |
4900 | PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT44); |
4901 | #endif |
4902 | #ifdef IPPROTO_RSVP46 |
4903 | PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP46); |
4904 | #endif |
4905 | #ifdef IPPROTO_GRE47 |
4906 | PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE47); |
4907 | #endif |
4908 | #ifdef IPPROTO_ESP50 |
4909 | PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP50); |
4910 | #endif |
4911 | #ifdef IPPROTO_AH51 |
4912 | PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH51); |
4913 | #endif |
4914 | #ifdef IPPROTO_MOBILE |
4915 | PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE); |
4916 | #endif |
4917 | #ifdef IPPROTO_ICMPV658 |
4918 | PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV658); |
4919 | #endif |
4920 | #ifdef IPPROTO_NONE59 |
4921 | PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE59); |
4922 | #endif |
4923 | #ifdef IPPROTO_DSTOPTS60 |
4924 | PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS60); |
4925 | #endif |
4926 | #ifdef IPPROTO_XTP36 |
4927 | PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP36); |
4928 | #endif |
4929 | #ifdef IPPROTO_EON80 |
4930 | PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON80); |
4931 | #endif |
4932 | #ifdef IPPROTO_PIM103 |
4933 | PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM103); |
4934 | #endif |
4935 | #ifdef IPPROTO_IPCOMP108 |
4936 | PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP108); |
4937 | #endif |
4938 | #ifdef IPPROTO_VRRP |
4939 | PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP); |
4940 | #endif |
4941 | #ifdef IPPROTO_BIP |
4942 | PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); |
4943 | #endif |
4944 | /**/ |
4945 | #ifdef IPPROTO_RAW255 |
4946 | PyModule_AddIntConstant(m, "IPPROTO_RAW", IPPROTO_RAW255); |
4947 | #else |
4948 | PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); |
4949 | #endif |
4950 | #ifdef IPPROTO_MAX256 |
4951 | PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX256); |
4952 | #endif |
4953 | |
4954 | /* Some port configuration */ |
4955 | #ifdef IPPORT_RESERVED1024 |
4956 | PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED1024); |
4957 | #else |
4958 | PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); |
4959 | #endif |
4960 | #ifdef IPPORT_USERRESERVED5000 |
4961 | PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED5000); |
4962 | #else |
4963 | PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); |
4964 | #endif |
4965 | |
4966 | /* Some reserved IP v.4 addresses */ |
4967 | #ifdef INADDR_ANY(u_int32_t)0x00000000 |
4968 | PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY(u_int32_t)0x00000000); |
4969 | #else |
4970 | PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); |
4971 | #endif |
4972 | #ifdef INADDR_BROADCAST(u_int32_t)0xffffffff |
4973 | PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST(u_int32_t)0xffffffff); |
4974 | #else |
4975 | PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); |
4976 | #endif |
4977 | #ifdef INADDR_LOOPBACK(u_int32_t)0x7f000001 |
4978 | PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK(u_int32_t)0x7f000001); |
4979 | #else |
4980 | PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); |
4981 | #endif |
4982 | #ifdef INADDR_UNSPEC_GROUP(u_int32_t)0xe0000000 |
4983 | PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP(u_int32_t)0xe0000000); |
4984 | #else |
4985 | PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); |
4986 | #endif |
4987 | #ifdef INADDR_ALLHOSTS_GROUP(u_int32_t)0xe0000001 |
4988 | PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", |
4989 | INADDR_ALLHOSTS_GROUP(u_int32_t)0xe0000001); |
4990 | #else |
4991 | PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); |
4992 | #endif |
4993 | #ifdef INADDR_MAX_LOCAL_GROUP(u_int32_t)0xe00000ff |
4994 | PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", |
4995 | INADDR_MAX_LOCAL_GROUP(u_int32_t)0xe00000ff); |
4996 | #else |
4997 | PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); |
4998 | #endif |
4999 | #ifdef INADDR_NONE0xffffffff |
5000 | PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE0xffffffff); |
5001 | #else |
5002 | PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); |
5003 | #endif |
5004 | |
5005 | /* IPv4 [gs]etsockopt options */ |
5006 | #ifdef IP_OPTIONS1 |
5007 | PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS1); |
5008 | #endif |
5009 | #ifdef IP_HDRINCL2 |
5010 | PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL2); |
5011 | #endif |
5012 | #ifdef IP_TOS3 |
5013 | PyModule_AddIntConstant(m, "IP_TOS", IP_TOS3); |
5014 | #endif |
5015 | #ifdef IP_TTL4 |
5016 | PyModule_AddIntConstant(m, "IP_TTL", IP_TTL4); |
5017 | #endif |
5018 | #ifdef IP_RECVOPTS5 |
5019 | PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS5); |
5020 | #endif |
5021 | #ifdef IP_RECVRETOPTS6 |
5022 | PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS6); |
5023 | #endif |
5024 | #ifdef IP_RECVDSTADDR7 |
5025 | PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR7); |
5026 | #endif |
5027 | #ifdef IP_RETOPTS8 |
5028 | PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS8); |
5029 | #endif |
5030 | #ifdef IP_MULTICAST_IF9 |
5031 | PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF9); |
5032 | #endif |
5033 | #ifdef IP_MULTICAST_TTL10 |
5034 | PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL10); |
5035 | #endif |
5036 | #ifdef IP_MULTICAST_LOOP11 |
5037 | PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP11); |
5038 | #endif |
5039 | #ifdef IP_ADD_MEMBERSHIP12 |
5040 | PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP12); |
5041 | #endif |
5042 | #ifdef IP_DROP_MEMBERSHIP13 |
5043 | PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP13); |
5044 | #endif |
5045 | #ifdef IP_DEFAULT_MULTICAST_TTL1 |
5046 | PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_TTL", |
5047 | IP_DEFAULT_MULTICAST_TTL1); |
5048 | #endif |
5049 | #ifdef IP_DEFAULT_MULTICAST_LOOP1 |
5050 | PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_LOOP", |
5051 | IP_DEFAULT_MULTICAST_LOOP1); |
5052 | #endif |
5053 | #ifdef IP_MAX_MEMBERSHIPS20 |
5054 | PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS20); |
5055 | #endif |
5056 | |
5057 | /* IPv6 [gs]etsockopt options, defined in RFC2553 */ |
5058 | #ifdef IPV6_JOIN_GROUP12 |
5059 | PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP12); |
5060 | #endif |
5061 | #ifdef IPV6_LEAVE_GROUP13 |
5062 | PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP13); |
5063 | #endif |
5064 | #ifdef IPV6_MULTICAST_HOPS10 |
5065 | PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS10); |
5066 | #endif |
5067 | #ifdef IPV6_MULTICAST_IF9 |
5068 | PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF9); |
5069 | #endif |
5070 | #ifdef IPV6_MULTICAST_LOOP11 |
5071 | PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP11); |
5072 | #endif |
5073 | #ifdef IPV6_UNICAST_HOPS4 |
5074 | PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS4); |
5075 | #endif |
5076 | /* Additional IPV6 socket options, defined in RFC 3493 */ |
5077 | #ifdef IPV6_V6ONLY27 |
5078 | PyModule_AddIntConstant(m, "IPV6_V6ONLY", IPV6_V6ONLY27); |
5079 | #endif |
5080 | /* Advanced IPV6 socket options, from RFC 3542 */ |
5081 | #ifdef IPV6_CHECKSUM26 |
5082 | PyModule_AddIntConstant(m, "IPV6_CHECKSUM", IPV6_CHECKSUM26); |
5083 | #endif |
5084 | #ifdef IPV6_DONTFRAG |
5085 | PyModule_AddIntConstant(m, "IPV6_DONTFRAG", IPV6_DONTFRAG); |
5086 | #endif |
5087 | #ifdef IPV6_DSTOPTS23 |
5088 | PyModule_AddIntConstant(m, "IPV6_DSTOPTS", IPV6_DSTOPTS23); |
5089 | #endif |
5090 | #ifdef IPV6_HOPLIMIT20 |
5091 | PyModule_AddIntConstant(m, "IPV6_HOPLIMIT", IPV6_HOPLIMIT20); |
5092 | #endif |
5093 | #ifdef IPV6_HOPOPTS22 |
5094 | PyModule_AddIntConstant(m, "IPV6_HOPOPTS", IPV6_HOPOPTS22); |
5095 | #endif |
5096 | #ifdef IPV6_NEXTHOP21 |
5097 | PyModule_AddIntConstant(m, "IPV6_NEXTHOP", IPV6_NEXTHOP21); |
5098 | #endif |
5099 | #ifdef IPV6_PATHMTU |
5100 | PyModule_AddIntConstant(m, "IPV6_PATHMTU", IPV6_PATHMTU); |
5101 | #endif |
5102 | #ifdef IPV6_PKTINFO19 |
5103 | PyModule_AddIntConstant(m, "IPV6_PKTINFO", IPV6_PKTINFO19); |
5104 | #endif |
5105 | #ifdef IPV6_RECVDSTOPTS |
5106 | PyModule_AddIntConstant(m, "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS); |
5107 | #endif |
5108 | #ifdef IPV6_RECVHOPLIMIT |
5109 | PyModule_AddIntConstant(m, "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT); |
5110 | #endif |
5111 | #ifdef IPV6_RECVHOPOPTS |
5112 | PyModule_AddIntConstant(m, "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS); |
5113 | #endif |
5114 | #ifdef IPV6_RECVPKTINFO |
5115 | PyModule_AddIntConstant(m, "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO); |
5116 | #endif |
5117 | #ifdef IPV6_RECVRTHDR |
5118 | PyModule_AddIntConstant(m, "IPV6_RECVRTHDR", IPV6_RECVRTHDR); |
5119 | #endif |
5120 | #ifdef IPV6_RECVTCLASS35 |
5121 | PyModule_AddIntConstant(m, "IPV6_RECVTCLASS", IPV6_RECVTCLASS35); |
5122 | #endif |
5123 | #ifdef IPV6_RTHDR24 |
5124 | PyModule_AddIntConstant(m, "IPV6_RTHDR", IPV6_RTHDR24); |
5125 | #endif |
5126 | #ifdef IPV6_RTHDRDSTOPTS |
5127 | PyModule_AddIntConstant(m, "IPV6_RTHDRDSTOPTS", IPV6_RTHDRDSTOPTS); |
5128 | #endif |
5129 | #ifdef IPV6_RTHDR_TYPE_00 |
5130 | PyModule_AddIntConstant(m, "IPV6_RTHDR_TYPE_0", IPV6_RTHDR_TYPE_00); |
5131 | #endif |
5132 | #ifdef IPV6_RECVPATHMTU |
5133 | PyModule_AddIntConstant(m, "IPV6_RECVPATHMTU", IPV6_RECVPATHMTU); |
5134 | #endif |
5135 | #ifdef IPV6_TCLASS36 |
5136 | PyModule_AddIntConstant(m, "IPV6_TCLASS", IPV6_TCLASS36); |
5137 | #endif |
5138 | #ifdef IPV6_USE_MIN_MTU |
5139 | PyModule_AddIntConstant(m, "IPV6_USE_MIN_MTU", IPV6_USE_MIN_MTU); |
5140 | #endif |
5141 | |
5142 | /* TCP options */ |
5143 | #ifdef TCP_NODELAY0x01 |
5144 | PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY0x01); |
5145 | #endif |
5146 | #ifdef TCP_MAXSEG0x02 |
5147 | PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG0x02); |
5148 | #endif |
5149 | #ifdef TCP_CORK |
5150 | PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK); |
5151 | #endif |
5152 | #ifdef TCP_KEEPIDLE |
5153 | PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE); |
5154 | #endif |
5155 | #ifdef TCP_KEEPINTVL |
5156 | PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL); |
5157 | #endif |
5158 | #ifdef TCP_KEEPCNT |
5159 | PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT); |
5160 | #endif |
5161 | #ifdef TCP_SYNCNT |
5162 | PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT); |
5163 | #endif |
5164 | #ifdef TCP_LINGER2 |
5165 | PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2); |
5166 | #endif |
5167 | #ifdef TCP_DEFER_ACCEPT |
5168 | PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); |
5169 | #endif |
5170 | #ifdef TCP_WINDOW_CLAMP |
5171 | PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); |
5172 | #endif |
5173 | #ifdef TCP_INFO |
5174 | PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO); |
5175 | #endif |
5176 | #ifdef TCP_QUICKACK |
5177 | PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); |
5178 | #endif |
5179 | |
5180 | |
5181 | /* IPX options */ |
5182 | #ifdef IPX_TYPE |
5183 | PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE); |
5184 | #endif |
5185 | |
5186 | /* get{addr,name}info parameters */ |
5187 | #ifdef EAI_ADDRFAMILY1 |
5188 | PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY1); |
5189 | #endif |
5190 | #ifdef EAI_AGAIN2 |
5191 | PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN2); |
5192 | #endif |
5193 | #ifdef EAI_BADFLAGS3 |
5194 | PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS3); |
5195 | #endif |
5196 | #ifdef EAI_FAIL4 |
5197 | PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL4); |
5198 | #endif |
5199 | #ifdef EAI_FAMILY5 |
5200 | PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY5); |
5201 | #endif |
5202 | #ifdef EAI_MEMORY6 |
5203 | PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY6); |
5204 | #endif |
5205 | #ifdef EAI_NODATA7 |
5206 | PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA7); |
5207 | #endif |
5208 | #ifdef EAI_NONAME8 |
5209 | PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME8); |
5210 | #endif |
5211 | #ifdef EAI_OVERFLOW14 |
5212 | PyModule_AddIntConstant(m, "EAI_OVERFLOW", EAI_OVERFLOW14); |
5213 | #endif |
5214 | #ifdef EAI_SERVICE9 |
5215 | PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE9); |
5216 | #endif |
5217 | #ifdef EAI_SOCKTYPE10 |
5218 | PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE10); |
5219 | #endif |
5220 | #ifdef EAI_SYSTEM11 |
5221 | PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM11); |
5222 | #endif |
5223 | #ifdef EAI_BADHINTS12 |
5224 | PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS12); |
5225 | #endif |
5226 | #ifdef EAI_PROTOCOL13 |
5227 | PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL13); |
5228 | #endif |
5229 | #ifdef EAI_MAX15 |
5230 | PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX15); |
5231 | #endif |
5232 | #ifdef AI_PASSIVE0x00000001 |
5233 | PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE0x00000001); |
5234 | #endif |
5235 | #ifdef AI_CANONNAME0x00000002 |
5236 | PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME0x00000002); |
5237 | #endif |
5238 | #ifdef AI_NUMERICHOST0x00000004 |
5239 | PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST0x00000004); |
5240 | #endif |
5241 | #ifdef AI_NUMERICSERV0x00001000 |
5242 | PyModule_AddIntConstant(m, "AI_NUMERICSERV", AI_NUMERICSERV0x00001000); |
5243 | #endif |
5244 | #ifdef AI_MASK(0x00000001 | 0x00000002 | 0x00000004 | 0x00001000 | 0x00000400 ) |
5245 | PyModule_AddIntConstant(m, "AI_MASK", AI_MASK(0x00000001 | 0x00000002 | 0x00000004 | 0x00001000 | 0x00000400 )); |
5246 | #endif |
5247 | #ifdef AI_ALL0x00000100 |
5248 | PyModule_AddIntConstant(m, "AI_ALL", AI_ALL0x00000100); |
5249 | #endif |
5250 | #ifdef AI_V4MAPPED_CFG0x00000200 |
5251 | PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG0x00000200); |
5252 | #endif |
5253 | #ifdef AI_ADDRCONFIG0x00000400 |
5254 | PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG0x00000400); |
5255 | #endif |
5256 | #ifdef AI_V4MAPPED0x00000800 |
5257 | PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED0x00000800); |
5258 | #endif |
5259 | #ifdef AI_DEFAULT(0x00000200 | 0x00000400) |
5260 | PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT(0x00000200 | 0x00000400)); |
5261 | #endif |
5262 | #ifdef NI_MAXHOST1025 |
5263 | PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST1025); |
5264 | #endif |
5265 | #ifdef NI_MAXSERV32 |
5266 | PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV32); |
5267 | #endif |
5268 | #ifdef NI_NOFQDN0x00000001 |
5269 | PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN0x00000001); |
5270 | #endif |
5271 | #ifdef NI_NUMERICHOST0x00000002 |
5272 | PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST0x00000002); |
5273 | #endif |
5274 | #ifdef NI_NAMEREQD0x00000004 |
5275 | PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD0x00000004); |
5276 | #endif |
5277 | #ifdef NI_NUMERICSERV0x00000008 |
5278 | PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV0x00000008); |
5279 | #endif |
5280 | #ifdef NI_DGRAM0x00000010 |
5281 | PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM0x00000010); |
5282 | #endif |
5283 | |
5284 | /* shutdown() parameters */ |
5285 | #ifdef SHUT_RD0 |
5286 | PyModule_AddIntConstant(m, "SHUT_RD", SHUT_RD0); |
5287 | #elif defined(SD_RECEIVE) |
5288 | PyModule_AddIntConstant(m, "SHUT_RD", SD_RECEIVE); |
5289 | #else |
5290 | PyModule_AddIntConstant(m, "SHUT_RD", 0); |
5291 | #endif |
5292 | #ifdef SHUT_WR1 |
5293 | PyModule_AddIntConstant(m, "SHUT_WR", SHUT_WR1); |
5294 | #elif defined(SD_SEND) |
5295 | PyModule_AddIntConstant(m, "SHUT_WR", SD_SEND); |
5296 | #else |
5297 | PyModule_AddIntConstant(m, "SHUT_WR", 1); |
5298 | #endif |
5299 | #ifdef SHUT_RDWR2 |
5300 | PyModule_AddIntConstant(m, "SHUT_RDWR", SHUT_RDWR2); |
5301 | #elif defined(SD_BOTH) |
5302 | PyModule_AddIntConstant(m, "SHUT_RDWR", SD_BOTH); |
5303 | #else |
5304 | PyModule_AddIntConstant(m, "SHUT_RDWR", 2); |
5305 | #endif |
5306 | |
5307 | #ifdef SIO_RCVALL |
5308 | { |
5309 | DWORD codes[] = {SIO_RCVALL, SIO_KEEPALIVE_VALS}; |
5310 | const char *names[] = {"SIO_RCVALL", "SIO_KEEPALIVE_VALS"}; |
5311 | int i; |
5312 | for(i = 0; i<sizeof(codes)/sizeof(*codes); ++i) { |
5313 | PyObject *tmp; |
5314 | tmp = PyLong_FromUnsignedLong(codes[i]); |
5315 | if (tmp == NULL((void*)0)) |
5316 | return NULL((void*)0); |
5317 | PyModule_AddObject(m, names[i], tmp); |
5318 | } |
5319 | } |
5320 | PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF); |
5321 | PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON); |
5322 | PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY); |
5323 | #ifdef RCVALL_IPLEVEL |
5324 | PyModule_AddIntConstant(m, "RCVALL_IPLEVEL", RCVALL_IPLEVEL); |
5325 | #endif |
5326 | #ifdef RCVALL_MAX |
5327 | PyModule_AddIntConstant(m, "RCVALL_MAX", RCVALL_MAX); |
5328 | #endif |
5329 | #endif /* _MSTCPIP_ */ |
5330 | |
5331 | /* Initialize gethostbyname lock */ |
5332 | #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
5333 | netdb_lock = PyThread_allocate_lock(); |
5334 | #endif |
5335 | return m; |
5336 | } |
5337 | |
5338 | |
5339 | #ifndef HAVE_INET_PTON1 |
5340 | #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
5341 | |
5342 | /* Simplistic emulation code for inet_pton that only works for IPv4 */ |
5343 | /* These are not exposed because they do not set errno properly */ |
5344 | |
5345 | int |
5346 | inet_pton(int af, const char *src, void *dst) |
5347 | { |
5348 | if (af == AF_INET2) { |
5349 | #if (SIZEOF_INT4 != 4) |
5350 | #error "Not sure if in_addr_t exists and int is not 32-bits." |
5351 | #endif |
5352 | unsigned int packed_addr; |
5353 | packed_addr = inet_addr(src); |
5354 | if (packed_addr == INADDR_NONE0xffffffff) |
5355 | return 0; |
5356 | memcpy(dst, &packed_addr, 4)((__builtin_object_size (dst, 0) != (size_t) -1) ? __builtin___memcpy_chk (dst, &packed_addr, 4, __builtin_object_size (dst, 0)) : __inline_memcpy_chk (dst, &packed_addr, 4)); |
5357 | return 1; |
5358 | } |
5359 | /* Should set errno to EAFNOSUPPORT */ |
5360 | return -1; |
5361 | } |
5362 | |
5363 | const char * |
5364 | inet_ntop(int af, const void *src, char *dst, socklen_t size) |
5365 | { |
5366 | if (af == AF_INET2) { |
5367 | struct in_addr packed_addr; |
5368 | if (size < 16) |
5369 | /* Should set errno to ENOSPC. */ |
5370 | return NULL((void*)0); |
5371 | memcpy(&packed_addr, src, sizeof(packed_addr))((__builtin_object_size (&packed_addr, 0) != (size_t) -1) ? __builtin___memcpy_chk (&packed_addr, src, sizeof(packed_addr ), __builtin_object_size (&packed_addr, 0)) : __inline_memcpy_chk (&packed_addr, src, sizeof(packed_addr))); |
5372 | return strncpy(dst, inet_ntoa(packed_addr), size)((__builtin_object_size (dst, 0) != (size_t) -1) ? __builtin___strncpy_chk (dst, inet_ntoa(packed_addr), size, __builtin_object_size (dst , 2 > 1)) : __inline_strncpy_chk (dst, inet_ntoa(packed_addr ), size)); |
5373 | } |
5374 | /* Should set errno to EAFNOSUPPORT */ |
5375 | return NULL((void*)0); |
5376 | } |
5377 | |
5378 | #endif |
5379 | #endif |