Add Packet/IPv4/TCP/UDP helpers API
This commit is contained in:
@@ -10,6 +10,20 @@ extern "C"
|
||||
#define __FAVOR_BSD 1
|
||||
#include <netinet/udp.h>
|
||||
|
||||
/*
|
||||
* User Datagram Header Format
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Source Port | Destination Port |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Length | Checksum |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Data |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
static inline uint16_t udp_hdr_get_sport(const struct udphdr *hdr)
|
||||
{
|
||||
return ntohs(hdr->uh_sport);
|
||||
@@ -20,6 +34,16 @@ static inline uint16_t udp_hdr_get_dport(const struct udphdr *hdr)
|
||||
return ntohs(hdr->uh_dport);
|
||||
}
|
||||
|
||||
static inline uint16_t udp_hdr_get_len(const struct udphdr *hdr)
|
||||
{
|
||||
return ntohs(hdr->uh_ulen);
|
||||
}
|
||||
|
||||
static inline uint16_t udp_hdr_get_checksum(const struct udphdr *hdr)
|
||||
{
|
||||
return ntohs(hdr->uh_sum);
|
||||
}
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user