Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Send and receive IPv4 or IPv6 ICMP Echo Request messages.

Data Structures

struct  net_icmp_ctx
 ICMP context structure. More...
 
struct  net_icmp_ip_hdr
 Struct presents either IPv4 or IPv6 header in ICMP response message. More...
 
struct  net_icmp_ping_params
 Struct presents parameters that are needed when sending Echo-Request (ping) messages. More...
 
struct  net_icmp_offload
 ICMP offload context structure. More...
 

Macros

#define NET_ICMPV4_ECHO_REQUEST   8
 ICMPv4 Echo-Request.
 
#define NET_ICMPV4_ECHO_REPLY   0
 ICMPv4 Echo-Reply.
 
#define NET_ICMPV6_ECHO_REQUEST   128
 ICMPv6 Echo-Request.
 
#define NET_ICMPV6_ECHO_REPLY   129
 ICMPv6 Echo-Reply.
 

Typedefs

typedef int(* net_icmp_handler_t) (struct net_icmp_ctx *ctx, struct net_pkt *pkt, struct net_icmp_ip_hdr *ip_hdr, struct net_icmp_hdr *icmp_hdr, void *user_data)
 Handler function that is called when ICMP response is received.
 
typedef int(* net_icmp_offload_ping_handler_t) (struct net_icmp_ctx *ctx, struct net_if *iface, struct sockaddr *dst, struct net_icmp_ping_params *params, void *user_data)
 Handler function that is called when an Echo-Request is sent to offloaded device.
 

Functions

int net_icmp_init_ctx (struct net_icmp_ctx *ctx, uint8_t type, uint8_t code, net_icmp_handler_t handler)
 Initialize the ICMP context structure.
 
int net_icmp_cleanup_ctx (struct net_icmp_ctx *ctx)
 Cleanup the ICMP context structure.
 
int net_icmp_send_echo_request (struct net_icmp_ctx *ctx, struct net_if *iface, struct sockaddr *dst, struct net_icmp_ping_params *params, void *user_data)
 Send ICMP echo request message.
 
int net_icmp_register_offload_ping (struct net_icmp_offload *ctx, struct net_if *iface, net_icmp_offload_ping_handler_t ping_handler)
 Register a handler function that is called when an Echo-Request is sent to the offloaded device.
 
int net_icmp_unregister_offload_ping (struct net_icmp_offload *ctx)
 Unregister the offload handler.
 
int net_icmp_get_offload_rsp_handler (struct net_icmp_offload *ctx, net_icmp_handler_t *resp_handler)
 Get a ICMP response handler function for an offloaded device.
 

Detailed Description

Macro Definition Documentation

◆ NET_ICMPV4_ECHO_REPLY

#define NET_ICMPV4_ECHO_REPLY   0

#include <zephyr/net/icmp.h>

ICMPv4 Echo-Reply.

◆ NET_ICMPV4_ECHO_REQUEST

#define NET_ICMPV4_ECHO_REQUEST   8

#include <zephyr/net/icmp.h>

ICMPv4 Echo-Request.

◆ NET_ICMPV6_ECHO_REPLY

#define NET_ICMPV6_ECHO_REPLY   129

#include <zephyr/net/icmp.h>

ICMPv6 Echo-Reply.

◆ NET_ICMPV6_ECHO_REQUEST

#define NET_ICMPV6_ECHO_REQUEST   128

#include <zephyr/net/icmp.h>

ICMPv6 Echo-Request.

Typedef Documentation

◆ net_icmp_handler_t

net_icmp_handler_t

#include <zephyr/net/icmp.h>

Handler function that is called when ICMP response is received.

Parameters
ctxICMP context to use.
pktReceived ICMP response network packet.
ip_hdrIP header of the packet.
icmp_hdrICMP header of the packet.
user_dataA valid pointer to user data or NULL

◆ net_icmp_offload_ping_handler_t

net_icmp_offload_ping_handler_t

#include <zephyr/net/icmp.h>

Handler function that is called when an Echo-Request is sent to offloaded device.

This handler is typically setup by the device driver so that it can catch the ping request and send it to the offloaded device.

Parameters
ctxICMP context used in this request.
ifaceNetwork interface, can be set to NULL in which case the interface is selected according to destination address.
dstIP address of the target host.
paramsEcho-Request specific parameters. May be NULL in which case suitable default parameters are used.
user_dataUser supplied opaque data passed to the handler. May be NULL.

Function Documentation

◆ net_icmp_cleanup_ctx()

int net_icmp_cleanup_ctx ( struct net_icmp_ctx ctx)

#include <zephyr/net/icmp.h>

Cleanup the ICMP context structure.

This will unregister the ICMP handler from the system.

Parameters
ctxICMP context used in this request.

◆ net_icmp_get_offload_rsp_handler()

int net_icmp_get_offload_rsp_handler ( struct net_icmp_offload ctx,
net_icmp_handler_t resp_handler 
)

#include <zephyr/net/icmp.h>

Get a ICMP response handler function for an offloaded device.

When a ping response is received by the driver, it should call the handler function with proper parameters so that the ICMP response is received by the net stack.

Parameters
ctxICMP offload context used in this request.
resp_handlerFunction to be called when offloaded ping response is received by the offloaded driver. The ICMP response handler function is returned and the caller should call it when appropriate.
Returns
Return 0 if the call succeed, <0 otherwise.

◆ net_icmp_init_ctx()

int net_icmp_init_ctx ( struct net_icmp_ctx ctx,
uint8_t  type,
uint8_t  code,
net_icmp_handler_t  handler 
)

#include <zephyr/net/icmp.h>

Initialize the ICMP context structure.

Must be called before ICMP messages can be sent. This will register handler to the system.

Parameters
ctxICMP context used in this request.
typeType of ICMP message we are handling.
codeCode of ICMP message we are handling.
handlerCallback function that is called when a response is received.

◆ net_icmp_register_offload_ping()

int net_icmp_register_offload_ping ( struct net_icmp_offload ctx,
struct net_if iface,
net_icmp_offload_ping_handler_t  ping_handler 
)

#include <zephyr/net/icmp.h>

Register a handler function that is called when an Echo-Request is sent to the offloaded device.

This function is typically called by a device driver so that it can do the actual offloaded ping call.

Parameters
ctxICMP offload context used for this interface.
ifaceNetwork interface of the offloaded device.
ping_handlerFunction to be called when offloaded ping request is done.
Returns
Return 0 if the register succeed, <0 otherwise.

◆ net_icmp_send_echo_request()

int net_icmp_send_echo_request ( struct net_icmp_ctx ctx,
struct net_if iface,
struct sockaddr dst,
struct net_icmp_ping_params params,
void *  user_data 
)

#include <zephyr/net/icmp.h>

Send ICMP echo request message.

Parameters
ctxICMP context used in this request.
ifaceNetwork interface, can be set to NULL in which case the interface is selected according to destination address.
dstIP address of the target host.
paramsEcho-Request specific parameters. May be NULL in which case suitable default parameters are used.
user_dataUser supplied opaque data passed to the handler. May be NULL.
Returns
Return 0 if the sending succeed, <0 otherwise.

◆ net_icmp_unregister_offload_ping()

int net_icmp_unregister_offload_ping ( struct net_icmp_offload ctx)

#include <zephyr/net/icmp.h>

Unregister the offload handler.

Parameters
ctxICMP offload context used for this interface.
Returns
Return 0 if the call succeed, <0 otherwise.