Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_ip.h File Reference

IPv6 and IPv4 definitions. More...

#include <string.h>
#include <zephyr/types.h>
#include <stdbool.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/toolchain.h>
#include <zephyr/net/net_linkaddr.h>
#include <zephyr/syscalls/net_ip.h>

Go to the source code of this file.

Data Structures

struct  net_in6_addr
 IPv6 address struct. More...
struct  net_in_addr
 IPv4 address struct. More...
struct  net_sockaddr_in6
 Socket address struct for IPv6. More...
struct  net_sockaddr_in
 Socket address struct for IPv4. More...
struct  net_sockaddr_ll
 Socket address struct for packet socket. More...
struct  net_iovec
 IO vector array element. More...
struct  net_msghdr
 Message struct. More...
struct  net_cmsghdr
 Control message ancillary data. More...
struct  net_sockaddr
 Generic sockaddr struct. More...
struct  net_tuple
 IPv6/IPv4 network connection tuple. More...
struct  net_ifreq
 Interface description structure. More...
struct  net_in_pktinfo
 Incoming IPv4 packet information. More...
struct  net_ip_mreqn
 Struct used when joining or leaving a IPv4 multicast group. More...
struct  net_ip_mreq
 Struct used when setting a IPv4 multicast network interface. More...
struct  net_ipv6_mreq
 Struct used when joining or leaving a IPv6 multicast group. More...
struct  net_in6_pktinfo
 Incoming IPv6 packet information. More...

Macros

#define NET_PF_UNSPEC   0
 Unspecified protocol family.
#define NET_PF_INET   1
 IP protocol family version 4.
#define NET_PF_INET6   2
 IP protocol family version 6.
#define NET_PF_PACKET   3
 Packet family.
#define NET_PF_CAN   4
 Controller Area Network.
#define NET_PF_NET_MGMT   5
 Network management info.
#define NET_PF_LOCAL   6
 Inter-process communication.
#define NET_PF_UNIX   NET_PF_LOCAL
 Inter-process communication.
#define NET_AF_UNSPEC   NET_PF_UNSPEC
 Unspecified address family.
#define NET_AF_INET   NET_PF_INET
 IP protocol family version 4.
#define NET_AF_INET6   NET_PF_INET6
 IP protocol family version 6.
#define NET_AF_PACKET   NET_PF_PACKET
 Packet family.
#define NET_AF_CAN   NET_PF_CAN
 Controller Area Network.
#define NET_AF_NET_MGMT   NET_PF_NET_MGMT
 Network management info.
#define NET_AF_LOCAL   NET_PF_LOCAL
 Inter-process communication.
#define NET_AF_UNIX   NET_PF_UNIX
 Inter-process communication.
#define net_ntohs(x)
 Convert 16-bit value from network to host byte order.
#define net_ntohl(x)
 Convert 32-bit value from network to host byte order.
#define net_ntohll(x)
 Convert 64-bit value from network to host byte order.
#define net_htons(x)
 Convert 16-bit value from host to network byte order.
#define net_htonl(x)
 Convert 32-bit value from host to network byte order.
#define net_htonll(x)
 Convert 64-bit value from host to network byte order.
#define NET_IPV6_ADDR_SIZE   16
 Binary size of the IPv6 address.
#define NET_IPV4_ADDR_SIZE   4
 Binary size of the IPv4 address.
#define NET_CMSG_FIRSTHDR(msghdr)
 Returns a pointer to the first cmsghdr in the ancillary data buffer associated with the passed msghdr.
#define NET_CMSG_NXTHDR(msghdr, cmsg)
 Returns the next valid cmsghdr after the passed cmsghdr.
#define NET_CMSG_DATA(cmsg)
 Returns a pointer to the data portion of a cmsghdr.
#define NET_CMSG_SPACE(length)
 Returns the number of bytes an ancillary element with payload of the passed data length occupies.
#define NET_CMSG_LEN(length)
 Returns the value to store in the cmsg_len member of the net_cmsghdr structure, taking into account any necessary alignment.
