LCOV - code coverage report
Current view: top level - util/net - fd_net_headers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 19 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_util_net_headers_h
       2             : #define HEADER_fd_src_util_net_headers_h
       3             : 
       4             : #include "fd_udp.h"
       5             : #include "fd_eth.h"
       6             : 
       7             : typedef struct __attribute__((packed)) {
       8             :   fd_eth_hdr_t eth[1];
       9             :   fd_ip4_hdr_t ip4[1];
      10             :   fd_udp_hdr_t udp[1];
      11             : } fd_net_hdrs_t;
      12             : 
      13             : FD_PROTOTYPES_BEGIN
      14             : 
      15             : /* Helper method to populate a header template
      16             :    containing ethernet, UDP and IP headers with
      17             :    default values. Used for pre-staging headers. */
      18             : 
      19             : static inline fd_net_hdrs_t *
      20             : fd_net_create_packet_header_template( fd_net_hdrs_t * pkt,
      21             :                                  ulong          payload_sz,
      22             :                                  uint           src_ip,
      23             :                                  uchar const *  src_mac,
      24           0 :                                  ushort         src_port ) {
      25           0 :   memset( pkt->eth->dst, 0,       6UL );
      26           0 :   memcpy( pkt->eth->src, src_mac, 6UL );
      27           0 :   pkt->eth->net_type  = fd_ushort_bswap( FD_ETH_HDR_TYPE_IP );
      28             : 
      29           0 :   pkt->ip4->verihl       = FD_IP4_VERIHL( 4U, 5U );
      30           0 :   pkt->ip4->tos          = (uchar)0;
      31           0 :   pkt->ip4->net_tot_len  = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_ip4_hdr_t)+sizeof(fd_udp_hdr_t)) );
      32           0 :   pkt->ip4->net_frag_off = fd_ushort_bswap( FD_IP4_HDR_FRAG_OFF_DF );
      33           0 :   pkt->ip4->ttl          = (uchar)64;
      34           0 :   pkt->ip4->protocol     = FD_IP4_HDR_PROTOCOL_UDP;
      35           0 :   pkt->ip4->check        = 0U;
      36           0 :   memcpy( pkt->ip4->saddr_c, &src_ip, 4UL );
      37           0 :   memset( pkt->ip4->daddr_c, 0,       4UL );
      38             : 
      39           0 :   pkt->udp->net_sport = fd_ushort_bswap( src_port );
      40           0 :   pkt->udp->net_dport = (ushort)0;
      41           0 :   pkt->udp->net_len   = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_udp_hdr_t)) );
      42           0 :   pkt->udp->check     = (ushort)0;
      43             : 
      44           0 :   return pkt;
      45           0 : }
      46             : 
      47             : FD_PROTOTYPES_END
      48             : 
      49             : #endif /* HEADER_fd_src_util_net_headers_h */

Generated by: LCOV version 1.14