ip_to_bytes

Function ip_to_bytes 

Source
pub fn ip_to_bytes(ip: IpAddr) -> [u8; 16]
Expand description

Converts an IP address to its 16-byte representation.

For IPv4 addresses, this function creates an IPv4-mapped IPv6 address by:

  • Setting the first 10 bytes to 0x00
  • Setting bytes 10-11 to 0xFF
  • Copying the 4 IPv4 address bytes to positions 12-15

For IPv6 addresses, it simply returns the 16-byte representation directly.

§Arguments

  • ip - The IP address to convert

§Returns

A 16-byte array containing the address representation