Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(9)

Delta Between Two Patch Sets: Modules/socketmodule.c

Issue 27744: Add AF_ALG (Linux Kernel crypto) to socket module
Left Patch Set: Created 3 years, 6 months ago
Right Patch Set: Created 3 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« Lib/test/test_socket.py ('K') | « Lib/test/test_socket.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* Socket module */ 1 /* Socket module */
2 2
3 /* 3 /*
4 4
5 This module provides an interface to Berkeley socket IPC. 5 This module provides an interface to Berkeley socket IPC.
6 6
7 Limitations: 7 Limitations:
8 8
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a 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 10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 listen([n]) -- start listening for incoming connections\n\ 129 listen([n]) -- start listening for incoming connections\n\
130 recv(buflen[, flags]) -- receive data\n\ 130 recv(buflen[, flags]) -- receive data\n\
131 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ 131 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\
132 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\ 132 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\
133 recvfrom_into(buffer[, nbytes, [, flags])\n\ 133 recvfrom_into(buffer[, nbytes, [, flags])\n\
134 -- receive data and sender\'s address (into a buffer)\n\ 134 -- receive data and sender\'s address (into a buffer)\n\
135 sendall(data[, flags]) -- send all data\n\ 135 sendall(data[, flags]) -- send all data\n\
136 send(data[, flags]) -- send data, may not send all of it\n\ 136 send(data[, flags]) -- send data, may not send all of it\n\
137 sendto(data[, flags], addr) -- send data to a given address\n\ 137 sendto(data[, flags], addr) -- send data to a given address\n\
138 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\ 138 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\
139 setsockopt(level, optname, value) -- set socket options\n\ 139 setsockopt(level, optname, value[, optlen]) -- set socket options\n\
140 settimeout(None | float) -- set or clear the timeout\n\ 140 settimeout(None | float) -- set or clear the timeout\n\
141 shutdown(how) -- shut down traffic in one or both directions\n\ 141 shutdown(how) -- shut down traffic in one or both directions\n\
142 if_nameindex() -- return all network interface indices and names\n\ 142 if_nameindex() -- return all network interface indices and names\n\
143 if_nametoindex(name) -- return the corresponding interface index\n\ 143 if_nametoindex(name) -- return the corresponding interface index\n\
144 if_indextoname(index) -- return the corresponding interface name\n\ 144 if_indextoname(index) -- return the corresponding interface name\n\
145 \n\ 145 \n\
146 [*] not available on all platforms!"); 146 [*] not available on all platforms!");
147 147
148 /* XXX This is a terrible mess of platform-dependent preprocessor hacks. 148 /* XXX This is a terrible mess of platform-dependent preprocessor hacks.
149 I hope some day someone can clean this up please... */ 149 I hope some day someone can clean this up please... */
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 #endif 287 #endif
288 288
289 #ifdef HAVE_SOCKADDR_ALG 289 #ifdef HAVE_SOCKADDR_ALG
290 #include <linux/if_alg.h> 290 #include <linux/if_alg.h>
291 #ifndef AF_ALG 291 #ifndef AF_ALG
292 #define AF_ALG 38 292 #define AF_ALG 38
293 #endif 293 #endif
294 #ifndef SOL_ALG 294 #ifndef SOL_ALG
295 #define SOL_ALG 279 295 #define SOL_ALG 279
296 #endif 296 #endif
297 #endif 297
298 /* Linux 3.19 */
299 #ifndef ALG_SET_AEAD_ASSOCLEN
300 #define ALG_SET_AEAD_ASSOCLEN 4
301 #endif
302 #ifndef ALG_SET_AEAD_AUTHSIZE
303 #define ALG_SET_AEAD_AUTHSIZE 5
304 #endif
305 /* Linux 4.8 */
306 #ifndef ALG_SET_PUBKEY
307 #define ALG_SET_PUBKEY 6
308 #endif
309
310 #ifndef ALG_OP_SIGN
311 #define ALG_OP_SIGN 2
312 #endif
313 #ifndef ALG_OP_VERIFY
314 #define ALG_OP_VERIFY 3
315 #endif
316
317 #endif /* HAVE_SOCKADDR_ALG */
298 318
299 /* Generic socket object definitions and includes */ 319 /* Generic socket object definitions and includes */
300 #define PySocket_BUILDING_SOCKET 320 #define PySocket_BUILDING_SOCKET
301 #include "socketmodule.h" 321 #include "socketmodule.h"
302 322
303 /* Addressing includes */ 323 /* Addressing includes */
304 324
305 #ifndef MS_WINDOWS 325 #ifndef MS_WINDOWS
306 326
307 /* Non-MS WINDOWS includes */ 327 /* Non-MS WINDOWS includes */
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 char *type; 1993 char *type;
1974 char *name; 1994 char *name;
1975 sa = (struct sockaddr_alg *)addr_ret; 1995 sa = (struct sockaddr_alg *)addr_ret;
1976 1996
1977 memset(sa, 0, sizeof(*sa)); 1997 memset(sa, 0, sizeof(*sa));
1978 sa->salg_family = AF_ALG; 1998 sa->salg_family = AF_ALG;
1979 1999
1980 if (!PyArg_ParseTuple(args, "ss|HH:getsockaddrarg", 2000 if (!PyArg_ParseTuple(args, "ss|HH:getsockaddrarg",
1981 &type, &name, &sa->salg_feat, &sa->salg_mask)) 2001 &type, &name, &sa->salg_feat, &sa->salg_mask))
1982 return 0; 2002 return 0;
2003 /* sockaddr_alg has fixed-sized char arrays for type and name */
1983 if (strlen(type) > sizeof(sa->salg_type)) { 2004 if (strlen(type) > sizeof(sa->salg_type)) {
1984 PyErr_SetString(PyExc_ValueError, "AF_ALG type too long."); 2005 PyErr_SetString(PyExc_ValueError, "AF_ALG type too long.");
1985 return 0; 2006 return 0;
1986 } 2007 }
1987 strncpy((char *)sa->salg_type, type, sizeof(sa->salg_type)); 2008 strncpy((char *)sa->salg_type, type, sizeof(sa->salg_type));
1988 if (strlen(name) > sizeof(sa->salg_name)) { 2009 if (strlen(name) > sizeof(sa->salg_name)) {
1989 PyErr_SetString(PyExc_ValueError, "AF_ALG name too long."); 2010 PyErr_SetString(PyExc_ValueError, "AF_ALG name too long.");
1990 return 0; 2011 return 0;
1991 } 2012 }
1992 strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name)); 2013 strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2297 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2277 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */ 2298 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */
2278 static int accept4_works = -1; 2299 static int accept4_works = -1;
2279 #endif 2300 #endif
2280 2301
2281 static int 2302 static int
2282 sock_accept_impl(PySocketSockObject *s, void *data) 2303 sock_accept_impl(PySocketSockObject *s, void *data)
2283 { 2304 {
2284 struct sock_accept *ctx = data; 2305 struct sock_accept *ctx = data;
2285 struct sockaddr *addr = SAS2SA(ctx->addrbuf); 2306 struct sockaddr *addr = SAS2SA(ctx->addrbuf);
2286 socklen_t *addrlen = ctx->addrlen; 2307 socklen_t *paddrlen = ctx->addrlen;
2287 #ifdef HAVE_SOCKADDR_ALG 2308 #ifdef HAVE_SOCKADDR_ALG
2288 /* AF_ALG does not support accept() with addr and raises 2309 /* AF_ALG does not support accept() with addr and raises
2289 * ECONNABORTED instead. */ 2310 * ECONNABORTED instead. */
2290 if (s->sock_family == AF_ALG) { 2311 if (s->sock_family == AF_ALG) {
2291 addr = NULL; 2312 addr = NULL;
2292 addrlen = NULL; 2313 paddrlen = NULL;
2293 *ctx->addrlen = 0; 2314 *ctx->addrlen = 0;
haypo 2016/08/17 13:20:25 Is it needed to set address length to zero since y
2294 } 2315 }
2295 #endif 2316 #endif
2296 2317
2297 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2318 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2298 if (accept4_works != 0) { 2319 if (accept4_works != 0) {
2299 ctx->result = accept4(s->sock_fd, addr, addrlen, 2320 ctx->result = accept4(s->sock_fd, addr, paddrlen,
2300 SOCK_CLOEXEC); 2321 SOCK_CLOEXEC);
2301 if (ctx->result == INVALID_SOCKET && accept4_works == -1) { 2322 if (ctx->result == INVALID_SOCKET && accept4_works == -1) {
2302 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */ 2323 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */
2303 accept4_works = (errno != ENOSYS); 2324 accept4_works = (errno != ENOSYS);
2304 } 2325 }
2305 } 2326 }
2306 if (accept4_works == 0) 2327 if (accept4_works == 0)
2307 ctx->result = accept(s->sock_fd, addr, addrlen); 2328 ctx->result = accept(s->sock_fd, addr, paddrlen);
2308 #else 2329 #else
2309 ctx->result = accept(s->sock_fd, addr, addrlen); 2330 ctx->result = accept(s->sock_fd, addr, paddrlen);
2310 #endif 2331 #endif
2311 2332
2312 #ifdef MS_WINDOWS 2333 #ifdef MS_WINDOWS
2313 return (ctx->result != INVALID_SOCKET); 2334 return (ctx->result != INVALID_SOCKET);
2314 #else 2335 #else
2315 return (ctx->result >= 0); 2336 return (ctx->result >= 0);
2316 #endif 2337 #endif
2317 } 2338 }
2318 2339
2319 /* s._accept() -> (fd, address) */ 2340 /* s._accept() -> (fd, address) */
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 } 2522 }
2502 2523
2503 PyDoc_STRVAR(gettimeout_doc, 2524 PyDoc_STRVAR(gettimeout_doc,
2504 "gettimeout() -> timeout\n\ 2525 "gettimeout() -> timeout\n\
2505 \n\ 2526 \n\
2506 Returns the timeout in seconds (float) associated with socket \n\ 2527 Returns the timeout in seconds (float) associated with socket \n\
2507 operations. A timeout of None indicates that timeouts on socket \n\ 2528 operations. A timeout of None indicates that timeouts on socket \n\
2508 operations are disabled."); 2529 operations are disabled.");
2509 2530
2510 /* s.setsockopt() method. 2531 /* s.setsockopt() method.
2511 With an integer third argument, sets an integer option. 2532 With an integer third argument, sets an integer optval with optlen=4.
2533 With None as third argument and an integer fourth argument, set
2534 optval=NULL with unsigned int as optlen.
2512 With a string third argument, sets an option from a buffer; 2535 With a string third argument, sets an option from a buffer;
2513 use optional built-in module 'struct' to encode the string. */ 2536 use optional built-in module 'struct' to encode the string.
2537 */
2514 2538
2515 static PyObject * 2539 static PyObject *
2516 sock_setsockopt(PySocketSockObject *s, PyObject *args) 2540 sock_setsockopt(PySocketSockObject *s, PyObject *args)
2517 { 2541 {
2518 int level; 2542 int level;
2519 int optname; 2543 int optname;
2520 int res; 2544 int res;
2521 Py_buffer optval; 2545 Py_buffer optval;
2522 int flag; 2546 int flag;
2523 2547 unsigned int optlen;
haypo 2016/09/01 23:10:30 Oh, thanks for fixing optlen type ;-)
2548 PyObject *none;
2549
2550 /* setsockopt(level, opt, flag) */
2524 if (PyArg_ParseTuple(args, "iii:setsockopt", 2551 if (PyArg_ParseTuple(args, "iii:setsockopt",
2525 &level, &optname, &flag)) { 2552 &level, &optname, &flag)) {
2526 res = setsockopt(s->sock_fd, level, optname, 2553 res = setsockopt(s->sock_fd, level, optname,
2527 (char*)&flag, sizeof flag); 2554 (char*)&flag, sizeof flag);
2528 } 2555 goto done;
2529 else { 2556 }
2530 PyErr_Clear(); 2557
2531 if (!PyArg_ParseTuple(args, "iiy*:setsockopt", 2558 PyErr_Clear();
2532 &level, &optname, &optval)) 2559 /* setsockopt(level, opt, (None, flag)) */
haypo 2016/09/01 23:10:30 The comment is still outdated, no?
2533 return NULL; 2560 if (PyArg_ParseTuple(args, "iiO!I:setsockopt",
2561 &level, &optname, Py_TYPE(Py_None), &none, &optlen)) {
2562 assert(sizeof(socklen_t) >= sizeof(unsigned int));
2563 res = setsockopt(s->sock_fd, level, optname,
2564 NULL, (socklen_t)optlen);
2565 goto done;
2566 }
2567
2568 PyErr_Clear();
2569 /* setsockopt(level, opt, buffer) */
2570 if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
2571 &level, &optname, &optval))
2572 return NULL;
2573
2534 #ifdef MS_WINDOWS 2574 #ifdef MS_WINDOWS
2535 if (optval.len > INT_MAX) { 2575 if (optval.len > INT_MAX) {
2536 PyBuffer_Release(&optval); 2576 PyBuffer_Release(&optval);
2537 PyErr_Format(PyExc_OverflowError, 2577 PyErr_Format(PyExc_OverflowError,
2538 "socket option is larger than %i bytes", 2578 "socket option is larger than %i bytes",
2539 INT_MAX); 2579 INT_MAX);
2540 return NULL; 2580 return NULL;
2541 } 2581 }
2542 res = setsockopt(s->sock_fd, level, optname, 2582 res = setsockopt(s->sock_fd, level, optname,
2543 optval.buf, (int)optval.len); 2583 optval.buf, (int)optval.len);
2544 #else 2584 #else
2545 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len); 2585 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
2546 #endif 2586 #endif
2547 PyBuffer_Release(&optval); 2587 PyBuffer_Release(&optval);
2548 } 2588
2589 done:
2549 if (res < 0) { 2590 if (res < 0) {
2550 return s->errorhandler(); 2591 return s->errorhandler();
2551 } 2592 }
2552 2593
2553 Py_RETURN_NONE; 2594 Py_RETURN_NONE;
2554 } 2595 }
2555 2596
2556 PyDoc_STRVAR(setsockopt_doc, 2597 PyDoc_STRVAR(setsockopt_doc,
2557 "setsockopt(level, option, value)\n\ 2598 "setsockopt(level, option, value: int)\n\
2599 setsockopt(level, option, value: buffer)\n\
2600 setsockopt(level, option, None, optlen: int)\n\
2558 \n\ 2601 \n\
2559 Set a socket option. See the Unix manual for level and option.\n\ 2602 Set a socket option. See the Unix manual for level and option.\n\
2560 The value argument can either be an integer or a string."); 2603 The value argument can either be an integer, a string buffer, or \n\
2604 None, optlen.");
2561 2605
2562 2606
2563 /* s.getsockopt() method. 2607 /* s.getsockopt() method.
2564 With two arguments, retrieves an integer option. 2608 With two arguments, retrieves an integer option.
2565 With a third integer argument, retrieves a string buffer of that size; 2609 With a third integer argument, retrieves a string buffer of that size;
2566 use optional built-in module 'struct' to decode the string. */ 2610 use optional built-in module 'struct' to decode the string. */
2567 2611
2568 static PyObject * 2612 static PyObject *
2569 sock_getsockopt(PySocketSockObject *s, PyObject *args) 2613 sock_getsockopt(PySocketSockObject *s, PyObject *args)
2570 { 2614 {
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
3840 /* The sendmsg() and recvmsg[_into]() methods require a working 3884 /* The sendmsg() and recvmsg[_into]() methods require a working
3841 CMSG_LEN(). See the comment near get_CMSG_LEN(). */ 3885 CMSG_LEN(). See the comment near get_CMSG_LEN(). */
3842 #ifdef CMSG_LEN 3886 #ifdef CMSG_LEN
3843 struct sock_sendmsg { 3887 struct sock_sendmsg {
3844 struct msghdr *msg; 3888 struct msghdr *msg;
3845 int flags; 3889 int flags;
3846 ssize_t result; 3890 ssize_t result;
3847 }; 3891 };
3848 3892
3849 static int 3893 static int
3894 sock_sendmsg_iovec(PySocketSockObject *s, PyObject *data_arg,
3895 struct msghdr *msg,
3896 Py_buffer **databufsout, Py_ssize_t *ndatabufsout) {
3897 Py_ssize_t ndataparts, ndatabufs = 0;
3898 int result = -1;
3899 struct iovec *iovs = NULL;
3900 PyObject *data_fast = NULL;
3901 Py_buffer *databufs = NULL;
3902
3903 /* Fill in an iovec for each message part, and save the Py_buffer
3904 structs to release afterwards. */
3905 if ((data_fast = PySequence_Fast(data_arg,
3906 "sendmsg() argument 1 must be an "
3907 "iterable")) == NULL)
3908 goto finally;
3909 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3910 if (ndataparts > INT_MAX) {
3911 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3912 goto finally;
3913 }
3914 msg->msg_iovlen = ndataparts;
3915 if (ndataparts > 0 &&
3916 ((msg->msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3917 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3918 PyErr_NoMemory();
3919 goto finally;
3920 }
3921 for (; ndatabufs < ndataparts; ndatabufs++) {
3922 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3923 "y*;sendmsg() argument 1 must be an iterable of "
3924 "bytes-like objects",
3925 &databufs[ndatabufs]))
3926 goto finally;
3927 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3928 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3929 }
3930 result = 0;
3931 finally:
3932 *databufsout = databufs;
3933 *ndatabufsout = ndatabufs;
3934 Py_XDECREF(data_fast);
3935 return result;
3936 }
3937
3938 static int
3850 sock_sendmsg_impl(PySocketSockObject *s, void *data) 3939 sock_sendmsg_impl(PySocketSockObject *s, void *data)
3851 { 3940 {
3852 struct sock_sendmsg *ctx = data; 3941 struct sock_sendmsg *ctx = data;
3853 3942
3854 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags); 3943 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags);
3855 return (ctx->result >= 0); 3944 return (ctx->result >= 0);
3856 } 3945 }
3857 3946
3858 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */ 3947 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */
3859 3948
3860 static PyObject * 3949 static PyObject *
3861 sock_sendmsg(PySocketSockObject *s, PyObject *args) 3950 sock_sendmsg(PySocketSockObject *s, PyObject *args)
3862 { 3951 {
3863 Py_ssize_t i, ndataparts, ndatabufs = 0, ncmsgs, ncmsgbufs = 0; 3952 Py_ssize_t i, ndatabufs = 0, ncmsgs, ncmsgbufs = 0;
3864 Py_buffer *databufs = NULL; 3953 Py_buffer *databufs = NULL;
3865 struct iovec *iovs = NULL;
3866 sock_addr_t addrbuf; 3954 sock_addr_t addrbuf;
3867 struct msghdr msg = {0}; 3955 struct msghdr msg = {0};
3868 struct cmsginfo { 3956 struct cmsginfo {
3869 int level; 3957 int level;
3870 int type; 3958 int type;
3871 Py_buffer data; 3959 Py_buffer data;
3872 } *cmsgs = NULL; 3960 } *cmsgs = NULL;
3873 void *controlbuf = NULL; 3961 void *controlbuf = NULL;
3874 size_t controllen, controllen_last; 3962 size_t controllen, controllen_last;
3875 int addrlen, flags = 0; 3963 int addrlen, flags = 0;
3876 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL, *data_fast = NULL, 3964 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL,
3877 *cmsg_fast = NULL, *retval = NULL; 3965 *cmsg_fast = NULL, *retval = NULL;
3878 struct sock_sendmsg ctx; 3966 struct sock_sendmsg ctx;
3879 3967
3880 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg", 3968 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg",
3881 &data_arg, &cmsg_arg, &flags, &addr_arg)) 3969 &data_arg, &cmsg_arg, &flags, &addr_arg))
3882 return NULL; 3970 return NULL;
3883 3971
3884 /* Parse destination address. */ 3972 /* Parse destination address. */
3885 if (addr_arg != NULL && addr_arg != Py_None) { 3973 if (addr_arg != NULL && addr_arg != Py_None) {
3886 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen)) 3974 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen))
3887 goto finally; 3975 goto finally;
3888 msg.msg_name = &addrbuf; 3976 msg.msg_name = &addrbuf;
3889 msg.msg_namelen = addrlen; 3977 msg.msg_namelen = addrlen;
3890 } 3978 }
3891 3979
3892 /* Fill in an iovec for each message part, and save the Py_buffer 3980 /* Fill in an iovec for each message part, and save the Py_buffer
3893 structs to release afterwards. */ 3981 structs to release afterwards. */
3894 if ((data_fast = PySequence_Fast(data_arg, 3982 if (sock_sendmsg_iovec(s, data_arg, &msg, &databufs, &ndatabufs) == -1) {
3895 "sendmsg() argument 1 must be an "
3896 "iterable")) == NULL)
3897 goto finally; 3983 goto finally;
3898 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3899 if (ndataparts > INT_MAX) {
3900 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3901 goto finally;
3902 }
3903 msg.msg_iovlen = ndataparts;
3904 if (ndataparts > 0 &&
3905 ((msg.msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3906 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3907 PyErr_NoMemory();
3908 goto finally;
3909 }
3910 for (; ndatabufs < ndataparts; ndatabufs++) {
3911 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3912 "y*;sendmsg() argument 1 must be an iterable of "
3913 "bytes-like objects",
3914 &databufs[ndatabufs]))
3915 goto finally;
3916 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3917 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3918 } 3984 }
3919 3985
3920 if (cmsg_arg == NULL) 3986 if (cmsg_arg == NULL)
3921 ncmsgs = 0; 3987 ncmsgs = 0;
3922 else { 3988 else {
3923 if ((cmsg_fast = PySequence_Fast(cmsg_arg, 3989 if ((cmsg_fast = PySequence_Fast(cmsg_arg,
3924 "sendmsg() argument 2 must be an " 3990 "sendmsg() argument 2 must be an "
3925 "iterable")) == NULL) 3991 "iterable")) == NULL)
3926 goto finally; 3992 goto finally;
3927 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast); 3993 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
4038 4104
4039 finally: 4105 finally:
4040 PyMem_Free(controlbuf); 4106 PyMem_Free(controlbuf);
4041 for (i = 0; i < ncmsgbufs; i++) 4107 for (i = 0; i < ncmsgbufs; i++)
4042 PyBuffer_Release(&cmsgs[i].data); 4108 PyBuffer_Release(&cmsgs[i].data);
4043 PyMem_Free(cmsgs); 4109 PyMem_Free(cmsgs);
4044 Py_XDECREF(cmsg_fast); 4110 Py_XDECREF(cmsg_fast);
4045 for (i = 0; i < ndatabufs; i++) 4111 for (i = 0; i < ndatabufs; i++)
4046 PyBuffer_Release(&databufs[i]); 4112 PyBuffer_Release(&databufs[i]);
4047 PyMem_Free(databufs); 4113 PyMem_Free(databufs);
4048 PyMem_Free(iovs);
4049 Py_XDECREF(data_fast);
4050 return retval; 4114 return retval;
4051 } 4115 }
4052 4116
4053 PyDoc_STRVAR(sendmsg_doc, 4117 PyDoc_STRVAR(sendmsg_doc,
4054 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\ 4118 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\
4055 \n\ 4119 \n\
4056 Send normal and ancillary data to the socket, gathering the\n\ 4120 Send normal and ancillary data to the socket, gathering the\n\
4057 non-ancillary data from a series of buffers and concatenating it into\n\ 4121 non-ancillary data from a series of buffers and concatenating it into\n\
4058 a single message. The buffers argument specifies the non-ancillary\n\ 4122 a single message. The buffers argument specifies the non-ancillary\n\
4059 data as an iterable of bytes-like objects (e.g. bytes objects).\n\ 4123 data as an iterable of bytes-like objects (e.g. bytes objects).\n\
4060 The ancdata argument specifies the ancillary data (control messages)\n\ 4124 The ancdata argument specifies the ancillary data (control messages)\n\
4061 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\ 4125 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\
4062 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\ 4126 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\
4063 protocol level and protocol-specific type respectively, and cmsg_data\n\ 4127 protocol level and protocol-specific type respectively, and cmsg_data\n\
4064 is a bytes-like object holding the associated data. The flags\n\ 4128 is a bytes-like object holding the associated data. The flags\n\
4065 argument defaults to 0 and has the same meaning as for send(). If\n\ 4129 argument defaults to 0 and has the same meaning as for send(). If\n\
4066 address is supplied and not None, it sets a destination address for\n\ 4130 address is supplied and not None, it sets a destination address for\n\
4067 the message. The return value is the number of bytes of non-ancillary\n\ 4131 the message. The return value is the number of bytes of non-ancillary\n\
4068 data sent."); 4132 data sent.");
4069 #endif /* CMSG_LEN */ 4133 #endif /* CMSG_LEN */
4070 4134
4071 #ifdef HAVE_SOCKADDR_ALG 4135 #ifdef HAVE_SOCKADDR_ALG
4072 static PyObject* 4136 static PyObject*
4073 sock_algset(PySocketSockObject *self, PyObject *args, PyObject *kwds) 4137 sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds)
4074 { 4138 {
4075 PyObject *retval = NULL; 4139 PyObject *retval = NULL;
4140
4141 Py_ssize_t i, ndatabufs = 0;
4142 Py_buffer *databufs = NULL;
4143 PyObject *data_arg = NULL;
4144
4076 Py_buffer iv = {NULL, NULL}; 4145 Py_buffer iv = {NULL, NULL};
4077 int type = -1; 4146
4147 PyObject *opobj = NULL;
4148 int op = -1;
4149
4150 PyObject *assoclenobj = NULL;
4078 int assoclen = -1; 4151 int assoclen = -1;
4152
4079 unsigned int *uiptr; 4153 unsigned int *uiptr;
4080 int flags = 0; 4154 int flags = 0;
4155
4081 struct msghdr msg; 4156 struct msghdr msg;
4082 struct cmsghdr *header = NULL; 4157 struct cmsghdr *header = NULL;
4083 struct af_alg_iv *alg_iv = NULL; 4158 struct af_alg_iv *alg_iv = NULL;
4084 struct sock_sendmsg ctx; 4159 struct sock_sendmsg ctx;
4085 Py_ssize_t controllen; 4160 Py_ssize_t controllen;
4086 void *controlbuf = NULL; 4161 void *controlbuf = NULL;
4087 static char *keywords[] = {"op", "iv", "assoclen", "flags", 0}; 4162 static char *keywords[] = {"msg", "op", "iv", "assoclen", "flags", 0};
haypo 2016/08/17 13:20:25 Hum, it would be nice to start using Argument Clin
4088 4163
4089 if (self->sock_family != AF_ALG) { 4164 if (self->sock_family != AF_ALG) {
4090 PyErr_SetString(PyExc_OSError, 4165 PyErr_SetString(PyExc_OSError,
4091 "algset is only supported for AF_ALG"); 4166 "algset is only supported for AF_ALG");
4092 return NULL; 4167 return NULL;
4093 } 4168 }
4094 4169
4095 if (!PyArg_ParseTupleAndKeywords(args, kwds, 4170 if (!PyArg_ParseTupleAndKeywords(args, kwds,
4096 "|$iy*ii:socket", keywords, 4171 "|O$O!y*O!i:sendmsg_afalg", keywords,
4097 &type, &iv, &assoclen, &flags)) 4172 &data_arg,
haypo 2016/08/17 13:20:25 I'm a little bit confused. The Python parameter is
4098 return NULL; 4173 &PyLong_Type, &opobj, &iv,
4099 4174 &PyLong_Type, &assoclenobj, &flags))
4100 if (type < 0) { 4175 return NULL;
4176
4177 /* op is a required, keyword-only argument >= 0 */
4178 if (opobj != NULL) {
4179 op = _PyLong_AsInt(opobj);
4180 }
4181 if (op < 0) {
4182 /* override exception from _PyLong_AsInt() */
4101 PyErr_SetString(PyExc_TypeError, 4183 PyErr_SetString(PyExc_TypeError,
4102 "Required argument 'op' (pos 1) not found"); 4184 "Invalid or missing argument 'op'");
haypo 2016/08/17 13:20:25 Hum, the error message can be confusing if you exp
4103 goto finally; 4185 goto finally;
4104 } 4186 }
4105 4187 /* assoclen is optional but must be >= 0 */
4106 memset(&msg, 0, sizeof(msg)); 4188 if (assoclenobj != NULL) {
4189 assoclen = _PyLong_AsInt(assoclenobj);
4190 if (assoclen == -1 && PyErr_Occurred()) {
4191 goto finally;
4192 }
4193 if (assoclen < 0) {
4194 PyErr_SetString(PyExc_TypeError,
4195 "assoclen must be positive");
4196 goto finally;
4197 }
4198 }
4107 4199
4108 controllen = CMSG_SPACE(4); 4200 controllen = CMSG_SPACE(4);
4109 if (iv.buf != NULL) { 4201 if (iv.buf != NULL) {
4110 controllen += CMSG_SPACE(sizeof(*alg_iv) + iv.len); 4202 controllen += CMSG_SPACE(sizeof(*alg_iv) + iv.len);
4111 } 4203 }
4112 if (assoclen >= 0) { 4204 if (assoclen >= 0) {
4113 controllen += CMSG_SPACE(4); 4205 controllen += CMSG_SPACE(4);
4114 } 4206 }
4115 4207
4116 controlbuf = PyMem_Malloc(controllen); 4208 controlbuf = PyMem_Malloc(controllen);
4117 if (controlbuf == NULL) { 4209 if (controlbuf == NULL) {
4118 return PyErr_NoMemory(); 4210 return PyErr_NoMemory();
4119 } 4211 }
4120 memset(controlbuf, 0, controllen); 4212 memset(controlbuf, 0, controllen);
haypo 2016/08/17 13:20:25 FYI there is a PyMem_Calloc() function.
4121 4213
4214 memset(&msg, 0, sizeof(msg));
4122 msg.msg_controllen = controllen; 4215 msg.msg_controllen = controllen;
4123 msg.msg_control = controlbuf; 4216 msg.msg_control = controlbuf;
4217
4218 /* Fill in an iovec for each message part, and save the Py_buffer
4219 structs to release afterwards. */
4220 if (data_arg != NULL) {
4221 if (sock_sendmsg_iovec(self, data_arg, &msg, &databufs, &ndatabufs) == - 1) {
4222 goto finally;
4223 }
4224 }
4124 4225
4125 /* set operation to encrypt or decrypt */ 4226 /* set operation to encrypt or decrypt */
4126 header = CMSG_FIRSTHDR(&msg); 4227 header = CMSG_FIRSTHDR(&msg);
4127 if (header == NULL) { 4228 if (header == NULL) {
4128 PyErr_SetString(PyExc_RuntimeError, 4229 PyErr_SetString(PyExc_RuntimeError,
4129 "unexpected NULL result from CMSG_FIRSTHDR"); 4230 "unexpected NULL result from CMSG_FIRSTHDR");
4130 goto finally; 4231 goto finally;
4131 } 4232 }
4132 header->cmsg_level = SOL_ALG; 4233 header->cmsg_level = SOL_ALG;
4133 header->cmsg_type = ALG_SET_OP; 4234 header->cmsg_type = ALG_SET_OP;
4134 header->cmsg_len = CMSG_LEN(4); 4235 header->cmsg_len = CMSG_LEN(4);
4135 uiptr = (void*)CMSG_DATA(header); 4236 uiptr = (void*)CMSG_DATA(header);
4136 *uiptr = (unsigned int)type; 4237 *uiptr = (unsigned int)op;
4137 4238
4138 /* set initialization vector */ 4239 /* set initialization vector */
4139 if (iv.buf != NULL) { 4240 if (iv.buf != NULL) {
4140 header = CMSG_NXTHDR(&msg, header); 4241 header = CMSG_NXTHDR(&msg, header);
4141 if (header == NULL) { 4242 if (header == NULL) {
4142 PyErr_SetString(PyExc_RuntimeError, 4243 PyErr_SetString(PyExc_RuntimeError,
4143 "unexpected NULL result from CMSG_NXTHDR(iv)"); 4244 "unexpected NULL result from CMSG_NXTHDR(iv)");
4144 goto finally; 4245 goto finally;
4145 } 4246 }
4146 header->cmsg_level = SOL_ALG; 4247 header->cmsg_level = SOL_ALG;
(...skipping 15 matching lines...) Expand all
4162 header->cmsg_level = SOL_ALG; 4263 header->cmsg_level = SOL_ALG;
4163 header->cmsg_type = ALG_SET_AEAD_ASSOCLEN; 4264 header->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
4164 header->cmsg_len = CMSG_LEN(4); 4265 header->cmsg_len = CMSG_LEN(4);
4165 uiptr = (void*)CMSG_DATA(header); 4266 uiptr = (void*)CMSG_DATA(header);
4166 *uiptr = (unsigned int)assoclen; 4267 *uiptr = (unsigned int)assoclen;
4167 } 4268 }
4168 4269
4169 ctx.msg = &msg; 4270 ctx.msg = &msg;
4170 ctx.flags = flags; 4271 ctx.flags = flags;
4171 if (sock_call(self, 1, sock_sendmsg_impl, &ctx) < 0) 4272 if (sock_call(self, 1, sock_sendmsg_impl, &ctx) < 0)
4172 goto finally; 4273 goto finally;
haypo 2016/08/17 13:20:25 nit: PEP 7 now requires { ... } even for single li
4173 4274
4174 retval = PyLong_FromSsize_t(ctx.result); 4275 retval = PyLong_FromSsize_t(ctx.result);
4175 4276
4176 finally: 4277 finally:
4177 if (iv.buf != NULL) 4278 PyMem_Free(controlbuf);
4178 » PyBuffer_Release(&iv); 4279 if (iv.buf != NULL) {
4179 if (controlbuf != NULL) 4280 PyBuffer_Release(&iv);
haypo 2016/08/17 13:20:25 PyMem_Free(NULL) is well defined: it does nothing,
4180 PyMem_Free(controlbuf); 4281 }
4282 for (i = 0; i < ndatabufs; i++)
4283 PyBuffer_Release(&databufs[i]);
4284 PyMem_Free(databufs);
4181 return retval; 4285 return retval;
4182 } 4286 }
4183 4287
4184 PyDoc_STRVAR(algset_doc, 4288 PyDoc_STRVAR(sendmsg_afalg_doc,
4185 "algset(op[, iv[, assoclen[, flags]]])\n\ 4289 "sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags=MSG_MORE]]])\n\
4186 \n\ 4290 \n\
4187 Set operation mode, IV and length of associated data for an AF_ALG\n\ 4291 Set operation mode, IV and length of associated data for an AF_ALG\n\
4188 operation socket."); 4292 operation socket.");
4189 #endif 4293 #endif
4190 4294
4191 /* s.shutdown(how) method */ 4295 /* s.shutdown(how) method */
4192 4296
4193 static PyObject * 4297 static PyObject *
4194 sock_shutdown(PySocketSockObject *s, PyObject *arg) 4298 sock_shutdown(PySocketSockObject *s, PyObject *arg)
4195 { 4299 {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4360 shutdown_doc}, 4464 shutdown_doc},
4361 #ifdef CMSG_LEN 4465 #ifdef CMSG_LEN
4362 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS, 4466 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS,
4363 recvmsg_doc}, 4467 recvmsg_doc},
4364 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS, 4468 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS,
4365 recvmsg_into_doc,}, 4469 recvmsg_into_doc,},
4366 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS, 4470 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS,
4367 sendmsg_doc}, 4471 sendmsg_doc},
4368 #endif 4472 #endif
4369 #ifdef HAVE_SOCKADDR_ALG 4473 #ifdef HAVE_SOCKADDR_ALG
4370 {"algset", (PyCFunction)sock_algset, METH_VARARGS | METH_KEYWORDS , 4474 {"sendmsg_afalg", (PyCFunction)sock_sendmsg_afalg, METH_VARARGS | METH_K EYWORDS,
4371 algset_doc}, 4475 sendmsg_afalg_doc},
4372 #endif 4476 #endif
4373 {NULL, NULL} /* sentinel */ 4477 {NULL, NULL} /* sentinel */
4374 }; 4478 };
4375 4479
4376 /* SockObject members */ 4480 /* SockObject members */
4377 static PyMemberDef sock_memberlist[] = { 4481 static PyMemberDef sock_memberlist[] = {
4378 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"}, 4482 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"},
4379 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"}, 4483 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"},
4380 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"}, 4484 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"},
4381 {0}, 4485 {0},
(...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after
6530 #ifdef NETLINK_ROUTE6 6634 #ifdef NETLINK_ROUTE6
6531 PyModule_AddIntMacro(m, NETLINK_ROUTE6); 6635 PyModule_AddIntMacro(m, NETLINK_ROUTE6);
6532 #endif 6636 #endif
6533 PyModule_AddIntMacro(m, NETLINK_IP6_FW); 6637 PyModule_AddIntMacro(m, NETLINK_IP6_FW);
6534 #ifdef NETLINK_DNRTMSG 6638 #ifdef NETLINK_DNRTMSG
6535 PyModule_AddIntMacro(m, NETLINK_DNRTMSG); 6639 PyModule_AddIntMacro(m, NETLINK_DNRTMSG);
6536 #endif 6640 #endif
6537 #ifdef NETLINK_TAPBASE 6641 #ifdef NETLINK_TAPBASE
6538 PyModule_AddIntMacro(m, NETLINK_TAPBASE); 6642 PyModule_AddIntMacro(m, NETLINK_TAPBASE);
6539 #endif 6643 #endif
6644 #ifdef NETLINK_CRYPTO
6645 PyModule_AddIntMacro(m, NETLINK_CRYPTO);
6646 #endif
6540 #endif /* AF_NETLINK */ 6647 #endif /* AF_NETLINK */
6541 #ifdef AF_ROUTE 6648 #ifdef AF_ROUTE
6542 /* Alias to emulate 4.4BSD */ 6649 /* Alias to emulate 4.4BSD */
6543 PyModule_AddIntMacro(m, AF_ROUTE); 6650 PyModule_AddIntMacro(m, AF_ROUTE);
6544 #endif 6651 #endif
6545 #ifdef AF_LINK 6652 #ifdef AF_LINK
6546 PyModule_AddIntMacro(m, AF_LINK); 6653 PyModule_AddIntMacro(m, AF_LINK);
6547 #endif 6654 #endif
6548 #ifdef AF_ASH 6655 #ifdef AF_ASH
6549 /* Ash */ 6656 /* Ash */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6684 #endif 6791 #endif
6685 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER); 6792 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER);
6686 PyModule_AddIntMacro(m, TIPC_PUBLISHED); 6793 PyModule_AddIntMacro(m, TIPC_PUBLISHED);
6687 PyModule_AddIntMacro(m, TIPC_WITHDRAWN); 6794 PyModule_AddIntMacro(m, TIPC_WITHDRAWN);
6688 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT); 6795 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT);
6689 PyModule_AddIntMacro(m, TIPC_CFG_SRV); 6796 PyModule_AddIntMacro(m, TIPC_CFG_SRV);
6690 PyModule_AddIntMacro(m, TIPC_TOP_SRV); 6797 PyModule_AddIntMacro(m, TIPC_TOP_SRV);
6691 #endif 6798 #endif
6692 6799
6693 #ifdef HAVE_SOCKADDR_ALG 6800 #ifdef HAVE_SOCKADDR_ALG
6694 /* Socket options */ 6801 /* Socket options */
haypo 2016/08/17 13:20:26 indent the comment?
6695 PyModule_AddIntMacro(m, ALG_SET_KEY); 6802 PyModule_AddIntMacro(m, ALG_SET_KEY);
6696 PyModule_AddIntMacro(m, ALG_SET_IV); 6803 PyModule_AddIntMacro(m, ALG_SET_IV);
6697 PyModule_AddIntMacro(m, ALG_SET_OP); 6804 PyModule_AddIntMacro(m, ALG_SET_OP);
6698 PyModule_AddIntMacro(m, ALG_SET_AEAD_ASSOCLEN); 6805 PyModule_AddIntMacro(m, ALG_SET_AEAD_ASSOCLEN);
6699 PyModule_AddIntMacro(m, ALG_SET_AEAD_AUTHSIZE); 6806 PyModule_AddIntMacro(m, ALG_SET_AEAD_AUTHSIZE);
6700 6807 PyModule_AddIntMacro(m, ALG_SET_PUBKEY);
6701 /* Operations */ 6808
6809 /* Operations */
6702 PyModule_AddIntMacro(m, ALG_OP_DECRYPT); 6810 PyModule_AddIntMacro(m, ALG_OP_DECRYPT);
6703 PyModule_AddIntMacro(m, ALG_OP_ENCRYPT); 6811 PyModule_AddIntMacro(m, ALG_OP_ENCRYPT);
6812 PyModule_AddIntMacro(m, ALG_OP_SIGN);
6813 PyModule_AddIntMacro(m, ALG_OP_VERIFY);
6704 #endif 6814 #endif
6705 6815
6706 /* Socket types */ 6816 /* Socket types */
6707 PyModule_AddIntMacro(m, SOCK_STREAM); 6817 PyModule_AddIntMacro(m, SOCK_STREAM);
6708 PyModule_AddIntMacro(m, SOCK_DGRAM); 6818 PyModule_AddIntMacro(m, SOCK_DGRAM);
6709 /* We have incomplete socket support. */ 6819 /* We have incomplete socket support. */
6710 #ifdef SOCK_RAW 6820 #ifdef SOCK_RAW
6711 /* SOCK_RAW is marked as optional in the POSIX specification */ 6821 /* SOCK_RAW is marked as optional in the POSIX specification */
6712 PyModule_AddIntMacro(m, SOCK_RAW); 6822 PyModule_AddIntMacro(m, SOCK_RAW);
6713 #endif 6823 #endif
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
6787 #endif 6897 #endif
6788 #ifdef SO_PASSCRED 6898 #ifdef SO_PASSCRED
6789 PyModule_AddIntMacro(m, SO_PASSCRED); 6899 PyModule_AddIntMacro(m, SO_PASSCRED);
6790 #endif 6900 #endif
6791 #ifdef SO_PEERCRED 6901 #ifdef SO_PEERCRED
6792 PyModule_AddIntMacro(m, SO_PEERCRED); 6902 PyModule_AddIntMacro(m, SO_PEERCRED);
6793 #endif 6903 #endif
6794 #ifdef LOCAL_PEERCRED 6904 #ifdef LOCAL_PEERCRED
6795 PyModule_AddIntMacro(m, LOCAL_PEERCRED); 6905 PyModule_AddIntMacro(m, LOCAL_PEERCRED);
6796 #endif 6906 #endif
6907 #ifdef SO_PASSSEC
6908 PyModule_AddIntMacro(m, SO_PASSSEC);
6909 #endif
6910 #ifdef SO_PEERSEC
6911 PyModule_AddIntMacro(m, SO_PEERSEC);
6912 #endif
6797 #ifdef SO_BINDTODEVICE 6913 #ifdef SO_BINDTODEVICE
6798 PyModule_AddIntMacro(m, SO_BINDTODEVICE); 6914 PyModule_AddIntMacro(m, SO_BINDTODEVICE);
6799 #endif 6915 #endif
6800 #ifdef SO_PRIORITY 6916 #ifdef SO_PRIORITY
6801 PyModule_AddIntMacro(m, SO_PRIORITY); 6917 PyModule_AddIntMacro(m, SO_PRIORITY);
6802 #endif 6918 #endif
6803 #ifdef SO_MARK 6919 #ifdef SO_MARK
6804 PyModule_AddIntMacro(m, SO_MARK); 6920 PyModule_AddIntMacro(m, SO_MARK);
6921 #endif
6922 #ifdef SO_DOMAIN
6923 PyModule_AddIntMacro(m, SO_DOMAIN);
6924 #endif
6925 #ifdef SO_PROTOCOL
6926 PyModule_AddIntMacro(m, SO_PROTOCOL);
6805 #endif 6927 #endif
6806 6928
6807 /* Maximum number of connections for "listen" */ 6929 /* Maximum number of connections for "listen" */
6808 #ifdef SOMAXCONN 6930 #ifdef SOMAXCONN
6809 PyModule_AddIntMacro(m, SOMAXCONN); 6931 PyModule_AddIntMacro(m, SOMAXCONN);
6810 #else 6932 #else
6811 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ 6933 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
6812 #endif 6934 #endif
6813 6935
6814 /* Ancilliary message types */ 6936 /* Ancillary message types */
6815 #ifdef SCM_RIGHTS 6937 #ifdef SCM_RIGHTS
6816 PyModule_AddIntMacro(m, SCM_RIGHTS); 6938 PyModule_AddIntMacro(m, SCM_RIGHTS);
6817 #endif 6939 #endif
6818 #ifdef SCM_CREDENTIALS 6940 #ifdef SCM_CREDENTIALS
6819 PyModule_AddIntMacro(m, SCM_CREDENTIALS); 6941 PyModule_AddIntMacro(m, SCM_CREDENTIALS);
6820 #endif 6942 #endif
6821 #ifdef SCM_CREDS 6943 #ifdef SCM_CREDS
6822 PyModule_AddIntMacro(m, SCM_CREDS); 6944 PyModule_AddIntMacro(m, SCM_CREDS);
6823 #endif 6945 #endif
6824 6946
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
7573 return NULL; 7695 return NULL;
7574 memcpy(&packed_addr, src, sizeof(packed_addr)); 7696 memcpy(&packed_addr, src, sizeof(packed_addr));
7575 return strncpy(dst, inet_ntoa(packed_addr), size); 7697 return strncpy(dst, inet_ntoa(packed_addr), size);
7576 } 7698 }
7577 /* Should set errno to EAFNOSUPPORT */ 7699 /* Should set errno to EAFNOSUPPORT */
7578 return NULL; 7700 return NULL;
7579 } 7701 }
7580 7702
7581 #endif 7703 #endif
7582 #endif 7704 #endif
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+