#define SOCKADDR_ALIGN   (4)
#define NET_IN6ADDR_ANY_INIT
 IPv6 address initializer.
#define NET_IN6ADDR_LOOPBACK_INIT
 IPv6 loopback address initializer.
#define NET_INADDR_ANY   0
 IPv4 any address.
#define NET_INADDR_BROADCAST   0xffffffff
 IPv4 broadcast address.
#define NET_INADDR_ANY_INIT   { { { NET_INADDR_ANY } } }
 IPv4 address initializer.
#define NET_INADDR_LOOPBACK_INIT   { { { 127, 0, 0, 1 } } }
 IPv6 loopback address initializer.
#define NET_INET_ADDRSTRLEN   16
 Max length of the IPv4 address as a string.
#define NET_INET6_ADDRSTRLEN   46
 Max length of the IPv6 address as a string.
#define NET_MAX_PRIORITIES   8
 How many priority values there are.
#define net_ipaddr_copy(dest, src)
 Copy an IPv4 or IPv6 address.

Typedefs

typedef unsigned short int net_sa_family_t
 Socket address family type.
typedef uint32_t net_socklen_t
 Length of a socket address.

Enumerations

enum  net_ip_protocol {
  NET_IPPROTO_IP = 0 , NET_IPPROTO_ICMP = 1 , NET_IPPROTO_IGMP = 2 , NET_IPPROTO_ETH_P_ALL = 3 ,
  NET_IPPROTO_IPIP = 4 , NET_IPPROTO_TCP = 6 , NET_IPPROTO_UDP = 17 , NET_IPPROTO_IPV6 = 41 ,
  NET_IPPROTO_ICMPV6 = 58 , NET_IPPROTO_RAW = 255
}
 Protocol numbers from IANA/BSD. More...
enum  net_ip_protocol_secure {
  NET_IPPROTO_TLS_1_0 = 256 , NET_IPPROTO_TLS_1_1 = 257 , NET_IPPROTO_TLS_1_2 = 258 , NET_IPPROTO_TLS_1_3 = 259 ,
  NET_IPPROTO_DTLS_1_0 = 272 , NET_IPPROTO_DTLS_1_2 = 273
}
 Protocol numbers for TLS protocols. More...
enum  net_sock_type { NET_SOCK_STREAM = 1 , NET_SOCK_DGRAM , NET_SOCK_RAW }
 Socket type. More...
enum  net_ip_mtu { NET_IPV6_MTU = 1280 , NET_IPV4_MTU = 576 }
 IP Maximum Transfer Unit. More...
enum  net_priority {
  NET_PRIORITY_BK = 1 , NET_PRIORITY_BE = 0 , NET_PRIORITY_EE = 2 , NET_PRIORITY_CA = 3 ,
  NET_PRIORITY_VI = 4 , NET_PRIORITY_VO = 5 , NET_PRIORITY_IC = 6 , NET_PRIORITY_NC = 7
}
 Network packet priority settings described in IEEE 802.1Q Annex I.1. More...
enum  net_addr_state { NET_ADDR_ANY_STATE = -1 , NET_ADDR_TENTATIVE = 0 , NET_ADDR_PREFERRED , NET_ADDR_DEPRECATED }
 What is the current state of the network address. More...
enum  net_addr_type {
  NET_ADDR_ANY = 0 , NET_ADDR_AUTOCONF , NET_ADDR_DHCP , NET_ADDR_MANUAL ,
  NET_ADDR_OVERRIDABLE
}
 How the network address is assigned to network interface. More...

Functions

static bool net_ipv6_is_addr_loopback (const struct net_in6_addr *addr)
 Check if the IPv6 address is a loopback address (::1).
static bool net_ipv6_is_addr_mcast (const struct net_in6_addr *addr)
 Check if the IPv6 address is a multicast address.
struct net_if_addrnet_if_ipv6_addr_lookup (const struct net_in6_addr *addr, struct net_if **iface)
static bool net_ipv6_is_my_addr (struct net_in6_addr *addr)
 Check if IPv6 address is found in one of the network interfaces.
struct net_if_mcast_addrnet_if_ipv6_maddr_lookup (const struct net_in6_addr *addr, struct net_if **iface)
static bool net_ipv6_is_my_maddr (struct net_in6_addr *maddr)
 Check if IPv6 multicast address is found in one of the network interfaces.
static bool net_ipv6_is_prefix (const uint8_t *addr1, const uint8_t *addr2, uint8_t length)
 Check if two IPv6 addresses are same when compared after prefix mask.
static void net_ipv6_addr_prefix_mask (const uint8_t *inaddr, uint8_t *outaddr, uint8_t prefix_len)
 Get the IPv6 network address via the unicast address and the prefix mask.
static bool net_ipv4_is_addr_loopback (const struct net_in_addr *addr)
 Check if the IPv4 address is a loopback address (127.0.0.0/8).
static bool net_ipv4_is_addr_unspecified (const struct net_in_addr *addr)
 Check if the IPv4 address is unspecified (all bits zero)
static bool net_ipv4_is_addr_mcast (const struct net_in_addr *addr)
 Check if the IPv4 address is a multicast address.
static bool net_ipv4_is_ll_addr (const struct net_in_addr *addr)
 Check if the given IPv4 address is a link local address.
static bool net_ipv4_is_private_addr (const struct net_in_addr *addr)
 Check if the given IPv4 address is from a private address range.
static void net_ipv4_addr_copy_raw (uint8_t *dest, const uint8_t *src)
 Copy an IPv4 address raw buffer.
static void net_ipv6_addr_copy_raw (uint8_t *dest, const uint8_t *src)
 Copy an IPv6 address raw buffer.
static bool net_ipv4_addr_cmp_raw (const uint8_t *addr1, const uint8_t *addr2)
 Compare two raw IPv4 address buffers.
static bool net_ipv4_addr_cmp (const struct net_in_addr *addr1, const struct net_in_addr *addr2)
 Compare two IPv4 addresses.
static bool net_ipv6_addr_cmp (const struct net_in6_addr *addr1, const struct net_in6_addr *addr2)
 Compare two IPv6 addresses.
static bool net_ipv6_addr_cmp_raw (const uint8_t *addr1, const uint8_t *addr2)
 Compare two raw IPv6 address buffers.
static bool net_ipv6_is_ll_addr (const struct net_in6_addr *addr)
 Check if the given IPv6 address is a link local address.
static bool net_ipv6_is_sl_addr (const struct net_in6_addr *addr)
 Check if the given IPv6 address is a site local address.
static bool net_ipv6_is_ula_addr (const struct net_in6_addr *addr)
 Check if the given IPv6 address is a unique local address.
static bool net_ipv6_is_global_addr (const struct net_in6_addr *addr)
 Check if the given IPv6 address is a global address.
static bool net_ipv6_is_private_addr (const struct net_in6_addr *addr)
 Check if the given IPv6 address is from a private/local address range.
const struct net_in6_addrnet_ipv6_unspecified_address (void)
 Return pointer to any (all bits zeros) IPv6 address.
const struct net_in_addrnet_ipv4_unspecified_address (void)
 Return pointer to any (all bits zeros) IPv4 address.
const struct net_in_addrnet_ipv4_broadcast_address (void)
 Return pointer to broadcast (all bits ones) IPv4 address.
bool net_if_ipv4_addr_mask_cmp (struct net_if *iface, const struct net_in_addr *addr)
static bool net_ipv4_addr_mask_cmp (struct net_if *iface, const struct net_in_addr *addr)
 Check if the given address belongs to same subnet that has been configured for the interface.
bool net_if_ipv4_is_addr_bcast (struct net_if *iface, const struct net_in_addr *addr)
static bool net_ipv4_is_addr_bcast (struct net_if *iface, const struct net_in_addr *addr)
 Check if the given IPv4 address is a broadcast address.
struct net_if_addrnet_if_ipv4_addr_lookup (const struct net_in_addr *addr, struct net_if **iface)
static bool net_ipv4_is_my_addr (const struct net_in_addr *addr)
 Check if the IPv4 address is assigned to any network interface in the system.
