Questions tagged [recvfrom]

The recvfrom() call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented.

The recvfrom() call is used to receive messages from a , and may be used to receive data on a socket whether or not it is connection-oriented.

Synopsis

#include <sys/types.h>
#include <sys/socket.h>

ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);

Description

sockfd   -- the socket file descriptor to read from  
buf      -- The pointer to the memory location where the data has to be stored   
len      -- The length of the data to be read  
flags    -- Various flags to modify the socket file descriptor  
src_addr -- The memory location where the source address of the message will be filled  
addrlen  -- addrlen is a value-result argument, which the caller should initialize 
before the call to the size of the buffer associated with src_addr, and modified on
return to indicate the actual size of the source address.

Return Value

recvfrom() return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.

Errors

There are some standard errors generated by the socket layer. Additional errors may be generated and returned from the underlying protocol modules. For the complete list, see the manual pages.

126 questions
7
votes
1 answer

socket python : recvfrom

I would like to know if socket.recvfrom in python is a blocking function ? I couldn't find my answer in the documentation If it isn't, what will be return if nothing is receive ? An empty string '' ? In the other case, if in fact, it is blocking,…
AnonBird
  • 570
  • 13
  • 27
5
votes
0 answers

recvmmsg/recv/recvfrom blocks under high load

We have an application on Centos 6 that calls recvmmsg() on a multicast address to read 1024 UDP packets at a time. When we run multiple instances of this application on the same box (all listening to the same traffic), sometimes this call will…
Tars AC
  • 79
  • 2
5
votes
2 answers

UDP recvfrom query

int recvfrom(SOCKET socket, char * buffer, int buflen, int flags, struct sockaddr * from, int * fromlen); I know…
pa1
  • 778
  • 3
  • 11
  • 26
4
votes
1 answer

Linux recvfrom() can't receive traffic that Wireshark can see

I'm working with a piece of hardware that generates a data stream packaged in UDP packets. These are sent out on a dedicated 40Gb Ethernet link to another piece of receiver hardware. There are no hubs or switches involved, just a single sender and…
MarkT
  • 71
  • 3
3
votes
2 answers

Formal Parameters difference between sendto() and recvfrom() in C

I am using recvfrom() and sendto() for receiving and sending UDP packets. I have noticed that recvfrom() as last parameter requires a pointer to the variable storing the length of server address while sendto() requires the variable that stores the…
3
votes
1 answer

Why is UDP Multicast Server not responding?

I am trying to implement basic UDP multicast client and server on Linux. The server, based on a message sent by the client, is supposed to reply with system parameters (kinda like SNMP). Right now, I am testing with a single server. After running…
psk1993
  • 33
  • 5
3
votes
0 answers

SO_RCVTIMEO timeout value is not taking effect in recv_from API

I tried to use SO_RCVTIMEO option to timeout when there is no data in recvfrom API. But this is not taking effect, and the code is stuck when there is no data from the source. I even tried using recv instead of recvfrom. Still the same issue. Please…
3
votes
1 answer

What byte order does recvfrom() save src_addr as?

size_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) In what byte order is the src_addr argument written? Network or host? I couldn't find this in the recvfrom man page or a search through…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
2
votes
2 answers

How does recvfrom know when to stop reading packets?

in C recvfrom can be used to read UDP messages form a socket as such: int length = recvfrom(socket, buffer, max_length, 0, NULL, 0); max_length only tells the maximum number of bytes the buffer can hold, and not the actual length of course. Assume…
Dan
  • 2,694
  • 1
  • 6
  • 19
2
votes
0 answers

file transfer using stop and wait protocol and udp protocol in C

I want to send a file using UDP with stop and wait protocol. I have a client and server code that is working fine with a single input string. I was trying to change the code for file transfer but no success. Can anyone help me with minimal changes…
2
votes
1 answer

Why does recvfrom() returns wrong address of sender?

This simple UDP client: #include #include #include #include #include #include #include #define PORT 9877 #define BSIZE 256 #define ADDRSTRLEN 19 static char…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
2
votes
4 answers

Avoid accumulation of data in udp socket or read newest data from udp socket

I am trying to send data continuously from a c++ code to a python code. I used udp sockets to send the data. The rate of sending is at a faster rate than the receiving rate as it is a simple sensor code. So the data sent is accumulated in the…
2
votes
1 answer

winsock2: RAW SOCKET recvfrom() returns Error 10022 (Invalid Argument)

I'm trying to handle incoming network packets with RAW SOCKET in Windows 10. When I call recvfrom() function it returns -1 value. WSAGetLastError is 10022. Microsoft Docs page give me the following description: WSAEINVAL: 10022 Invalid argument. …
Raphael
  • 114
  • 6
2
votes
1 answer

IPv6 Server in c - recvfrom failed

i have written a small c-program for an IPv6 server with winsock2.h When I run the program in Visual Studio, I get the following message all the time: recvfrom failed I just can't find the error in the recvfrom function. Maybe someone can see why my…
2
votes
1 answer

RecvFrom missing a few UDP packets

OK, I am aware that UDP doesn't guarantee delivery, but I had hoped to catch all by having the RecvFrom in a thread with TimeCritical priority and just quickly moving the incoming messages into a buffer. However, when the rate of messages get up to…
Jens
  • 37
  • 1
  • 4
1
2 3
8 9