JFLib

netpkt/udp.rs#

Source: lib/netpkt/udp.rs

udp -- the User Datagram Protocol (RFC 768, RFC 8200 8.1)

  UdpView::parse(b)       ports, length, checksum, payload (bounded by the length field)
  checksum_ok_v4 / _v6    0 means "no checksum" over IPv4; over IPv6 it is mandatory
  UdpHdr { src_port, dst_port }   push_v4 / push_v6 (&mut Pkt) with the checksum
  port_name(port)         well-known names ("dns", "dhcp-server", ...)
UDP_HDR: usize = 8
PORT_DNS: u16 = 53
PORT_DHCP_SERVER: u16 = 67
PORT_DHCP_CLIENT: u16 = 68
PORT_TFTP: u16 = 69
PORT_NTP: u16 = 123
PORT_SNMP: u16 = 161
PORT_SYSLOG: u16 = 514
PORT_RIP: u16 = 520
PORT_DHCPV6_CLIENT: u16 = 546
PORT_DHCPV6_SERVER: u16 = 547
  • struct UdpView<'a> a received UDP datagram

impl<'a> UdpView<'a>

  • fn parse(b: &'a [u8]) -> Option<UdpView<'a>>

  • fn src_port(&self) -> u16

  • fn dst_port(&self) -> u16

  • fn len(&self) -> usize

  • fn checksum(&self) -> u16

  • fn payload(&self) -> &'a [u8]

  • fn bytes(&self) -> &'a [u8]

  • fn checksum_ok_v4(&self, src: Ipv4, dst: Ipv4) -> bool over IPv4 a zero checksum means "not computed" and is accepted

  • fn checksum_ok_v6(&self, src: Ipv6, dst: Ipv6) -> bool

  • struct UdpHdr a UDP header to write

    • src_port: u16
    • dst_port: u16

impl UdpHdr

  • const LEN: usize = UDP_HDR

  • fn new(src_port: u16, dst_port: u16) -> UdpHdr

  • fn push_v4(&self, p: &mut Pkt, src: Ipv4, dst: Ipv4) prepends the header with the checksum over the IPv4 pseudo header

  • fn push_v6(&self, p: &mut Pkt, src: Ipv6, dst: Ipv6) prepends the header with the checksum over the IPv6 pseudo header

  • fn port_name(port: u16) -> Option<&'static str> a short name of a well-known UDP port

Source: docs/API.md in the JFLib repository.