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

udp tftp: recvfrom() returns a positive but buff is empty

uint32_t ip=time_count.rbegin()->first; clientAddress=ip_to_struct.find(ip)->second; for(auto i=time_count.begin();i!=time_count.end();i++){ i->second+=timeOut_int-time_count.rbegin()->second; …
Micha Blum
  • 15
  • 5
0
votes
1 answer

UDP server consuming high CPU

I am observing high CPU usage in my UDP server implementation which runs an infinite loop expecting 15 1.5KB packets every milliseconds. It looks like below: struct RecvContext { enum { BufferSize = 1600 }; RecvContext() { …
Sayantan Ghosh
  • 998
  • 2
  • 9
  • 29
0
votes
1 answer

recvfrom returning errno 14 in debug mode with GDB

I have a code something like this. where recvfrom works fine if i run the code normally. but when i run the code with GDB, recvfrom doesn't wait for 2 seconds and instantly throwing errno 14. == char buf[sizeof(FSME_START)] = { 0 }; /* open socket…
pgoyal
  • 91
  • 1
  • 3
0
votes
0 answers

UDP Client Send & Receive Data from Server Python

I am trying to write a UDP client that can both send and receive data. However, the only way I can get it to work is to repeatedly create and then close the socket each time I want to send or receive data. I am guessing this is probably not the…
0
votes
0 answers

How can I recvive the ICMP packet (ICMP_PORT_UNREACH)?

I can find udp packet and ICMP packet in Wireshark, but recvfrom() return -1 when I use it to recvive ICMP packet in my program. I use GetLastError() and the error code is 10022. send_sa.sin_family = AF_INET; send_sa.sin_addr.s_addr =…
zawalida
  • 21
  • 3
0
votes
0 answers

recvfrom icmp packet without ip header

I am trying to get an ICMP packet using the recvfrom() function. The function receives a packet including the IP header, I only need the ICMP portion. Is it possible to somehow configure the socket so that recvfrom() receives only an ICMP packet…
Ivan Ivanovich
  • 880
  • 1
  • 6
  • 15
0
votes
2 answers

detect when to stop receiving data ( recfrom() ) from server when using UDP for file tranfer (sockets API)

I am trying to implement a UDP version for file transfer ( for learning purposes, i do not care about reliability :) ). Currently in the TCP version, I have the following code on the server side : while (1) { /* read file in chunks of 256 bytes…
rohit_r
  • 623
  • 1
  • 6
  • 18
0
votes
1 answer

What's the read logic when I call recvfrom() function in C/C++

I wrote a C++ program to create a socket and bind on this socket to receive ICMP/UDP packets. The code I wrote as following: while(true){ recvfrom(sockId, rePack, sizeof(rePack), 0, (struct sockaddr *)&raddr, (socklen_t *)&len); …
Jack
  • 5,540
  • 13
  • 65
  • 113
0
votes
0 answers

c - sendto/recvfrom not getting correct information on some end

I'm coding a server/client TCP implementation in c for class and I'm stuck, unsure why I'm not getting the correct data on one of the ends of my implementation. This only needs to work on a loopback address so I'm not too concerned with it working…
0
votes
0 answers

why is recvfrom() not updating the received message

I am using recvfrom inside a while loop that also performs other non related functions, I am using UDP to send either 1 or 0 continuously from a different machine. The message is received ok but when I change the message from 1 to 0 or viceversa…
jm96
  • 57
  • 5
0
votes
0 answers

Client receiving wrong message from server (UDP)

I am writing a private chat using UDP, but I have some problems while implementing the registration service. When the client writes the ID and password he wants to use, the server checks if the ID already exists(IDs and password are saved in a…
0
votes
1 answer

Is there any C socket function, which can look for datagrams from a specific UDP client?

The server I am building uses the UDP transport layer protocol. I have a scenario where multiple clients can send datagrams to my server. But each client may send the data across multiple datagrams, and before starting to process the data, I need to…
m0hithreddy
  • 1,752
  • 1
  • 10
  • 17
0
votes
1 answer

Unable to use a structure to store and later on print udp data usin recvfrom

I'm trying to use the following struct to put my received data in: typedef struct packet { uint8_t magic; uint8_t version; uint16_t body_length; char *body; } packet; This is the printing function: void displayPacket (struct packet p){ …
VDS-Atomic
  • 115
  • 1
  • 11
0
votes
1 answer

Unexpected behavior parsing recvfrom() message from UDP socket

Currently working with UDP socket, I am stucked trying to understand the following situation. A reception buffer has been defined as follow: char buf[1024]; ... memset(&buf, 0, sizeof(buf)); & is fullfilled by invoking recvfrom() size =…
ogs
  • 1,139
  • 8
  • 19
  • 42
0
votes
1 answer

How to get source IP address of a UDP packet using recvfrom in nasm?

I'm writing a UDP socket in nasm and I'm using the recvfrom system call to receive a UDP packet from a client. I can successfully get the message sent, but I would like to send back to the client an answer. The problem is that I can't extract the…
1 2 3
8 9