Mailing List Archive

Some more constants for the socket module
Following the recent discussion on c.l.p about socket options,
I found that the socket module does not define all constants
defined in the (Linux) socket header file.

Below is a patch that adds a few more (note that the SOL_*
constants should be used for the setsockopt() level, not the
IPPROTO_* constants).


--- socketmodule.c~ Sat Aug 7 17:56:05 1999
+++ socketmodule.c Sat Aug 7 18:10:07 1999
@@ -2005,14 +2005,48 @@ initsocket()
PySocketSock_Type.tp_doc = sockettype_doc;
Py_INCREF(&PySocketSock_Type);
if (PyDict_SetItemString(d, "SocketType",
(PyObject *)&PySocketSock_Type) != 0)
return;
+
+ /* Address families (we only support AF_INET and AF_UNIX) */
+#ifdef AF_UNSPEC
+ insint(moddict, "AF_UNSPEC", AF_UNSPEC);
+#endif
insint(d, "AF_INET", AF_INET);
#ifdef AF_UNIX
insint(d, "AF_UNIX", AF_UNIX);
#endif /* AF_UNIX */
+#ifdef AF_AX25
+ insint(moddict, "AF_AX25", AF_AX25); /* Amateur Radio AX.25 */
+#endif
+#ifdef AF_IPX
+ insint(moddict, "AF_IPX", AF_IPX); /* Novell IPX */
+#endif
+#ifdef AF_APPLETALK
+ insint(moddict, "AF_APPLETALK", AF_APPLETALK); /* Appletalk DDP */
+#endif
+#ifdef AF_NETROM
+ insint(moddict, "AF_NETROM", AF_NETROM); /* Amateur radio NetROM */
+#endif
+#ifdef AF_BRIDGE
+ insint(moddict, "AF_BRIDGE", AF_BRIDGE); /* Multiprotocol bridge */
+#endif
+#ifdef AF_AAL5
+ insint(moddict, "AF_AAL5", AF_AAL5); /* Reserved for Werner's ATM */
+#endif
+#ifdef AF_X25
+ insint(moddict, "AF_X25", AF_X25); /* Reserved for X.25 project */
+#endif
+#ifdef AF_INET6
+ insint(moddict, "AF_INET6", AF_INET6); /* IP version 6 */
+#endif
+#ifdef AF_ROSE
+ insint(moddict, "AF_ROSE", AF_ROSE); /* Amateur Radio X.25 PLP */
+#endif
+
+ /* Socket types */
insint(d, "SOCK_STREAM", SOCK_STREAM);
insint(d, "SOCK_DGRAM", SOCK_DGRAM);
#ifndef __BEOS__
/* We have incomplete socket support. */
insint(d, "SOCK_RAW", SOCK_RAW);
@@ -2048,11 +2082,10 @@ initsocket()
insint(d, "SO_OOBINLINE", SO_OOBINLINE);
#endif
#ifdef SO_REUSEPORT
insint(d, "SO_REUSEPORT", SO_REUSEPORT);
#endif
-
#ifdef SO_SNDBUF
insint(d, "SO_SNDBUF", SO_SNDBUF);
#endif
#ifdef SO_RCVBUF
insint(d, "SO_RCVBUF", SO_RCVBUF);
@@ -2111,14 +2144,43 @@ initsocket()
#ifdef MSG_ETAG
insint(d, "MSG_ETAG", MSG_ETAG);
#endif

/* Protocol level and numbers, usable for [gs]etsockopt */
-/* Sigh -- some systems (e.g. Linux) use enums for these. */
#ifdef SOL_SOCKET
insint(d, "SOL_SOCKET", SOL_SOCKET);
#endif
+#ifdef SOL_IP
+ insint(moddict, "SOL_IP", SOL_IP);
+#else
+ insint(moddict, "SOL_IP", 0);
+#endif
+#ifdef SOL_IPX
+ insint(moddict, "SOL_IPX", SOL_IPX);
+#endif
+#ifdef SOL_AX25
+ insint(moddict, "SOL_AX25", SOL_AX25);
+#endif
+#ifdef SOL_ATALK
+ insint(moddict, "SOL_ATALK", SOL_ATALK);
+#endif
+#ifdef SOL_NETROM
+ insint(moddict, "SOL_NETROM", SOL_NETROM);
+#endif
+#ifdef SOL_ROSE
+ insint(moddict, "SOL_ROSE", SOL_ROSE);
+#endif
+#ifdef SOL_TCP
+ insint(moddict, "SOL_TCP", SOL_TCP);
+#else
+ insint(moddict, "SOL_TCP", 6);
+#endif
+#ifdef SOL_UDP
+ insint(moddict, "SOL_UDP", SOL_UDP);
+#else
+ insint(moddict, "SOL_UDP", 17);
+#endif
#ifdef IPPROTO_IP
insint(d, "IPPROTO_IP", IPPROTO_IP);
#else
insint(d, "IPPROTO_IP", 0);
#endif
@@ -2266,10 +2328,32 @@ initsocket()
#ifdef IP_ADD_MEMBERSHIP
insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
#endif
#ifdef IP_DROP_MEMBERSHIP
insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
+#endif
+#ifdef IP_DEFAULT_MULTICAST_TTL
+ insint(moddict, "IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL);
+#endif
+#ifdef IP_DEFAULT_MULTICAST_LOOP
+ insint(moddict, "IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP);
+#endif
+#ifdef IP_MAX_MEMBERSHIPS
+ insint(moddict, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
+#endif
+
+ /* TCP options */
+#ifdef TCP_NODELAY
+ insint(moddict, "TCP_NODELAY", TCP_NODELAY);
+#endif
+#ifdef TCP_MAXSEG
+ insint(moddict, "TCP_MAXSEG", TCP_MAXSEG);
+#endif
+
+ /* IPX options */
+#ifdef IPX_TYPE
+ insint(moddict, "IPX_TYPE", IPX_TYPE);
#endif

/* Initialize gethostbyname lock */
#ifdef USE_GETHOSTBYNAME_LOCK
gethostbyname_lock = PyThread_allocate_lock();

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 146 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
Re: Some more constants for the socket module [ In reply to ]
Thanks for the socketmodule patch, Marc. This was on my mental TO-DO
list for a long time! I've checked it in.

(One note: I had a bit of trouble applying the patch; apparently your
mailer expanded all tabs to spaces. Perhaps you could use attachments
to mail diffs? Also, you seem to have renamed 'd' to 'moddict' but
you didn't send the patch for that...)

--Guido van Rossum (home page: http://www.python.org/~guido/)
Re: Some more constants for the socket module [ In reply to ]
Guido van Rossum wrote:
>
> Thanks for the socketmodule patch, Marc. This was on my mental TO-DO
> list for a long time! I've checked it in.

Cool, thanks.

> (One note: I had a bit of trouble applying the patch; apparently your
> mailer expanded all tabs to spaces. Perhaps you could use attachments
> to mail diffs?

Ok.

> Also, you seem to have renamed 'd' to 'moddict' but
> you didn't send the patch for that...)

Oops, sorry... my "#define to insint" script uses 'd' as moddict,
that's the reason why.

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 144 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/