Skip to content

GH-100813: Add IPv4 socket option constant IP_PKTINFO as socket module attribute #10294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 9, 2023

Conversation

dsentinel
Copy link
Contributor

@dsentinel dsentinel commented Nov 2, 2018

The socket option IP_PKTINFO is defined on Linux and OSX.
I would think we would want all the socket option constants defined in systems headers specifically <in.h> available as socket module level attributes.

There are many other constants I would be willing to add, if desired.
In fact I'm curious if all constants should be pulled from headers dynamically.

My first PR on cpython, forgive any transgressions. I'm not clear if I should also create a br on bpo.

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@dsentinel
Copy link
Contributor Author

Would it be possible to use something like Tools/scripts/h2py.py at import time?

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are merge conflicts.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost
Copy link

ghost commented Jan 4, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@dsentinel dsentinel changed the title Add IPv4 socket option constant IP_PKTINFO as socket module attribute. Add IPv4 socket option constant IP_PKTINFO as socket module attribute. gh-100813 Jan 6, 2023
@dsentinel
Copy link
Contributor Author

This should be about set.

Hold merging if you'd like me to add the other constants that are defined in in.h and not in cpython.

@dsentinel
Copy link
Contributor Author

dsentinel commented Jan 7, 2023

These are the other potential constants that could also be included.

The indented lines/defs are already in.

#define IP_TOS		1
	#define IP_TTL		2
	#define IP_HDRINCL	3
	#define IP_OPTIONS	4
#define IP_ROUTER_ALERT	5
	#define IP_RECVOPTS	6
	#define IP_RETOPTS	7
	#define IP_PKTINFO	8
#define IP_PKTOPTIONS	9
#define IP_MTU_DISCOVER	10
#define IP_RECVERR	11
#define IP_RECVTTL	12
	#define	IP_RECVTOS	13 #define IP_MTU		14
#define IP_FREEBIND	15
#define IP_IPSEC_POLICY	16
#define IP_XFRM_POLICY	17
#define IP_PASSSEC	18
	#define IP_TRANSPARENT	19

	#define IP_RECVRETOPTS	IP_RETOPTS

#define IP_ORIGDSTADDR       20
#define IP_RECVORIGDSTADDR   IP_ORIGDSTADDR

#define IP_MINTTL       21
#define IP_NODEFRAG     22
#define IP_CHECKSUM	23
	#define IP_BIND_ADDRESS_NO_PORT	24
#define IP_RECVFRAGSIZE	25
#define IP_RECVERR_RFC4884	26

#define IP_PMTUDISC_DONT		0	/* Never send DF frames */
#define IP_PMTUDISC_WANT		1	/* Use per route hints	*/
#define IP_PMTUDISC_DO			2	/* Always DF		*/
#define IP_PMTUDISC_PROBE		3       /* Ignore dst pmtu      */

#define IP_PMTUDISC_INTERFACE		4

#define IP_PMTUDISC_OMIT		5

	#define IP_MULTICAST_IF			32
	#define IP_MULTICAST_TTL 		33
	#define IP_MULTICAST_LOOP 		34
	#define IP_ADD_MEMBERSHIP		35
	#define IP_DROP_MEMBERSHIP		36
#define IP_UNBLOCK_SOURCE		37
#define IP_BLOCK_SOURCE			38
#define IP_ADD_SOURCE_MEMBERSHIP	39
#define IP_DROP_SOURCE_MEMBERSHIP	40
#define IP_MSFILTER			41
#define MCAST_JOIN_GROUP		42
#define MCAST_BLOCK_SOURCE		43
#define MCAST_UNBLOCK_SOURCE		44
#define MCAST_LEAVE_GROUP		45
#define MCAST_JOIN_SOURCE_GROUP		46
#define MCAST_LEAVE_SOURCE_GROUP	47
#define MCAST_MSFILTER			48
#define IP_MULTICAST_ALL		49
#define IP_UNICAST_IF			50

#define MCAST_EXCLUDE	0
#define MCAST_INCLUDE	1

	#define IP_DEFAULT_MULTICAST_TTL        1
	#define IP_DEFAULT_MULTICAST_LOOP       1

source: https://github.com/torvalds/linux/blob/master/include/uapi/linux/in.h

@kumaraditya303 kumaraditya303 changed the title Add IPv4 socket option constant IP_PKTINFO as socket module attribute. gh-100813 GH-100813: Add IPv4 socket option constant IP_PKTINFO as socket module attribute Jan 8, 2023
@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Jan 8, 2023

Lets only add IP_PKTINFO in this PR, you also need to add versionadded field for the constant to the docs https://docs.python.org/3.12/library/socket.html?highlight=socket#socket.SOMAXCONN

@dsentinel
Copy link
Contributor Author

Lets only add IP_PKTINFO in this PR,

ok :)

you also need to add versionadded field for the constant to the docs https://docs.python.org/3.12/library/socket.html?highlight=socket#socket.SOMAXCONN

Done.

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants