You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2024/02/23 07:32:57 UTC
(nuttx) 02/02: Documentation: Add documentation for packet sockets
This is an automated email from the ASF dual-hosted git repository.
jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 1eaeef5251de184cdabe5f421d815d5c1cb58df4
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Fri Feb 23 11:39:24 2024 +0800
Documentation: Add documentation for packet sockets
Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
Documentation/components/net/index.rst | 1 +
Documentation/components/net/pkt.rst | 37 ++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
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 */