This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/packet/udp_helpers.h

62 lines
1.5 KiB
C
Raw Normal View History

2023-12-21 20:03:43 +08:00
#ifndef _UDP_HELPERS_H
#define _UDP_HELPERS_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <arpa/inet.h>
#define __FAVOR_BSD 1
#include <netinet/udp.h>
2024-01-03 09:57:06 +08:00
/*
* 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 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
2024-01-11 16:46:33 +08:00
static inline uint16_t udp_hdr_get_host_order_sport(const struct udphdr *hdr)
2023-12-21 20:03:43 +08:00
{
return ntohs(hdr->uh_sport);
}
2024-01-11 16:46:33 +08:00
static inline uint16_t udp_hdr_get_host_order_dport(const struct udphdr *hdr)
2023-12-21 20:03:43 +08:00
{
return ntohs(hdr->uh_dport);
}
2024-01-11 16:46:33 +08:00
static inline uint16_t udp_hdr_get_net_order_sport(const struct udphdr *hdr)
{
return hdr->uh_sport;
}
static inline uint16_t udp_hdr_get_net_order_dport(const struct udphdr *hdr)
{
return hdr->uh_dport;
}
2024-01-03 09:57:06 +08:00
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);
}
2023-12-21 20:03:43 +08:00
#ifdef __cpluscplus
}
#endif
#endif