Loading...
Searching...
No Matches
net.h File Reference

Network related helper functions. More...

Functions

int spdk_net_get_interface_name (const char *ip, char *ifc, size_t len)
 Gets the name of the network interface for the given IP address.
 
int spdk_net_get_address_string (struct sockaddr *sa, char *addr, size_t len)
 Gets the address string for a given struct sockaddr.
 
bool spdk_net_is_loopback (int fd)
 Checks if the given fd is a loopback interface or not.
 
int spdk_net_getaddr (int fd, char *laddr, int llen, uint16_t *lport, char *paddr, int plen, uint16_t *pport)
 
int spdk_net_compare_address (int adrfam, const char *addr1, const char *addr2, int *cmp)
 Compare two IP addresses to check if they are equal, and store the comparison result in *cmp.
 

Detailed Description

Network related helper functions.

Function Documentation

◆ spdk_net_compare_address()

int spdk_net_compare_address ( int adrfam,
const char * addr1,
const char * addr2,
int * cmp )

Compare two IP addresses to check if they are equal, and store the comparison result in *cmp.

The comparison result follows the same rule as strcmp, i.e. 0 if addr1 == addr2, less than 0 if addr1 < addr2, and greater than 0 if addr1 > addr2.

Note that the result is only valid when this function returns 0. Otherwise, the content of *cmp will not be touched.

Parameters
adrfamAddress family of the IP addresses, can be AF_INET or AF_INET6.
addr1First IP address.
addr2Second IP address.
cmpA pointer to the variable to store the result of the comparison.
Returns
0 on success, and *cmp contains the comparison result, -EAFNOSUPPORT if adrfam is not supported, or -EINVAL if the addresses are invalid.

◆ spdk_net_get_address_string()

int spdk_net_get_address_string ( struct sockaddr * sa,
char * addr,
size_t len )

Gets the address string for a given struct sockaddr.

Parameters
sasockaddr to get the address string for
addrstring to put the address
lenlength of the the addr parameter
Returns
0 on success, negative errno otherwise

◆ spdk_net_get_interface_name()

int spdk_net_get_interface_name ( const char * ip,
char * ifc,
size_t len )

Gets the name of the network interface for the given IP address.

Parameters
ipIP address to find the interface name for
ifcstring output parameter for the interface name
lenlength of the ifc parameter in bytes
Returns
0 if successful, the interface name will be copied to the ifc parameter -ENODEV if an interface name could not be identified -ENOMEM the provided ifc string was too small

◆ spdk_net_is_loopback()

bool spdk_net_is_loopback ( int fd)

Checks if the given fd is a loopback interface or not.

Parameters
fdfile descriptor to check
Returns
true if the fd is loopback, false if not