From 1eaeef5251de184cdabe5f421d815d5c1cb58df4 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Fri, 23 Feb 2024 11:39:24 +0800 Subject: [PATCH] Documentation: Add documentation for packet sockets Signed-off-by: Zhe Weng --- Documentation/components/net/index.rst | 1 + Documentation/components/net/pkt.rst | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Documentation/components/net/pkt.rst diff --git a/Documentation/components/net/index.rst b/Documentation/components/net/index.rst index b60451e5db..4f9fc7f6cc 100644 --- a/Documentation/components/net/index.rst +++ b/Documentation/components/net/index.rst @@ -7,6 +7,7 @@ Network Support sixlowpan.rst socketcan.rst + pkt.rst nat.rst netdev.rst netguardsize.rst diff --git a/Documentation/components/net/pkt.rst b/Documentation/components/net/pkt.rst new file mode 100644 index 0000000000..28eb044293 --- /dev/null +++ b/Documentation/components/net/pkt.rst @@ -0,0 +1,37 @@ +=========================== +"Raw" packet socket support +=========================== + +Packet sockets (:c:macro:`AF_PACKET`) allow receiving and transmitting frames +without a transport protocol in between. Frames received are copied into a +packet socket tap before they enter the network. Data written into a packet +socket will bypass the network altogether and be placed in the transmission +buffer of the network interface driver. + +Configuration Options +===================== + +``CONFIG_NET_PKT_PREALLOC_CONNS`` + Number of preallocated packet connections (all tasks). +``CONFIG_NET_PKT_ALLOC_CONNS`` + Dynamic memory allocations for packet connections. +``CONFIG_NET_PKT_MAX_CONNS`` + Maximum number of packet connections. + +Usage +===== + +.. code-block:: c + + struct sockaddr_ll addr; + uint8_t buffer[BUFSIZE]; + int sd = socket(AF_PACKET, SOCK_RAW, 0); /* Create a packet socket */ + + addr.sll_family = AF_PACKET; + addr.sll_ifindex = if_nametoindex("eth0"); + bind(sd, (FAR struct sockaddr *)&addr, sizeof(addr)); /* Bind to device */ + + recv(sd, buffer, sizeof(buffer), 0); /* read(sd, buffer, sizeof(buffer)); */ + send(sd, buffer, sizeof(buffer), 0); /* write(sd, buffer, sizeof(buffer)); */ + + close(sd); /* Close the socket */