![]() Our sockaddr_ll was written into directly during the recvfrom() so we can simply use it. ![]() I’m using SOCK_RAW so when I receive an ARP packet so this is the information I will end up receiving: /// An ARP packet with ethernet headers still attached # struct RawArpFrame The first includes the ethernet headers in the packet body the second does not. If you’re using the AF_PACKET interface you can choose between SOCK_RAW and SOCK_DGRAM. ![]() To send and receive packets the first thing you need is a socket. This is the complete code for the server I’m going to be describing: Opening a Socket I wanted to blog about how I got it working, but since AX.25 is a little obscure I’ve decided to build a basic ARP server using similar code. I recently figured out how to make this work for sending and receiving raw AX.25 packets. Clearly Rust’s type checker is not going to be thrilled about this. If you’re receiving from a raw socket then this actually needs to be a pointer to a sockaddr_ll, which is included in libc but is a completely different type from Rust’s point of view. The libc bindings for recvfrom(), for example, require you to pass in a *mut sockaddr. ![]() This is not especially ergonomic in Rust. It’s ostensibly a type of sockaddr but it has a different length, different fields, and different parts that are relevant in different situations. It’s documented primarily in the packet(7) manpage and the workhorse of this interface is a struct called sockaddr_ll. ![]() Linux has a fiddly but useful C interface for sending and receiving raw network packets. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |