简体   繁体   中英

Extract UDP packet payload from a ethernet frame

I am writing UDP send/recv using some Layer-2 API. I can receive the Ethernet frame containing my UDP packet. For example, I send "hello" and got the following Ethernet frame.

000f 5325 fb00 000f 5324 8c30 0800 4500   
0022 0000 4000 4011 5b0c 0a80 657d 0a80 
6542 c179 15b3 000e 46a2 3068 656c 6c6f 
0000 0000 0000 0000 0000 0000    

where

000f 5325 fb00 : destination MAC
000f 5324 8c30 : source MAC
0800           : Ethernet type
....
68 656c 6c6f   : "hello"

If I use different programs to send UDP packets, the starting bit of my message/payload ("hello") varies.

Question: How can I extract the payload?

I need to keep my UDP protocol implementation as lean as possible, so I better write them in C. But library or system functions related is still useful.

You can simply use POSIX Socket API in Linux. You can create UDP sockets and recvfrom() call can get you your UDP payload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM