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

Side by Side Diff: Modules/socketmodule.c

Issue 27744: Add AF_ALG (Linux Kernel crypto) to socket module
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:
View unified diff | Download patch
« Lib/test/test_socket.py ('K') | « Lib/test/test_socket.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 #include <sys/types.h> 278 #include <sys/types.h>
279 #endif 279 #endif
280 280
281 #ifdef HAVE_SYS_SOCKET_H 281 #ifdef HAVE_SYS_SOCKET_H
282 #include <sys/socket.h> 282 #include <sys/socket.h>
283 #endif 283 #endif
284 284
285 #ifdef HAVE_NET_IF_H 285 #ifdef HAVE_NET_IF_H
286 #include <net/if.h> 286 #include <net/if.h>
287 #endif 287 #endif
288
289 #ifdef HAVE_SOCKADDR_ALG
290 #include <linux/if_alg.h>
291 #ifndef AF_ALG
292 #define AF_ALG 38
293 #endif
294 #ifndef SOL_ALG
295 #define SOL_ALG 279
296 #endif
haypo 2016/08/30 16:56:07 I don't understand why you need to define these co
christian.heimes 2016/08/30 17:21:51 It's fine to define missi g constants. For example
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
haypo 2016/08/30 16:56:07 Ditto. I would prefer to only use constants provid
christian.heimes 2016/08/30 17:21:51 AF_ALG is Linux-only. The values are already fixed
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 */
288 318
289 /* Generic socket object definitions and includes */ 319 /* Generic socket object definitions and includes */
290 #define PySocket_BUILDING_SOCKET 320 #define PySocket_BUILDING_SOCKET
291 #include "socketmodule.h" 321 #include "socketmodule.h"
292 322
293 /* Addressing includes */ 323 /* Addressing includes */
294 324
295 #ifndef MS_WINDOWS 325 #ifndef MS_WINDOWS
296 326
297 /* Non-MS WINDOWS includes */ 327 /* Non-MS WINDOWS includes */
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 { 1396 {
1367 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr; 1397 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr;
1368 return Py_BuildValue("(II)", a->sc_id, a->sc_unit); 1398 return Py_BuildValue("(II)", a->sc_id, a->sc_unit);
1369 } 1399 }
1370 #endif 1400 #endif
1371 default: 1401 default:
1372 PyErr_SetString(PyExc_ValueError, 1402 PyErr_SetString(PyExc_ValueError,
1373 "Invalid address type"); 1403 "Invalid address type");
1374 return 0; 1404 return 0;
1375 } 1405 }
1406 #endif
1407
1408 #ifdef HAVE_SOCKADDR_ALG
1409 case AF_ALG:
1410 {
1411 struct sockaddr_alg *a = (struct sockaddr_alg *)addr;
1412 return Py_BuildValue("s#s#HH",
1413 a->salg_type,
1414 strnlen((const char*)a->salg_type,
1415 sizeof(a->salg_type)),
haypo 2016/08/30 16:56:07 Oh, too bad, socketmodule.c still doesn't support
1416 a->salg_name,
1417 strnlen((const char*)a->salg_name,
1418 sizeof(a->salg_name)),
1419 a->salg_feat,
1420 a->salg_mask);
1421 }
1376 #endif 1422 #endif
1377 1423
1378 /* More cases here... */ 1424 /* More cases here... */
1379 1425
1380 default: 1426 default:
1381 /* If we don't know the address family, don't raise an 1427 /* If we don't know the address family, don't raise an
1382 exception -- return it as an (int, bytes) tuple. */ 1428 exception -- return it as an (int, bytes) tuple. */
1383 return Py_BuildValue("iy#", 1429 return Py_BuildValue("iy#",
1384 addr->sa_family, 1430 addr->sa_family,
1385 addr->sa_data, 1431 addr->sa_data,
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1978
1933 *len_ret = sizeof(*addr); 1979 *len_ret = sizeof(*addr);
1934 return 1; 1980 return 1;
1935 } 1981 }
1936 #endif 1982 #endif
1937 default: 1983 default:
1938 PyErr_SetString(PyExc_OSError, 1984 PyErr_SetString(PyExc_OSError,
1939 "getsockaddrarg: unsupported PF_SYSTEM protocol"); 1985 "getsockaddrarg: unsupported PF_SYSTEM protocol");
1940 return 0; 1986 return 0;
1941 } 1987 }
1988 #endif
1989 #ifdef HAVE_SOCKADDR_ALG
1990 case AF_ALG:
1991 {
1992 struct sockaddr_alg *sa;
1993 char *type;
1994 char *name;
1995 sa = (struct sockaddr_alg *)addr_ret;
1996
1997 memset(sa, 0, sizeof(*sa));
1998 sa->salg_family = AF_ALG;
1999
2000 if (!PyArg_ParseTuple(args, "ss|HH:getsockaddrarg",
2001 &type, &name, &sa->salg_feat, &sa->salg_mask))
2002 return 0;
2003 if (strlen(type) > sizeof(sa->salg_type)) {
haypo 2016/08/30 16:56:07 Is it ok to not put a NUL byte at the end?
christian.heimes 2016/08/30 17:21:51 Yes, it's fine. The sockaddr_alg has fixed-size ch
haypo 2016/08/30 17:49:09 Can you please add a comment just saying that? It
christian.heimes 2016/09/04 16:58:44 That makes sense. I've added a comment.
2004 PyErr_SetString(PyExc_ValueError, "AF_ALG type too long.");
2005 return 0;
2006 }
2007 strncpy((char *)sa->salg_type, type, sizeof(sa->salg_type));
2008 if (strlen(name) > sizeof(sa->salg_name)) {
2009 PyErr_SetString(PyExc_ValueError, "AF_ALG name too long.");
2010 return 0;
2011 }
2012 strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
2013
2014 *len_ret = sizeof(*sa);
2015 return 1;
2016 }
1942 #endif 2017 #endif
1943 2018
1944 /* More cases here... */ 2019 /* More cases here... */
1945 2020
1946 default: 2021 default:
1947 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family"); 2022 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family");
1948 return 0; 2023 return 0;
1949 2024
1950 } 2025 }
1951 } 2026 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 #ifdef SYSPROTO_CONTROL 2128 #ifdef SYSPROTO_CONTROL
2054 case SYSPROTO_CONTROL: 2129 case SYSPROTO_CONTROL:
2055 *len_ret = sizeof (struct sockaddr_ctl); 2130 *len_ret = sizeof (struct sockaddr_ctl);
2056 return 1; 2131 return 1;
2057 #endif 2132 #endif
2058 default: 2133 default:
2059 PyErr_SetString(PyExc_OSError, "getsockaddrlen: " 2134 PyErr_SetString(PyExc_OSError, "getsockaddrlen: "
2060 "unknown PF_SYSTEM protocol"); 2135 "unknown PF_SYSTEM protocol");
2061 return 0; 2136 return 0;
2062 } 2137 }
2138 #endif
2139 #ifdef HAVE_SOCKADDR_ALG
2140 case AF_ALG:
2141 {
2142 *len_ret = sizeof (struct sockaddr_alg);
2143 return 1;
2144 }
2063 #endif 2145 #endif
2064 2146
2065 /* More cases here... */ 2147 /* More cases here... */
2066 2148
2067 default: 2149 default:
2068 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family"); 2150 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family");
2069 return 0; 2151 return 0;
2070 2152
2071 } 2153 }
2072 } 2154 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 2295
2214 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2296 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2215 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */ 2297 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */
2216 static int accept4_works = -1; 2298 static int accept4_works = -1;
2217 #endif 2299 #endif
2218 2300
2219 static int 2301 static int
2220 sock_accept_impl(PySocketSockObject *s, void *data) 2302 sock_accept_impl(PySocketSockObject *s, void *data)
2221 { 2303 {
2222 struct sock_accept *ctx = data; 2304 struct sock_accept *ctx = data;
2305 struct sockaddr *addr = SAS2SA(ctx->addrbuf);
2306 socklen_t *addrlen = ctx->addrlen;
haypo 2016/08/30 16:56:07 Hum, would it make sense to rename the variable to
christian.heimes 2016/08/30 17:21:51 Good idea, makes sense!
2307 #ifdef HAVE_SOCKADDR_ALG
2308 /* AF_ALG does not support accept() with addr and raises
2309 * ECONNABORTED instead. */
2310 if (s->sock_family == AF_ALG) {
2311 addr = NULL;
2312 addrlen = NULL;
2313 *ctx->addrlen = 0;
2314 }
2315 #endif
2223 2316
2224 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2317 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2225 if (accept4_works != 0) { 2318 if (accept4_works != 0) {
2226 ctx->result = accept4(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen, 2319 ctx->result = accept4(s->sock_fd, addr, addrlen,
2227 SOCK_CLOEXEC); 2320 SOCK_CLOEXEC);
2228 if (ctx->result == INVALID_SOCKET && accept4_works == -1) { 2321 if (ctx->result == INVALID_SOCKET && accept4_works == -1) {
2229 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */ 2322 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */
2230 accept4_works = (errno != ENOSYS); 2323 accept4_works = (errno != ENOSYS);
2231 } 2324 }
2232 } 2325 }
2233 if (accept4_works == 0) 2326 if (accept4_works == 0)
2234 ctx->result = accept(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen); 2327 ctx->result = accept(s->sock_fd, addr, addrlen);
2235 #else 2328 #else
2236 ctx->result = accept(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen); 2329 ctx->result = accept(s->sock_fd, addr, addrlen);
2237 #endif 2330 #endif
2238 2331
2239 #ifdef MS_WINDOWS 2332 #ifdef MS_WINDOWS
2240 return (ctx->result != INVALID_SOCKET); 2333 return (ctx->result != INVALID_SOCKET);
2241 #else 2334 #else
2242 return (ctx->result >= 0); 2335 return (ctx->result >= 0);
2243 #endif 2336 #endif
2244 } 2337 }
2245 2338
2246 /* s._accept() -> (fd, address) */ 2339 /* s._accept() -> (fd, address) */
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 } 2521 }
2429 2522
2430 PyDoc_STRVAR(gettimeout_doc, 2523 PyDoc_STRVAR(gettimeout_doc,
2431 "gettimeout() -> timeout\n\ 2524 "gettimeout() -> timeout\n\
2432 \n\ 2525 \n\
2433 Returns the timeout in seconds (float) associated with socket \n\ 2526 Returns the timeout in seconds (float) associated with socket \n\
2434 operations. A timeout of None indicates that timeouts on socket \n\ 2527 operations. A timeout of None indicates that timeouts on socket \n\
2435 operations are disabled."); 2528 operations are disabled.");
2436 2529
2437 /* s.setsockopt() method. 2530 /* s.setsockopt() method.
2438 With an integer third argument, sets an integer option. 2531 With an integer third argument, sets an integer optval with optlen=4.
2532 With None as third argument and an integer fourth argument, set
2533 optval=NULL with unsigned int as optlen.
2439 With a string third argument, sets an option from a buffer; 2534 With a string third argument, sets an option from a buffer;
2440 use optional built-in module 'struct' to encode the string. */ 2535 use optional built-in module 'struct' to encode the string.
2536 */
2441 2537
2442 static PyObject * 2538 static PyObject *
2443 sock_setsockopt(PySocketSockObject *s, PyObject *args) 2539 sock_setsockopt(PySocketSockObject *s, PyObject *args)
2444 { 2540 {
2445 int level; 2541 int level;
2446 int optname; 2542 int optname;
2447 int res; 2543 int res;
2448 Py_buffer optval; 2544 Py_buffer optval;
2449 int flag; 2545 int flag;
2546 socklen_t socklen;
haypo 2016/08/30 16:56:07 I suggest the name "optlen" to stay consistent wit
2547 PyObject *none;
2450 2548
2549 /* setsockopt(level, opt, flag) */
2451 if (PyArg_ParseTuple(args, "iii:setsockopt", 2550 if (PyArg_ParseTuple(args, "iii:setsockopt",
2452 &level, &optname, &flag)) { 2551 &level, &optname, &flag)) {
2453 res = setsockopt(s->sock_fd, level, optname, 2552 res = setsockopt(s->sock_fd, level, optname,
2454 (char*)&flag, sizeof flag); 2553 (char*)&flag, sizeof flag);
2554 goto done;
2455 } 2555 }
2456 else { 2556
2457 PyErr_Clear(); 2557 PyErr_Clear();
2458 if (!PyArg_ParseTuple(args, "iiy*:setsockopt", 2558 /* setsockopt(level, opt, (None, flag)) */
haypo 2016/08/30 16:56:07 The comment is outdated, no? It's now: /* setsoc
2459 &level, &optname, &optval)) 2559 if (PyArg_ParseTuple(args, "iiO!I:setsockopt",
2460 return NULL; 2560 &level, &optname, Py_TYPE(Py_None), &none, &socklen)) {
haypo 2016/08/30 16:56:07 Hum, I'm not confortable with passing a socklen_t*
christian.heimes 2016/08/30 17:21:51 socklen_t is an unsigned int. Let's keep it simple
haypo 2016/08/30 17:49:09 Please add at least the following assertion before
christian.heimes 2016/09/04 16:58:44 I have added the assertion assert(sizeof(socklen_t
2561 res = setsockopt(s->sock_fd, level, optname,
2562 NULL, socklen);
2563 goto done;
2564 }
2565
2566 PyErr_Clear();
2567 /* setsockopt(level, opt, buffer) */
2568 if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
2569 &level, &optname, &optval))
2570 return NULL;
2571
2461 #ifdef MS_WINDOWS 2572 #ifdef MS_WINDOWS
2462 if (optval.len > INT_MAX) { 2573 if (optval.len > INT_MAX) {
2463 PyBuffer_Release(&optval); 2574 PyBuffer_Release(&optval);
2464 PyErr_Format(PyExc_OverflowError, 2575 PyErr_Format(PyExc_OverflowError,
2465 "socket option is larger than %i bytes", 2576 "socket option is larger than %i bytes",
2466 INT_MAX); 2577 INT_MAX);
2467 return NULL; 2578 return NULL;
2468 } 2579 }
2469 res = setsockopt(s->sock_fd, level, optname, 2580 res = setsockopt(s->sock_fd, level, optname,
2470 optval.buf, (int)optval.len); 2581 optval.buf, (int)optval.len);
2471 #else 2582 #else
2472 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len); 2583 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
2473 #endif 2584 #endif
2474 PyBuffer_Release(&optval); 2585 PyBuffer_Release(&optval);
2475 } 2586
2587 done:
2476 if (res < 0) { 2588 if (res < 0) {
2477 return s->errorhandler(); 2589 return s->errorhandler();
2478 } 2590 }
2479 2591
2480 Py_RETURN_NONE; 2592 Py_RETURN_NONE;
2481 } 2593 }
2482 2594
2483 PyDoc_STRVAR(setsockopt_doc, 2595 PyDoc_STRVAR(setsockopt_doc,
2484 "setsockopt(level, option, value)\n\ 2596 "setsockopt(level, option, value: int)\n\
2597 setsockopt(level, option, value: buffer)\n\
2598 setsockopt(level, option, None, optlen: int)\n\
2485 \n\ 2599 \n\
2486 Set a socket option. See the Unix manual for level and option.\n\ 2600 Set a socket option. See the Unix manual for level and option.\n\
2487 The value argument can either be an integer or a string."); 2601 The value argument can either be an integer, a string buffer, or \n\
2602 None, optlen.");
2488 2603
2489 2604
2490 /* s.getsockopt() method. 2605 /* s.getsockopt() method.
2491 With two arguments, retrieves an integer option. 2606 With two arguments, retrieves an integer option.
2492 With a third integer argument, retrieves a string buffer of that size; 2607 With a third integer argument, retrieves a string buffer of that size;
2493 use optional built-in module 'struct' to decode the string. */ 2608 use optional built-in module 'struct' to decode the string. */
2494 2609
2495 static PyObject * 2610 static PyObject *
2496 sock_getsockopt(PySocketSockObject *s, PyObject *args) 2611 sock_getsockopt(PySocketSockObject *s, PyObject *args)
2497 { 2612 {
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 3880
3766 3881
3767 /* The sendmsg() and recvmsg[_into]() methods require a working 3882 /* The sendmsg() and recvmsg[_into]() methods require a working
3768 CMSG_LEN(). See the comment near get_CMSG_LEN(). */ 3883 CMSG_LEN(). See the comment near get_CMSG_LEN(). */
3769 #ifdef CMSG_LEN 3884 #ifdef CMSG_LEN
3770 struct sock_sendmsg { 3885 struct sock_sendmsg {
3771 struct msghdr *msg; 3886 struct msghdr *msg;
3772 int flags; 3887 int flags;
3773 ssize_t result; 3888 ssize_t result;
3774 }; 3889 };
3890
3891 static int
3892 sock_sendmsg_iovec(PySocketSockObject *s, PyObject *data_arg,
3893 struct msghdr *msg,
3894 Py_buffer **databufsout, Py_ssize_t *ndatabufsout) {
3895 Py_ssize_t ndataparts, ndatabufs = 0;
3896 int result = -1;
3897 struct iovec *iovs = NULL;
3898 PyObject *data_fast = NULL;
3899 Py_buffer *databufs = NULL;
3900
3901 /* Fill in an iovec for each message part, and save the Py_buffer
3902 structs to release afterwards. */
3903 if ((data_fast = PySequence_Fast(data_arg,
3904 "sendmsg() argument 1 must be an "
3905 "iterable")) == NULL)
3906 goto finally;
3907 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3908 if (ndataparts > INT_MAX) {
3909 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3910 goto finally;
3911 }
3912 msg->msg_iovlen = ndataparts;
3913 if (ndataparts > 0 &&
3914 ((msg->msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3915 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3916 PyErr_NoMemory();
3917 goto finally;
3918 }
3919 for (; ndatabufs < ndataparts; ndatabufs++) {
3920 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3921 "y*;sendmsg() argument 1 must be an iterable of "
3922 "bytes-like objects",
3923 &databufs[ndatabufs]))
3924 goto finally;
3925 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3926 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3927 }
3928 result = 0;
3929 finally:
3930 *databufsout = databufs;
3931 *ndatabufsout = ndatabufs;
3932 Py_XDECREF(data_fast);
3933 return result;
3934 }
3775 3935
3776 static int 3936 static int
3777 sock_sendmsg_impl(PySocketSockObject *s, void *data) 3937 sock_sendmsg_impl(PySocketSockObject *s, void *data)
3778 { 3938 {
3779 struct sock_sendmsg *ctx = data; 3939 struct sock_sendmsg *ctx = data;
3780 3940
3781 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags); 3941 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags);
3782 return (ctx->result >= 0); 3942 return (ctx->result >= 0);
3783 } 3943 }
3784 3944
3785 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */ 3945 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */
3786 3946
3787 static PyObject * 3947 static PyObject *
3788 sock_sendmsg(PySocketSockObject *s, PyObject *args) 3948 sock_sendmsg(PySocketSockObject *s, PyObject *args)
3789 { 3949 {
3790 Py_ssize_t i, ndataparts, ndatabufs = 0, ncmsgs, ncmsgbufs = 0; 3950 Py_ssize_t i, ndatabufs = 0, ncmsgs, ncmsgbufs = 0;
3791 Py_buffer *databufs = NULL; 3951 Py_buffer *databufs = NULL;
3792 struct iovec *iovs = NULL;
3793 sock_addr_t addrbuf; 3952 sock_addr_t addrbuf;
3794 struct msghdr msg = {0}; 3953 struct msghdr msg = {0};
3795 struct cmsginfo { 3954 struct cmsginfo {
3796 int level; 3955 int level;
3797 int type; 3956 int type;
3798 Py_buffer data; 3957 Py_buffer data;
3799 } *cmsgs = NULL; 3958 } *cmsgs = NULL;
3800 void *controlbuf = NULL; 3959 void *controlbuf = NULL;
3801 size_t controllen, controllen_last; 3960 size_t controllen, controllen_last;
3802 int addrlen, flags = 0; 3961 int addrlen, flags = 0;
3803 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL, *data_fast = NULL, 3962 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL,
3804 *cmsg_fast = NULL, *retval = NULL; 3963 *cmsg_fast = NULL, *retval = NULL;
3805 struct sock_sendmsg ctx; 3964 struct sock_sendmsg ctx;
3806 3965
3807 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg", 3966 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg",
3808 &data_arg, &cmsg_arg, &flags, &addr_arg)) 3967 &data_arg, &cmsg_arg, &flags, &addr_arg))
3809 return NULL; 3968 return NULL;
3810 3969
3811 /* Parse destination address. */ 3970 /* Parse destination address. */
3812 if (addr_arg != NULL && addr_arg != Py_None) { 3971 if (addr_arg != NULL && addr_arg != Py_None) {
3813 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen)) 3972 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen))
3814 goto finally; 3973 goto finally;
3815 msg.msg_name = &addrbuf; 3974 msg.msg_name = &addrbuf;
3816 msg.msg_namelen = addrlen; 3975 msg.msg_namelen = addrlen;
3817 } 3976 }
3818 3977
3819 /* Fill in an iovec for each message part, and save the Py_buffer 3978 /* Fill in an iovec for each message part, and save the Py_buffer
3820 structs to release afterwards. */ 3979 structs to release afterwards. */
3821 if ((data_fast = PySequence_Fast(data_arg, 3980 if (sock_sendmsg_iovec(s, data_arg, &msg, &databufs, &ndatabufs) == -1) {
3822 "sendmsg() argument 1 must be an "
3823 "iterable")) == NULL)
3824 goto finally; 3981 goto finally;
3825 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3826 if (ndataparts > INT_MAX) {
3827 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3828 goto finally;
3829 }
3830 msg.msg_iovlen = ndataparts;
3831 if (ndataparts > 0 &&
3832 ((msg.msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3833 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3834 PyErr_NoMemory();
3835 goto finally;
3836 }
3837 for (; ndatabufs < ndataparts; ndatabufs++) {
3838 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3839 "y*;sendmsg() argument 1 must be an iterable of "
3840 "bytes-like objects",
3841 &databufs[ndatabufs]))
3842 goto finally;
3843 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3844 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3845 } 3982 }
3846 3983
3847 if (cmsg_arg == NULL) 3984 if (cmsg_arg == NULL)
3848 ncmsgs = 0; 3985 ncmsgs = 0;
3849 else { 3986 else {
3850 if ((cmsg_fast = PySequence_Fast(cmsg_arg, 3987 if ((cmsg_fast = PySequence_Fast(cmsg_arg,
3851 "sendmsg() argument 2 must be an " 3988 "sendmsg() argument 2 must be an "
3852 "iterable")) == NULL) 3989 "iterable")) == NULL)
3853 goto finally; 3990 goto finally;
3854 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast); 3991 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 4102
3966 finally: 4103 finally:
3967 PyMem_Free(controlbuf); 4104 PyMem_Free(controlbuf);
3968 for (i = 0; i < ncmsgbufs; i++) 4105 for (i = 0; i < ncmsgbufs; i++)
3969 PyBuffer_Release(&cmsgs[i].data); 4106 PyBuffer_Release(&cmsgs[i].data);
3970 PyMem_Free(cmsgs); 4107 PyMem_Free(cmsgs);
3971 Py_XDECREF(cmsg_fast); 4108 Py_XDECREF(cmsg_fast);
3972 for (i = 0; i < ndatabufs; i++) 4109 for (i = 0; i < ndatabufs; i++)
3973 PyBuffer_Release(&databufs[i]); 4110 PyBuffer_Release(&databufs[i]);
3974 PyMem_Free(databufs); 4111 PyMem_Free(databufs);
3975 PyMem_Free(iovs);
3976 Py_XDECREF(data_fast);
3977 return retval; 4112 return retval;
3978 } 4113 }
3979 4114
3980 PyDoc_STRVAR(sendmsg_doc, 4115 PyDoc_STRVAR(sendmsg_doc,
3981 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\ 4116 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\
3982 \n\ 4117 \n\
3983 Send normal and ancillary data to the socket, gathering the\n\ 4118 Send normal and ancillary data to the socket, gathering the\n\
3984 non-ancillary data from a series of buffers and concatenating it into\n\ 4119 non-ancillary data from a series of buffers and concatenating it into\n\
3985 a single message. The buffers argument specifies the non-ancillary\n\ 4120 a single message. The buffers argument specifies the non-ancillary\n\
3986 data as an iterable of bytes-like objects (e.g. bytes objects).\n\ 4121 data as an iterable of bytes-like objects (e.g. bytes objects).\n\
3987 The ancdata argument specifies the ancillary data (control messages)\n\ 4122 The ancdata argument specifies the ancillary data (control messages)\n\
3988 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\ 4123 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\
3989 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\ 4124 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\
3990 protocol level and protocol-specific type respectively, and cmsg_data\n\ 4125 protocol level and protocol-specific type respectively, and cmsg_data\n\
3991 is a bytes-like object holding the associated data. The flags\n\ 4126 is a bytes-like object holding the associated data. The flags\n\
3992 argument defaults to 0 and has the same meaning as for send(). If\n\ 4127 argument defaults to 0 and has the same meaning as for send(). If\n\
3993 address is supplied and not None, it sets a destination address for\n\ 4128 address is supplied and not None, it sets a destination address for\n\
3994 the message. The return value is the number of bytes of non-ancillary\n\ 4129 the message. The return value is the number of bytes of non-ancillary\n\
3995 data sent."); 4130 data sent.");
3996 #endif /* CMSG_LEN */ 4131 #endif /* CMSG_LEN */
3997 4132
4133 #ifdef HAVE_SOCKADDR_ALG
4134 static PyObject*
4135 sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds)
haypo 2016/08/30 16:56:07 I suggest to rename the method: socket.sendmsg_alg
christian.heimes 2016/08/30 17:21:51 I prefer sendmsg_afalg(). It makes it clear that i
4136 {
4137 PyObject *retval = NULL;
4138
4139 Py_ssize_t i, ndatabufs = 0;
4140 Py_buffer *databufs = NULL;
4141 PyObject *data_arg = NULL;
4142
4143 Py_buffer iv = {NULL, NULL};
4144
4145 PyObject *opobj = NULL;
4146 int op = -1;
4147
4148 PyObject *assoclenobj = NULL;
4149 int assoclen = -1;
4150
4151 unsigned int *uiptr;
4152 int flags = 0;
4153
4154 struct msghdr msg;
4155 struct cmsghdr *header = NULL;
4156 struct af_alg_iv *alg_iv = NULL;
4157 struct sock_sendmsg ctx;
4158 Py_ssize_t controllen;
4159 void *controlbuf = NULL;
4160 static char *keywords[] = {"msg", "op", "iv", "assoclen", "flags", 0};
4161
4162 if (self->sock_family != AF_ALG) {
4163 PyErr_SetString(PyExc_OSError,
4164 "algset is only supported for AF_ALG");
4165 return NULL;
4166 }
4167
4168 if (!PyArg_ParseTupleAndKeywords(args, kwds,
4169 "|O$O!y*O!i:sendmsg_afalg", keywords,
4170 &data_arg,
4171 &PyLong_Type, &opobj, &iv,
4172 &PyLong_Type, &assoclenobj, &flags))
4173 return NULL;
4174
4175 /* op is a required, keyword-only argument >= 0 */
4176 if (opobj != NULL) {
4177 op = _PyLong_AsInt(opobj);
haypo 2016/08/30 16:56:07 You may check for integer overflow here as you did
christian.heimes 2016/08/30 17:21:51 The check on 4179 checks for overflow error. The e
4178 }
4179 if (op < 0) {
4180 /* override exception from _PyLong_AsInt() */
4181 PyErr_SetString(PyExc_TypeError,
4182 "Invalid or missing argument 'op'");
4183 goto finally;
4184 }
4185 /* assoclen is optional but must be >= 0 */
4186 if (assoclenobj != NULL) {
4187 assoclen = _PyLong_AsInt(assoclenobj);
4188 if (assoclen == -1 && PyErr_Occurred()) {
4189 goto finally;
4190 }
4191 if (assoclen < 0) {
4192 PyErr_SetString(PyExc_TypeError,
4193 "assoclen must be positive");
4194 goto finally;
4195 }
4196 }
4197
4198 controllen = CMSG_SPACE(4);
4199 if (iv.buf != NULL) {
4200 controllen += CMSG_SPACE(sizeof(*alg_iv) + iv.len);
4201 }
4202 if (assoclen >= 0) {
4203 controllen += CMSG_SPACE(4);
4204 }
4205
4206 controlbuf = PyMem_Malloc(controllen);
4207 if (controlbuf == NULL) {
4208 return PyErr_NoMemory();
4209 }
4210 memset(controlbuf, 0, controllen);
4211
4212 memset(&msg, 0, sizeof(msg));
4213 msg.msg_controllen = controllen;
4214 msg.msg_control = controlbuf;
4215
4216 /* Fill in an iovec for each message part, and save the Py_buffer
4217 structs to release afterwards. */
4218 if (data_arg != NULL) {
4219 if (sock_sendmsg_iovec(self, data_arg, &msg, &databufs, &ndatabufs) == - 1) {
4220 goto finally;
4221 }
4222 }
4223
4224 /* set operation to encrypt or decrypt */
4225 header = CMSG_FIRSTHDR(&msg);
4226 if (header == NULL) {
4227 PyErr_SetString(PyExc_RuntimeError,
4228 "unexpected NULL result from CMSG_FIRSTHDR");
4229 goto finally;
4230 }
4231 header->cmsg_level = SOL_ALG;
4232 header->cmsg_type = ALG_SET_OP;
4233 header->cmsg_len = CMSG_LEN(4);
4234 uiptr = (void*)CMSG_DATA(header);
4235 *uiptr = (unsigned int)op;
4236
4237 /* set initialization vector */
4238 if (iv.buf != NULL) {
4239 header = CMSG_NXTHDR(&msg, header);
4240 if (header == NULL) {
4241 PyErr_SetString(PyExc_RuntimeError,
4242 "unexpected NULL result from CMSG_NXTHDR(iv)");
4243 goto finally;
4244 }
4245 header->cmsg_level = SOL_ALG;
4246 header->cmsg_type = ALG_SET_IV;
4247 header->cmsg_len = CMSG_SPACE(sizeof(*alg_iv) + iv.len);
4248 alg_iv = (void*)CMSG_DATA(header);
4249 alg_iv->ivlen = iv.len;
4250 memcpy(alg_iv->iv, iv.buf, iv.len);
4251 }
4252
4253 /* set length of associated data for AEAD */
4254 if (assoclen >= 0) {
4255 header = CMSG_NXTHDR(&msg, header);
4256 if (header == NULL) {
4257 PyErr_SetString(PyExc_RuntimeError,
4258 "unexpected NULL result from CMSG_NXTHDR(assoc)");
4259 goto finally;
4260 }
4261 header->cmsg_level = SOL_ALG;
4262 header->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
4263 header->cmsg_len = CMSG_LEN(4);
4264 uiptr = (void*)CMSG_DATA(header);
4265 *uiptr = (unsigned int)assoclen;
4266 }
4267
4268 ctx.msg = &msg;
4269 ctx.flags = flags;
4270 if (sock_call(self, 1, sock_sendmsg_impl, &ctx) < 0)
4271 goto finally;
4272
4273 retval = PyLong_FromSsize_t(ctx.result);
4274
4275 finally:
4276 PyMem_Free(controlbuf);
4277 if (iv.buf != NULL) {
4278 PyBuffer_Release(&iv);
4279 }
4280 for (i = 0; i < ndatabufs; i++)
4281 PyBuffer_Release(&databufs[i]);
4282 PyMem_Free(databufs);
4283 return retval;
4284 }
4285
4286 PyDoc_STRVAR(sendmsg_afalg_doc,
4287 "sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags=MSG_MORE]]])\n\
4288 \n\
4289 Set operation mode, IV and length of associated data for an AF_ALG\n\
4290 operation socket.");
4291 #endif
3998 4292
3999 /* s.shutdown(how) method */ 4293 /* s.shutdown(how) method */
4000 4294
4001 static PyObject * 4295 static PyObject *
4002 sock_shutdown(PySocketSockObject *s, PyObject *arg) 4296 sock_shutdown(PySocketSockObject *s, PyObject *arg)
4003 { 4297 {
4004 int how; 4298 int how;
4005 int res; 4299 int res;
4006 4300
4007 how = _PyLong_AsInt(arg); 4301 how = _PyLong_AsInt(arg);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 setsockopt_doc}, 4460 setsockopt_doc},
4167 {"shutdown", (PyCFunction)sock_shutdown, METH_O, 4461 {"shutdown", (PyCFunction)sock_shutdown, METH_O,
4168 shutdown_doc}, 4462 shutdown_doc},
4169 #ifdef CMSG_LEN 4463 #ifdef CMSG_LEN
4170 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS, 4464 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS,
4171 recvmsg_doc}, 4465 recvmsg_doc},
4172 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS, 4466 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS,
4173 recvmsg_into_doc,}, 4467 recvmsg_into_doc,},
4174 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS, 4468 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS,
4175 sendmsg_doc}, 4469 sendmsg_doc},
4470 #endif
4471 #ifdef HAVE_SOCKADDR_ALG
4472 {"sendmsg_afalg", (PyCFunction)sock_sendmsg_afalg, METH_VARARGS | METH_K EYWORDS,
4473 sendmsg_afalg_doc},
4176 #endif 4474 #endif
4177 {NULL, NULL} /* sentinel */ 4475 {NULL, NULL} /* sentinel */
4178 }; 4476 };
4179 4477
4180 /* SockObject members */ 4478 /* SockObject members */
4181 static PyMemberDef sock_memberlist[] = { 4479 static PyMemberDef sock_memberlist[] = {
4182 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"}, 4480 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"},
4183 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"}, 4481 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"},
4184 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"}, 4482 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"},
4185 {0}, 4483 {0},
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after
6269 /* Multiprotocol bridge */ 6567 /* Multiprotocol bridge */
6270 PyModule_AddIntMacro(m, AF_BRIDGE); 6568 PyModule_AddIntMacro(m, AF_BRIDGE);
6271 #endif 6569 #endif
6272 #ifdef AF_ATMPVC 6570 #ifdef AF_ATMPVC
6273 /* ATM PVCs */ 6571 /* ATM PVCs */
6274 PyModule_AddIntMacro(m, AF_ATMPVC); 6572 PyModule_AddIntMacro(m, AF_ATMPVC);
6275 #endif 6573 #endif
6276 #ifdef AF_AAL5 6574 #ifdef AF_AAL5
6277 /* Reserved for Werner's ATM */ 6575 /* Reserved for Werner's ATM */
6278 PyModule_AddIntMacro(m, AF_AAL5); 6576 PyModule_AddIntMacro(m, AF_AAL5);
6577 #endif
6578 #ifdef HAVE_SOCKADDR_ALG
6579 PyModule_AddIntMacro(m, AF_ALG); /* Linux crypto */
6279 #endif 6580 #endif
6280 #ifdef AF_X25 6581 #ifdef AF_X25
6281 /* Reserved for X.25 project */ 6582 /* Reserved for X.25 project */
6282 PyModule_AddIntMacro(m, AF_X25); 6583 PyModule_AddIntMacro(m, AF_X25);
6283 #endif 6584 #endif
6284 #ifdef AF_INET6 6585 #ifdef AF_INET6
6285 PyModule_AddIntMacro(m, AF_INET6); /* IP version 6 */ 6586 PyModule_AddIntMacro(m, AF_INET6); /* IP version 6 */
6286 #endif 6587 #endif
6287 #ifdef AF_ROSE 6588 #ifdef AF_ROSE
6288 /* Amateur Radio X.25 PLP */ 6589 /* Amateur Radio X.25 PLP */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6330 #endif 6631 #endif
6331 #ifdef NETLINK_ROUTE6 6632 #ifdef NETLINK_ROUTE6
6332 PyModule_AddIntMacro(m, NETLINK_ROUTE6); 6633 PyModule_AddIntMacro(m, NETLINK_ROUTE6);
6333 #endif 6634 #endif
6334 PyModule_AddIntMacro(m, NETLINK_IP6_FW); 6635 PyModule_AddIntMacro(m, NETLINK_IP6_FW);
6335 #ifdef NETLINK_DNRTMSG 6636 #ifdef NETLINK_DNRTMSG
6336 PyModule_AddIntMacro(m, NETLINK_DNRTMSG); 6637 PyModule_AddIntMacro(m, NETLINK_DNRTMSG);
6337 #endif 6638 #endif
6338 #ifdef NETLINK_TAPBASE 6639 #ifdef NETLINK_TAPBASE
6339 PyModule_AddIntMacro(m, NETLINK_TAPBASE); 6640 PyModule_AddIntMacro(m, NETLINK_TAPBASE);
6641 #endif
6642 #ifdef NETLINK_CRYPTO
6643 PyModule_AddIntMacro(m, NETLINK_CRYPTO);
6340 #endif 6644 #endif
6341 #endif /* AF_NETLINK */ 6645 #endif /* AF_NETLINK */
6342 #ifdef AF_ROUTE 6646 #ifdef AF_ROUTE
6343 /* Alias to emulate 4.4BSD */ 6647 /* Alias to emulate 4.4BSD */
6344 PyModule_AddIntMacro(m, AF_ROUTE); 6648 PyModule_AddIntMacro(m, AF_ROUTE);
6345 #endif 6649 #endif
6346 #ifdef AF_LINK 6650 #ifdef AF_LINK
6347 PyModule_AddIntMacro(m, AF_LINK); 6651 PyModule_AddIntMacro(m, AF_LINK);
6348 #endif 6652 #endif
6349 #ifdef AF_ASH 6653 #ifdef AF_ASH
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6482 #ifdef TIPC_SUB_CANCEL 6786 #ifdef TIPC_SUB_CANCEL
6483 /* doesn't seem to be available everywhere */ 6787 /* doesn't seem to be available everywhere */
6484 PyModule_AddIntMacro(m, TIPC_SUB_CANCEL); 6788 PyModule_AddIntMacro(m, TIPC_SUB_CANCEL);
6485 #endif 6789 #endif
6486 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER); 6790 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER);
6487 PyModule_AddIntMacro(m, TIPC_PUBLISHED); 6791 PyModule_AddIntMacro(m, TIPC_PUBLISHED);
6488 PyModule_AddIntMacro(m, TIPC_WITHDRAWN); 6792 PyModule_AddIntMacro(m, TIPC_WITHDRAWN);
6489 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT); 6793 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT);
6490 PyModule_AddIntMacro(m, TIPC_CFG_SRV); 6794 PyModule_AddIntMacro(m, TIPC_CFG_SRV);
6491 PyModule_AddIntMacro(m, TIPC_TOP_SRV); 6795 PyModule_AddIntMacro(m, TIPC_TOP_SRV);
6796 #endif
6797
6798 #ifdef HAVE_SOCKADDR_ALG
6799 /* Socket options */
6800 PyModule_AddIntMacro(m, ALG_SET_KEY);
6801 PyModule_AddIntMacro(m, ALG_SET_IV);
6802 PyModule_AddIntMacro(m, ALG_SET_OP);
6803 PyModule_AddIntMacro(m, ALG_SET_AEAD_ASSOCLEN);
6804 PyModule_AddIntMacro(m, ALG_SET_AEAD_AUTHSIZE);
6805 PyModule_AddIntMacro(m, ALG_SET_PUBKEY);
6806
6807 /* Operations */
6808 PyModule_AddIntMacro(m, ALG_OP_DECRYPT);
6809 PyModule_AddIntMacro(m, ALG_OP_ENCRYPT);
6810 PyModule_AddIntMacro(m, ALG_OP_SIGN);
6811 PyModule_AddIntMacro(m, ALG_OP_VERIFY);
6492 #endif 6812 #endif
6493 6813
6494 /* Socket types */ 6814 /* Socket types */
6495 PyModule_AddIntMacro(m, SOCK_STREAM); 6815 PyModule_AddIntMacro(m, SOCK_STREAM);
6496 PyModule_AddIntMacro(m, SOCK_DGRAM); 6816 PyModule_AddIntMacro(m, SOCK_DGRAM);
6497 /* We have incomplete socket support. */ 6817 /* We have incomplete socket support. */
6498 #ifdef SOCK_RAW 6818 #ifdef SOCK_RAW
6499 /* SOCK_RAW is marked as optional in the POSIX specification */ 6819 /* SOCK_RAW is marked as optional in the POSIX specification */
6500 PyModule_AddIntMacro(m, SOCK_RAW); 6820 PyModule_AddIntMacro(m, SOCK_RAW);
6501 #endif 6821 #endif
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
6753 PyModule_AddIntConstant(m, "CAN_BCM_RX_DELETE", RX_DELETE); 7073 PyModule_AddIntConstant(m, "CAN_BCM_RX_DELETE", RX_DELETE);
6754 PyModule_AddIntConstant(m, "CAN_BCM_RX_READ", RX_READ); 7074 PyModule_AddIntConstant(m, "CAN_BCM_RX_READ", RX_READ);
6755 PyModule_AddIntConstant(m, "CAN_BCM_TX_STATUS", TX_STATUS); 7075 PyModule_AddIntConstant(m, "CAN_BCM_TX_STATUS", TX_STATUS);
6756 PyModule_AddIntConstant(m, "CAN_BCM_TX_EXPIRED", TX_EXPIRED); 7076 PyModule_AddIntConstant(m, "CAN_BCM_TX_EXPIRED", TX_EXPIRED);
6757 PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS); 7077 PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS);
6758 PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT); 7078 PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT);
6759 PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED); 7079 PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED);
6760 #endif 7080 #endif
6761 #ifdef SOL_RDS 7081 #ifdef SOL_RDS
6762 PyModule_AddIntMacro(m, SOL_RDS); 7082 PyModule_AddIntMacro(m, SOL_RDS);
7083 #endif
7084 #ifdef HAVE_SOCKADDR_ALG
7085 PyModule_AddIntMacro(m, SOL_ALG);
6763 #endif 7086 #endif
6764 #ifdef RDS_CANCEL_SENT_TO 7087 #ifdef RDS_CANCEL_SENT_TO
6765 PyModule_AddIntMacro(m, RDS_CANCEL_SENT_TO); 7088 PyModule_AddIntMacro(m, RDS_CANCEL_SENT_TO);
6766 #endif 7089 #endif
6767 #ifdef RDS_GET_MR 7090 #ifdef RDS_GET_MR
6768 PyModule_AddIntMacro(m, RDS_GET_MR); 7091 PyModule_AddIntMacro(m, RDS_GET_MR);
6769 #endif 7092 #endif
6770 #ifdef RDS_FREE_MR 7093 #ifdef RDS_FREE_MR
6771 PyModule_AddIntMacro(m, RDS_FREE_MR); 7094 PyModule_AddIntMacro(m, RDS_FREE_MR);
6772 #endif 7095 #endif
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
7370 return NULL; 7693 return NULL;
7371 memcpy(&packed_addr, src, sizeof(packed_addr)); 7694 memcpy(&packed_addr, src, sizeof(packed_addr));
7372 return strncpy(dst, inet_ntoa(packed_addr), size); 7695 return strncpy(dst, inet_ntoa(packed_addr), size);
7373 } 7696 }
7374 /* Should set errno to EAFNOSUPPORT */ 7697 /* Should set errno to EAFNOSUPPORT */
7375 return NULL; 7698 return NULL;
7376 } 7699 }
7377 7700
7378 #endif 7701 #endif
7379 #endif 7702 #endif
OLDNEW
« Lib/test/test_socket.py ('K') | « Lib/test/test_socket.py ('k') | no next file » | no next file with comments »

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