[][src]Struct capsule::packets::Udp

pub struct Udp<E: IpPacket> { /* fields omitted */ }

User Datagram Protocol packet based on IETF RFC 768.

 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                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  • Source Port: (16 bits) An optional field that, when meaningful, indicates the port of the sending process, and may be assumed to be the port to which a reply should be addressed in the absence of any other information. If not used, a value of zero is inserted.

  • Destination Port: (16 bits) Has a meaning within the context of a particular Internet destination address.

  • Length: (16 bits) The length in octets of this user datagram including its header and the data. (This means the minimum value of the length is eight.)

  • Checksum: (16 bits) The 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.

    The pseudo header conceptually prefixed to the UDP header contains the source address, the destination address, the protocol, and the UDP length. This information gives protection against misrouted datagrams. This checksum procedure is the same as is used in TCP.

Implementations

impl<E: IpPacket> Udp<E>[src]

pub fn src_port(&self) -> u16[src]

Returns the source port.

pub fn set_src_port(&mut self, src_port: u16)[src]

Sets the source port.

pub fn dst_port(&self) -> u16[src]

Returns the destination port.

pub fn set_dst_port(&mut self, dst_port: u16)[src]

Sets the destination port.

pub fn length(&self) -> u16[src]

Returns the length in octets of this user datagram including this header and the data.

pub fn checksum(&self) -> u16[src]

Returns the checksum.

pub fn no_checksum(&mut self)[src]

Sets checksum to 0 indicating no checksum generated.

pub fn flow(&self) -> Flow[src]

Returns the 5-tuple that uniquely identifies a UDP connection.

pub fn set_src_ip(&mut self, src_ip: IpAddr) -> Fallible<()>[src]

Sets the layer-3 source address and recomputes the checksum.

It recomputes the checksum using the incremental method. This is more efficient if the only change made is the address. Otherwise should use cascade to recompute the checksum over all the fields.

pub fn set_dst_ip(&mut self, dst_ip: IpAddr) -> Fallible<()>[src]

Sets the layer-3 destination address and recomputes the checksum.

It recomputes the checksum using the incremental method. This is more efficient if the only change made is the address. Otherwise should use cascade to recompute the checksum over all the fields.

Trait Implementations

impl<E: IpPacket> Debug for Udp<E>[src]

impl<E: IpPacket> Packet for Udp<E>[src]

type Envelope = E

The preceding packet type for an UDP packet can be either an IPv4 packet, an IPv6 packet, or any IPv6 extension packets.

fn try_parse(envelope: Self::Envelope, _internal: Internal) -> Fallible<Self>[src]

Parses the envelope's payload as an UDP packet.

If the envelope is IPv4, then Ipv4::protocol must be set to ProtocolNumbers::Udp. If the envelope is IPv6 or an extension header, then next_header must be set to ProtocolNumbers::Udp. Otherwise, a parsing error is returned.

fn try_push(envelope: Self::Envelope, _internal: Internal) -> Fallible<Self>[src]

Prepends an UDP packet to the beginning of the envelope's payload.

If the envelope is IPv4, then Ipv4::protocol is set to ProtocolNumbers::Udp. If the envelope is IPv6 or an extension header, then next_header is set to ProtocolNumbers::Udp.

fn reconcile(&mut self)[src]

Reconciles the derivable header fields against the changes made to the packet.

  • length is set to the total length of the header and the payload.
  • checksum is computed based on the pseudo-header and the full packet.

Auto Trait Implementations

impl<E> RefUnwindSafe for Udp<E> where
    E: RefUnwindSafe

impl<E> !Send for Udp<E>

impl<E> !Sync for Udp<E>

impl<E> Unpin for Udp<E> where
    E: Unpin

impl<E> UnwindSafe for Udp<E> where
    E: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,