FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

papstdfrisco wrote on Friday, January 26, 2018:

Hi All,

I’m looking to send raw Ethernet packets
Under Linux something in the vein of:

// Open our raw socket
if ((m_fd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1)
LogErr(VB_CHANNELOUT, “Error creating raw socket: %s\n”, strerror(errno));
return 0;

if (sendto(m_fd, m_buffer_0101, m_buffer_0101_len, 0, (struct sockaddr*)&m_sock_addr, sizeof(struct                                sockaddr_ll)) < 0)
	LogErr(VB_CHANNELOUT, "Error sending 0x0101 packet: %s\n", strerror(errno));
	return 0;

where m_buffer is:
// Setup 0x0101 packet data
m_buffer_0101_len = sizeof(struct ether_header) + 98;
m_buffer_0101 = (char *)calloc(m_buffer_0101_len, 1);
if (!m_buffer_0101)
LogErr(VB_CHANNELOUT, “Error allocating m_buffer_0101\n”);
return 0;

memset(m_buffer_0101, 0, m_buffer_0101_len);
m_eh = (struct ether_header *)m_buffer_0101;
m_eh->ether_type = htons(0x0101);

m_sock_addr.sll_ifindex = m_if_idx.ifr_ifindex;
m_sock_addr.sll_halen = ETH_ALEN;
memcpy(m_sock_addr.sll_addr, m_eh->ether_dhost, 6);

 Essentially a src & dest mac addr and a protocal type and the data....

I have not been able to determine if this is possible with FreeRTOS +TCP/+UDP or any setup therein.

Hopefully someone here will know either how to do this or if I'm barking up the wrong tree.


rtel wrote on Friday, January 26, 2018:

The user documentation only describes the interface to the TCP/IP stack, rather than directly to the Ethernet. There are a few function intended for use by people who are porting the TCP stack to a different platform though, and it is possible, with a bit of fiddling, you may be able to do what you want with those:

papstdfrisco wrote on Friday, January 26, 2018:

Thanks for the quick response.
However, I don’t see how this will help me.
It appears to still call the same stack functions and I don’t see the stuff there that will handle the raw packets.
Now it’s clear that I may not understand what’s going on, but that’s why I’m asking.
I have found neither AF_PACKET (which I understand is a Linux term) nor SOCK_RAW in the code anywhere - or anything that looks like it will setup things like those will.

So, is there another way to get from point a to b?


papstdfrisco wrote on Friday, January 26, 2018:

So I see this:
xDomain Must be set to FREERTOS_AF_INET. [no other choices}

xType Set to FREERTOS_SOCK_STREAM to create a TCP socket.
Set to FREERTOS_SOCK_DGRAM to create a UDP socket.
No other values are valid. [no other choices -> SOCKRAW]

xProtocol Set to FREERTOS_IPPROTO_TCP to create a TCP socket.
Set to FREERTOS_IPPROTO_UDP to create a UDP socket.
No other values are valid. [no other choices -> IPPROTORAW]

So I doubtfull that the stuff exists to do the raw packets.

So this begs the question: how likely is it for this functionality to be added?

heinbali01 wrote on Saturday, January 27, 2018:

You are right, there is no support yet for exchanging RAW Ethernet packets.
Just curiosity: why would you like to have that feature? What type of packets do you actually want to send?
When you send RAW packets, you probably also want to receive responses in a RAW way, or not?
It shouldn’t be too difficult to add both sending and reception of RAW packets.