This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

Network Packet Capture

Overview

The net_capture API allows user to monitor the network traffic in one of the Zephyr network interfaces and send that traffic to external system for analysis. The monitoring can be setup either manually using net-shell or automatically by using the net_capture API.

API Reference

group net_capture

Network packet capture support functions.

Functions

int net_capture_setup(const char *remote_addr, const char *my_local_addr, const char *peer_addr, const struct device **dev)

Setup network packet capturing support.

Parameters
  • remote_addr – The value tells the tunnel remote/outer endpoint IP address. The IP address can be either IPv4 or IPv6 address. This address is used to select the network interface where the tunnel is created.

  • my_local_addr – The local/inner IP address of the tunnel. Can contain also port number which is used as UDP source port.

  • peer_addr – The peer/inner IP address of the tunnel. Can contain also port number which is used as UDP destination port.

  • dev – Network capture device. This is returned to the caller.

Returns

0 if ok, <0 if network packet capture setup failed

static inline int net_capture_cleanup(const struct device *dev)

Cleanup network packet capturing support.

This should be called after the capturing is done and resources can be released.

Parameters
Returns

0 if ok, <0 if network packet capture cleanup failed

static inline int net_capture_enable(const struct device *dev, struct net_if *iface)

Enable network packet capturing support.

This creates tunnel network interface where all the captured packets are pushed. The captured network packets are placed in UDP packets that are sent to tunnel peer.

Parameters
  • dev – Network capture device

  • iface – Network interface we are starting to capture packets.

Returns

0 if ok, <0 if network packet capture enable failed

static inline bool net_capture_is_enabled(const struct device *dev)

Is network packet capture enabled or disabled.

Parameters
  • dev – Network capture device

Returns

True if enabled, False if network capture is disabled.

static inline int net_capture_disable(const struct device *dev)

Disable network packet capturing support.

Parameters
  • dev – Network capture device

Returns

0 if ok, <0 if network packet capture disable failed

static inline int net_capture_send(const struct device *dev, struct net_if *iface, struct net_pkt *pkt)

Send captured packet.

Parameters
  • dev – Network capture device

  • iface – Network interface the packet is being sent

  • pkt – The network packet that is sent

Returns

0 if ok, <0 if network packet capture send failed