Reputation: 103
I'm trying to build a simple router prototype in python with which I could test new routed protocols; let's say newly made up IPv7. From what I understood I cannot use sockets (socket.AF_INET) without modifying sys/socket.h file. If so, how would I serialise newly made up routed protocol?
The raw_socket would also not do trick as the packets isn't IPv4. I would envision IPv7 to be like encapsulation protocol for IPv4. I wonder how folks are implementing new protocols, or re-implementing old ones, let's say IPX or AppleTalk, in Python?
Any ideas on how can I approach this? Or the only way to go is hard-core C?
Upvotes: 0
Views: 184
Reputation: 30285
socket.AF_INET
is an IP-level socket, which means that the OS is responsible for handing the IP layer.
However, you can use a AF_PACKET
socket, which allows you to work on frames (L2) directly. From man 7 packet
:
PACKET(7) Linux Programmer's Manual PACKET(7)
NAME
packet - packet interface on device level
SYNOPSIS
#include <sys/socket.h>
#include <linux/if_packet.h>
#include <net/ethernet.h> /* the L2 protocols */
packet_socket = socket(AF_PACKET, int socket_type, int protocol);
DESCRIPTION
Packet sockets are used to receive or send raw packets at the device driver (OSI Layer 2) level.
They allow the user to implement protocol modules in user space on top of the physical layer.
In python, the constant is socket.AF_PACKET
(link)
Upvotes: 1