Using asyncio for ARP using raw sockets

438 views
Skip to first unread message

Olaf Conradi

unread,
Oct 6, 2016, 4:23:58 PM10/6/16
to python-tulip
Hi,

I'm working on an async version of a program that sends an ARP request and waits for the response.

To do that I need to open a raw socket. I monkey patched in two methods two accomplish this:
create_raw_connection and _create_raw_connection_transport
See https://github.com/oohlaf/arp_aio/blob/master/arp_aio/arp.py#L25 up to line 96.

Not sure if this is the most elegant way?
Might it be worthwhile to add something like this to asyncio?

Secondly, when I created my ArpRequestProtocol based on asyncio.Protocol (line 128), I noticed that data_received seems to always be called for every ethernet frame that is received. Is that always the case (coincidence?), or is there a possibility that a frame starts midway into the binary data argument?

Best regards,
Olaf

Andrew Svetlov

unread,
Oct 7, 2016, 9:22:45 AM10/7/16
to python-tulip
I suggest keeping create_raw_connection() a function, not loop's class method.
After this change you don't need monkey-patching at all.
Reply all
Reply to author
Forward
0 new messages