static bool net_ipv6_is_addr_unspecified (const struct net_in6_addr *addr)
 Check if the IPv6 address is unspecified (all bits zero)
static bool net_ipv6_is_addr_solicited_node (const struct net_in6_addr *addr)
 Check if the IPv6 address is solicited node multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC 3513.
static bool net_ipv6_is_addr_mcast_scope (const struct net_in6_addr *addr, int scope)
 Check if the IPv6 address is a given scope multicast address (FFyx::).
static bool net_ipv6_is_same_mcast_scope (const struct net_in6_addr *addr_1, const struct net_in6_addr *addr_2)
 Check if the IPv6 addresses have the same multicast scope (FFyx::).
static int net_ipv6_get_addr_mcast_scope (const struct net_in6_addr *addr)
 Returns the scope of the given IPv6 address.
static bool net_ipv6_is_addr_mcast_global (const struct net_in6_addr *addr)
 Check if the IPv6 address is a global multicast address (FFxE::/16).
static bool net_ipv6_is_addr_mcast_iface (const struct net_in6_addr *addr)
 Check if the IPv6 address is a interface scope multicast address (FFx1::).
static bool net_ipv6_is_addr_mcast_link (const struct net_in6_addr *addr)
 Check if the IPv6 address is a link local scope multicast address (FFx2::).
static bool net_ipv6_is_addr_mcast_mesh (const struct net_in6_addr *addr)
 Check if the IPv6 address is a mesh-local scope multicast address (FFx3::).
static bool net_ipv6_is_addr_mcast_site (const struct net_in6_addr *addr)
 Check if the IPv6 address is a site scope multicast address (FFx5::).
static bool net_ipv6_is_addr_mcast_org (const struct net_in6_addr *addr)
 Check if the IPv6 address is an organization scope multicast address (FFx8::).
static bool net_ipv6_is_addr_mcast_group (const struct net_in6_addr *addr, const struct net_in6_addr *group)
 Check if the IPv6 address belongs to certain multicast group.
static bool net_ipv6_is_addr_mcast_all_nodes_group (const struct net_in6_addr *addr)
 Check if the IPv6 address belongs to the all nodes multicast group.
static bool net_ipv6_is_addr_mcast_iface_all_nodes (const struct net_in6_addr *addr)
 Check if the IPv6 address is a interface scope all nodes multicast address (FF01::1).
static bool net_ipv6_is_addr_mcast_link_all_nodes (const struct net_in6_addr *addr)
 Check if the IPv6 address is a link local scope all nodes multicast address (FF02::1).
static void net_ipv6_addr_create_solicited_node (const struct net_in6_addr *src, struct net_in6_addr *dst)
 Create solicited node IPv6 multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC 3513.
static void net_ipv6_addr_create (struct net_in6_addr *addr, uint16_t addr0, uint16_t addr1, uint16_t addr2, uint16_t addr3, uint16_t addr4, uint16_t addr5, uint16_t addr6, uint16_t addr7)
 Construct an IPv6 address from eight 16-bit words.
static void net_ipv6_addr_create_ll_allnodes_mcast (struct net_in6_addr *addr)
 Create link local allnodes multicast IPv6 address.
static void net_ipv6_addr_create_ll_allrouters_mcast (struct net_in6_addr *addr)
 Create link local allrouters multicast IPv6 address.
static void net_ipv6_addr_create_v4_mapped (const struct net_in_addr *addr4, struct net_in6_addr *addr6)
 Create IPv4 mapped IPv6 address.
static bool net_ipv6_addr_is_v4_mapped (const struct net_in6_addr *addr)
 Is the IPv6 address an IPv4 mapped one.
int net_ipv6_addr_generate_iid (struct net_if *iface, const struct net_in6_addr *prefix, uint8_t *network_id, size_t network_id_len, uint8_t dad_counter, struct net_in6_addr *addr, struct net_linkaddr *lladdr)
 Generate IPv6 address using a prefix and interface identifier.
