Sending and Receiving OSPF Protocol Data with Twisted
![](https://secure.gravatar.com/avatar/e7f3eac254014c1dc7b964d6cc59d4a7.jpg?s=120&d=mm&r=g)
I am starting to work on a lightweight OSPFv2 protocol implementation and thought that twisted looked like a good tool to use for a lot of the state machine and timing parts. I need to create a SOCK_RAW socket for protocol 89. Can someone point me in the right direction to get twisted to use this? Here's a minimal example of what I need to do to receive the packets import socket import struct sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, 89) sock.bind(('', 0)) multicast_group = '224.0.0.5' group = socket.inet_aton(multicast_group) mreq = struct.pack('4s4s', group, socket.inet_aton('192.168.88.253')) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) while True: data, address = sock.recvfrom(1024) print(data.hex())
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
Sadly I have not used it much myself, so I can't give terribly specific recommendations, but this is the general domain of `twisted.pair`. I can see it has some tun/tap stuff but I don't see a SOCK_RAW anywhere. The docs, such as they are, are here: https://docs.twistedmatrix.com/en/stable/pair/index.html I hope someone else chimes in with more specificity, but I'd love to hear of your success, and maybe get some contributions which smooth over this sort of workflow… -g
On Nov 20, 2023, at 2:10 PM, Tim Nowaczyk <zimage@gmail.com> wrote:
I am starting to work on a lightweight OSPFv2 protocol implementation and thought that twisted looked like a good tool to use for a lot of the state machine and timing parts. I need to create a SOCK_RAW socket for protocol 89. Can someone point me in the right direction to get twisted to use this? Here's a minimal example of what I need to do to receive the packets
import socket import struct
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, 89) sock.bind(('', 0))
multicast_group = '224.0.0.5' group = socket.inet_aton(multicast_group) mreq = struct.pack('4s4s', group, socket.inet_aton('192.168.88.253')) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True: data, address = sock.recvfrom(1024) print(data.hex()) _______________________________________________ Twisted mailing list -- twisted@python.org To unsubscribe send an email to twisted-leave@python.org https://mail.python.org/mailman3/lists/twisted.python.org/ Message archived at https://mail.python.org/archives/list/twisted@python.org/message/6ATYCIUTTCT... Code of Conduct: https://twisted.org/conduct
participants (2)
-
Glyph
-
Tim Nowaczyk