Question:
I am writing a UDP socket application using F-Stack, but I am facing an issue with the ff_recvfrom
call. The ff_recvfrom
function fails even after successfully creating and binding the socket. Below, I’ve provided the complete code, configuration file, terminal output, and DPDK status.
I am unsure whether the issue lies in my configuration or how the socket is being used.
my code :
// Here's the context:
I am using F-Stack, which is designed to accelerate network applications in user space by leveraging DPDK for packet processing.
The socket is successfully created with ff_socket and bound using ff_bind, but when I try to receive data with ff_recvfrom, it fails.
The application is supposed to listen for UDP packets on a specified IP and port.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <ff_api.h>
#define PORT 12345
#define BUFFER_SIZE 1024
#define IP_ADDRESS "192.168.1.3"
int main(int argc, char *argv[]) {
if (ff_init(argc, argv) < 0) {
fprintf(stderr, "F-Stack initialization failedn");
return -1;
}
int sock = ff_socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
perror("ff_socket failed");
return -1;
}
struct linux_sockaddr server_addr;
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sa_family = AF_INET;
*((uint16_t *)server_addr.sa_data) = htons(PORT);
inet_pton(AF_INET, IP_ADDRESS, server_addr.sa_data + 2);
if (ff_bind(sock, &server_addr, sizeof(server_addr)) < 0) {
perror("ff_bind failed");
ff_close(sock);
return -1;
}
printf("Listening for UDP packets on port %d...n", PORT);
char buffer[BUFFER_SIZE];
struct linux_sockaddr from_addr;
socklen_t from_len = sizeof(from_addr);
while (1) {
ssize_t received_bytes = ff_recvfrom(sock, buffer, BUFFER_SIZE - 1, 0,
(struct linux_sockaddr *)&from_addr, &from_len);
if (received_bytes < 0) {
perror("ff_recvfrom failed");
break;
}
buffer[received_bytes] = '';
printf("Received %ld bytes from %s:%d: %sn", received_bytes,
inet_ntoa(*(struct in_addr *)&from_addr.sa_data[4]), ntohs(*(uint16_t *)&from_addr.sa_data[2]), buffer);
}
ff_close(sock);
return 0;
}
Configuration File (config.ini):
[dpdk]
lcore_mask=0x3
channel=2
promiscuous=1
numa_on=0
tcore_mask=0x3
port_list=0
mem_size=4096
[port0]
addr=192.168.1.3
netmask=255.255.255.0
broadcast=192.168.1.255
gateway=192.168.1.254
#addr6 = fe80::a8:6501:12f1:3eb9
#prefix6 = 64
#gateway6 = fe80::1
[log]
level = debug
Terminal output :
Terminal
DPDK Status (dpdk-devbind.py –status):
Network devices using DPDK-compatible driver
============================================
0000:00:08.0 '82540EM Gigabit Ethernet Controller 100e' drv=uio_pci_generic unused=e1000
Network devices using kernel driver
===================================
0000:00:03.0 '82540EM Gigabit Ethernet Controller 100e' if=enp0s3 drv=e1000 unused=uio_pci_generic *Active*
No 'Baseband' devices detected
==============================
No 'Crypto' devices detected
============================
No 'DMA' devices detected
=========================
No 'Eventdev' devices detected
==============================
No 'Mempool' devices detected
=============================
No 'Compress' devices detected
==============================
No 'Misc (rawdev)' devices detected
===================================
No 'Regex' devices detected
===========================
Things I’ve Tried:
Checked if the IP address and port are being used by another application.
Reviewed the config.ini file settings for addr, netmask, and gateway.
Verified the DPDK status to make sure the correct network card is being used.
Issue:
The ff_recvfrom function fails, but the socket has been successfully created and bound.
The IP address used is 192.168.1.3.
The network card seems to be correctly set up.
Any help would be greatly appreciated!
user28941695 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1