Skip to content

Commit 607309d

Browse files
committedMar 18, 2025·
samples: wifi: Fix proto type used for RAW sockets
It turned out that IPPROTO_RAW is not a valid proto type for AF_PACKET sockets, so it likely won't be supported anymore in the future. As the samples doing raw TX aren't actually using IP protocols, but just sending raw L2 frames, we could just use ETH_P_ALL as protocol when creating socket instead. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent d5d91c8 commit 607309d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎samples/wifi/raw_tx_packet/src/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LOG_MODULE_REGISTER(raw_tx_packet, CONFIG_LOG_DEFAULT_LEVEL);
1818
#include <zephyr/posix/sys/socket.h>
1919
#endif
2020

21+
#include <zephyr/net/ethernet.h>
2122
#include <zephyr/net/socket.h>
2223

2324
#include "net_private.h"
@@ -171,7 +172,7 @@ static int setup_raw_pkt_socket(int *sockfd, struct sockaddr_ll *sa)
171172
struct net_if *iface = NULL;
172173
int ret;
173174

174-
*sockfd = socket(AF_PACKET, SOCK_RAW, htons(IPPROTO_RAW));
175+
*sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
175176
if (*sockfd < 0) {
176177
LOG_ERR("Unable to create a socket %d", errno);
177178
return -1;

‎samples/wifi/shell/src/wifi_raw_tx_pkt_shell.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <stdlib.h>
12+
#include <zephyr/net/ethernet.h>
1213
#include <zephyr/shell/shell.h>
1314
#include <zephyr/posix/unistd.h>
1415
#include <zephyr/posix/sys/socket.h>
@@ -151,7 +152,7 @@ static int setup_raw_pkt_socket(int *sockfd, struct sockaddr_ll *sa)
151152
struct net_if *iface;
152153
int ret;
153154

154-
*sockfd = socket(AF_PACKET, SOCK_RAW, htons(IPPROTO_RAW));
155+
*sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
155156
if (*sockfd < 0) {
156157
LOG_ERR("Unable to create a socket %d", errno);
157158
return -1;

0 commit comments

Comments
 (0)
Please sign in to comment.