Open ad0d67ab-51fe-48a7-b2b3-b753bea68812 opened 2 years ago
For educational purposes, I'm developing my own IP stack in Python. It's going well but I'm stuck at a low level. I need to implement the following (simple) task:
Desperate, I tried to verify it wasn't a kernel problem. I wrote the C version of the above snippet.
First problem is that AF_PACKET sockets are broken in Python.
Second problem is inadequate documentation. Following issue ID 25041, some documentation has been added but there is still lot of room for improvements. For example:
recvfrom return 2 values. The first is the binary packet and the second one is a 5 member structure. The first member of the structure is the interface name. The 5th member if the MAC address (assuming the interface is an Ethernet NIC). The 3rd one is a protocol number (the data-link protocol) whose data is in front of the returnet packet (for WiFi packets, we will see Radiotap protocol at that level). That's a whole new world for documentors.
socket.bind() parameter is documented to be an address. For AF_PACKET, the address is documented in "Socket Families" section. Definition is vague. The 'proto' description would be easier to understand with "An integer (in network-byte-order) representing the low level protocol (enumerated in linux/if_ether.h) or ETH_P_ALL for all protocols. This parameter is only used for filtering inbound packets." IMO 'pkttype', 'hatype', 'addr' are there to document the information returned by recvfrom(). It's written they are "optional" but I think it's not correct.
Working examples of AF_PACKET must be provided, possibly in a HOWTO.
When it's easier to program in C, it should tell you there is a problem on Python side.
Thank you for the thorough report. Do you feel comfortable writing that missing documentation?
Next 3 steps must be (in decreasing priorities):
For the 3rd step, I would accept to join a team.
To contribute you'll need to sign a Contributor's License Agreement [1].
After that, anything you can do to help will move this forward. You may not be aware, but Python is developed primarily by volunteers, which unfortunately means that time is normally spent on bugs that the volunteers are interested in -- and nobody else seems interested in this one (which probably means not many people use this functionality).
If you have time, perhaps you could write some tests? They would obviously fail at the moment, but would help when somebody wants to fix the code itself.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['type-feature', '3.8', 'docs']
title = 'Problems with AF_PACKET sockets'
updated_at =
user = 'https://bugs.python.org/gallard'
```
bugs.python.org fields:
```python
activity =
actor = 'ethan.furman'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation =
creator = 'gallard'
dependencies = []
files = []
hgrepos = []
issue_num = 46089
keywords = []
message_count = 4.0
messages = ['408638', '408645', '408652', '408747']
nosy_count = 3.0
nosy_names = ['docs@python', 'ethan.furman', 'gallard']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46089'
versions = ['Python 3.8']
```