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
2
votes
1 answer

Recvfrom working locally, but don't receive anything on random ports between executions

I'm working on a multithreaded UDP listener and I'm stuck in a problem that definitely surpasses me. So, I'm required to receive huge amounts of UDP packets in several ports. Locally, the best solution for me was to call non blocking recvfrom in as…
Jose M
  • 104
  • 1
  • 7
2
votes
1 answer

Unable to receive UDP broadcast messages

I am trying to put together a UDP monitor. I thought this would be straight forward, but everything I have tried has failed to work. Currently, I am working with a Microsoft code example. Due to my past failed attempts, I just copied the website's…
Fred
  • 1,054
  • 1
  • 12
  • 32
2
votes
1 answer

C - UDP receiving packets from unknown sources

I'm relatively new to programming C sockets and I have to solve a task in C. There are multiple nodes in the network, each with its own settings. Each node broadcasts its current settings every second. It also has to listen for these broadcasts from…
fugasjunior
  • 461
  • 1
  • 6
  • 22
2
votes
2 answers

Bad address received from recvfrom: why?

I'm writing a function that is supposed to do some operations and then return (using its arguments) the address of the device that is interacting with (i.e. that used sendto) the recvfrom inside the function. Here's how I call the function,…
Robb1
  • 4,587
  • 6
  • 31
  • 60
2
votes
1 answer

Results returned by socket.recvfrom()

I have this simple code in python-3.5 : import socket sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3)) raw_data, addr = sock.recvfrom(65536) recvfrom() returns data received on the socket in raw_data variable and a tuple in…
T. Decker
  • 137
  • 6
2
votes
2 answers

What's difference, passing directly sizeof() on function and a previous declared and initialized variable?

For example, I'd like to know if there is any significant difference or good/bad practice Doing this way: unsigned int length_addr; length_addr = sizeof(cli_addr); nbytes = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct…
jorge saraiva
  • 235
  • 4
  • 15
2
votes
1 answer

recvfrom() behaviour when multiple connections to socket

I've been mucking around with a program that sends packets to other copies of itself, and recvfrom has been behaving in a way I don't fully understand. Each instance of the program is set up on a different port (with knowledge of other instances'…
2
votes
2 answers

Recvfrom re-reading old data

I am programming a real-time networking system in C/C++ with Berkeley C sockets, which works on a tick-based interval. Every tick, the client program will read data from the socket with recvfrom(). The problem is that if the server did not send any…
ParityB1t
  • 77
  • 4
2
votes
1 answer

How to disable the timeout setsockopt() has set?

In the program I am developing, I've set a timeout using setsockopt() in order to prevent recvfrom() from blocking indefinitely. How can I disable the timeout? (I'm on Ubuntu)
Rapidturtle
  • 217
  • 1
  • 3
  • 13
2
votes
1 answer

Implementing Stop and wait with C & UDP, and what does cause 'resource temporarily unavailable'?

I am implementing stop&wait with c and udp socket programming. To simulate this protocol, I wrote two codes. This is my server.c file: #include #include #include #include #include #include…
jungyh0218
  • 558
  • 1
  • 4
  • 17
2
votes
4 answers

C sockets send UDP and process ICMP reply from router

I'm trying to send a UDP packet to a router with a time to live of 1, to then receive an ICMP time exceeded reply. So far I'm able to send the packet, but when my program gets to the recv part of the execution, it just hangs. I have an error check…
Hugo
  • 2,186
  • 8
  • 28
  • 44
2
votes
1 answer

Confusion over poll() and recvfrom()

I'm trying to implement a protocol in C that sends/receives raw Ethernet frames, and I've ran into some problems using poll() and recvfrom() in a Linux environment. I think my problem is mostly conceptual, so I'll avoid posting my code for now. I…
Matt K
  • 598
  • 5
  • 19
1
vote
1 answer

Boost UDP recvfrom not getting packets from network

I am trying to get data from a device which sends data using UDP using the code below: #include "Boost.UdpLayer.h" #include #include using namespace boost::asio; UdpLayer::UdpLayer(const std::string _ip, const int…
1
vote
1 answer

segmentation fault(core dump created) in recvfrom

I was writing a simple C code to create a lisening socket. The code is teh following: #include #include #include #include void main() { struct sockaddr_in server; struct sockaddr_in…
1
vote
1 answer

problems sending structure UDP Socket

I'm new to c++ and need help. I use an UDP server to receive structure however i have problem to read it , the client send a structure I call : ChannAccessReq so the structure is send and the server receive it with RECVFROM and I use a general…
et11enne
  • 377
  • 1
  • 11
1
2
3
8 9