static void net_ipv6_addr_create_iid (struct net_in6_addr *addr, struct net_linkaddr *lladdr)
 Create IPv6 address interface identifier.
static bool net_ipv6_addr_based_on_ll (const struct net_in6_addr *addr, const struct net_linkaddr *lladdr)
 Check if given address is based on link layer address.
static struct net_sockaddrnet_sad (const struct net_sockaddr_storage *addr)
 Get net_sockaddr from net_sockaddr_storage.
static struct net_sockaddr_in6net_sin6 (const struct net_sockaddr *addr)
 Get net_sockaddr_in6 from net_sockaddr.
static struct net_sockaddr_innet_sin (const struct net_sockaddr *addr)
 Get net_sockaddr_in from net_sockaddr.
static struct net_sockaddr_in6_ptr * net_sin6_ptr (const struct net_sockaddr_ptr *addr)
 Get net_sockaddr_in6_ptr from net_sockaddr_ptr.
static struct net_sockaddr_in_ptr * net_sin_ptr (const struct net_sockaddr_ptr *addr)
 Get net_sockaddr_in_ptr from sockaddr_ptr.
static struct net_sockaddr_ll_ptr * net_sll_ptr (const struct net_sockaddr_ptr *addr)
 Get net_sockaddr_ll_ptr from sockaddr_ptr.
static struct net_sockaddr_can_ptr * net_can_ptr (const struct net_sockaddr_ptr *addr)
 Get net_sockaddr_can_ptr from net_sockaddr_ptr.
int net_addr_pton (net_sa_family_t family, const char *src, void *dst)
 Convert a string to IP address.
char * net_addr_ntop (net_sa_family_t family, const void *src, char *dst, size_t size)
 Convert IP address to string form.
int net_mask_len_to_netmask (net_sa_family_t family, uint8_t mask_len, struct net_sockaddr *mask)
 Create netmask from mask length.
int net_netmask_to_mask_len (net_sa_family_t family, struct net_sockaddr *mask, uint8_t *mask_len)
 Create mask length from netmask.
bool net_ipaddr_parse (const char *str, size_t str_len, struct net_sockaddr *addr)
 Parse a string that contains either IPv4 or IPv6 address and optional port, and store the information in user supplied sockaddr struct.
const char * net_ipaddr_parse_mask (const char *str, size_t str_len, struct net_sockaddr *addr, uint8_t *mask_len)
 Parse a string that contains either IPv4 or IPv6 address and optional mask len, and store the information in user supplied sockaddr struct.
int net_port_set_default (struct net_sockaddr *addr, uint16_t default_port)
 Set the default port in the sockaddr structure.
static int32_t net_tcp_seq_cmp (uint32_t seq1, uint32_t seq2)
 Compare TCP sequence numbers.
static bool net_tcp_seq_greater (uint32_t seq1, uint32_t seq2)
 Check that one TCP sequence number is greater.
int net_bytes_from_str (uint8_t *buf, int buf_len, const char *src)
 Convert a string of hex values to array of bytes.
int net_tx_priority2tc (enum net_priority prio)
 Convert Tx network packet priority to traffic class so we can place the packet into correct Tx queue.
int net_rx_priority2tc (enum net_priority prio)
 Convert Rx network packet priority to traffic class so we can place the packet into correct Rx queue.
static enum net_priority net_vlan2priority (uint8_t priority)
 Convert network packet VLAN priority to network packet priority so we can place the packet into correct queue.
static uint8_t net_priority2vlan (enum net_priority priority)
 Convert network packet priority to network packet VLAN priority.
const char * net_family2str (net_sa_family_t family)
 Return network address family value as a string.
static int net_ipv6_pe_add_filter (struct net_in6_addr *addr, bool is_denylist)
 Add IPv6 prefix as a privacy extension filter.
static int net_ipv6_pe_del_filter (struct net_in6_addr *addr)
 Delete IPv6 prefix from privacy extension filter list.

Detailed Description

IPv6 and IPv4 definitions.

Generic IPv6 and IPv4 address definitions.