#[repr(C)]
pub union OsSocketAddr {
    /* private fields */
}
Expand description

A type for handling platform-native socket addresses (struct sockaddr)

This type has a buffer big enough to hold a libc::sockaddr_in or libc::sockaddr_in6 struct. Its content can be arbitrary written using .as_mut() or .as_mut_ptr().

It also provides the conversion functions:

  • from/into SocketAddr
  • from (*const sockaddr, socklen_t)
  • into (*mut sockaddr, *mut socklen_t)

See crate level documentation.

Implementations§

Create a new empty socket address (all bytes initialised to 0)

Create a new socket address from a raw byte slice

The location pointed by ptr is assumed to hold a struct sockaddr whose length in bytes is given by len.

Its content is copied into a new OsSocketAddr object. If len is greater than the size of sockaddr_in6 then the resulting address is truncated. If less, then the extra bytes are zeroed.

If ptr is NULL, then the resulting address is zeroed.

See also OsSocketAddr::copy_to_raw

👎Deprecated since 0.2.4: use copy_from_raw()

Create a new socket address from a raw slice

Copy the socket address into a raw byte slice

The value pointed by len must be initialised with the length in bytes of the buffer pointed by ptr. On return it contains the actual size of the returned address.

If the provided buffer is too small, then the returned address is truncated (and len will have a greater value than before the call).

If ptr is NULL then the function does nothing.

If the value of .sa_family does not resolve to AF_INET or AF_INET6 then the function sets *len to 0 and returns an error.

See also OsSocketAddr::copy_from_raw

Create a new socket address from a SocketAddr object

Attempt to convert the internal buffer into a SocketAddr object

The internal buffer is assumed to be a sockaddr.

If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is converted into SocketAddr, otherwise the function returns None.

Return the length of the address

The result depends on the value of .sa_family in the internal buffer:

Return the size of the internal buffer

Get a pointer to the internal buffer

Get a mutable pointer to the internal buffer

Trait Implementations§

Get the internal buffer as a mutable slice

Get the internal buffer as a byte slice

Note: the actual length of slice depends on the value of .sa_family (see .len())

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more

Attempt to convert the internal buffer into a SocketAddr object

The internal buffer is assumed to be a sockaddr.

If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is converted into SocketAddr, otherwise the function returns None.

Attempt to convert the internal buffer into a SocketAddr object

The internal buffer is assumed to be a sockaddr.

If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is converted into SocketAddr, otherwise the function returns an error.

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.