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
1
vote
0 answers

Python socketcan interface for J1939 transport protocol

Using python with socketcan in the J1939 protocol, it seems that recvfrom() does not return the interface when the data is more than 8 bytes. In the J1939 protocl, when there is more than 8 data bytes, multiple CAN messages are sent since a CAN…
1
vote
2 answers

What is the maximum len to recv/recvfrom

When I listen to TCP or UDP socket with ssize_t recv(int sockfd, void *buf, size_t len, int flags); Or ssize_t recvfrom(int sockfd, void *buf, size_t len, int flag , struct sockaddr *src_addr, socklen_t *addrlen); There is argument called len In…
Keystone
  • 165
  • 1
  • 9
1
vote
1 answer

Recvfrom and Wireshark

I communicate with a server, i send a message with a socket (sock_raw..), it's works fine, the client (me), send the message, the server receive the right message, but when the server need to send it to me (the client), the client don't retrieve the…
Zahreddine Laidi
  • 560
  • 1
  • 7
  • 20
1
vote
1 answer

How to use raw socket send and receive arp package in python

I need to "send and receive ARP packet in one program". I'm aware that the scapy packet is already do it quiet well, and you just need to pass some argument. However, I want to know much further than just pass argument. So, if you recommend scapy as…
Alopex
  • 131
  • 8
1
vote
2 answers

Are sockets allowed to be global in C?

I'm making a program that is constantly checking to receive and send data through a socket, and I have the socket declared globally and it's used inside 2 thread functions. I setup the socket in main(), and one thread uses recvfrom using the socket…
Caleb lee
  • 43
  • 7
1
vote
0 answers

Recvfrom windows function doesn’t receive all packets from the OS

I wrote a c++ windows process (Win7 if it matters) that can send and receive packets using sendto and recvfrom, but unfortunately not all of the packets are read from the socket. Both of the computers are directly connected and transmitting…
Shani.M
  • 29
  • 3
1
vote
2 answers

Is it possible to receive UDP packets only from a specified source address?

I know that recvfrom can return the source address via a pointer argument so that I can check whether the received packet is from an address I'm interested in. Is there any way other than checking the source address only after a packet has already…
xiaokaoy
  • 1,608
  • 3
  • 15
  • 27
1
vote
1 answer

TCP handshake via raw sockets, why recvfrom hangs?

I am trying to implement handshaking functionality. I am sending SYN packet and server responds via ACK packet. For getting server response i have used recvfrom function which is hang. Here is my code. import socket, sys from struct import * import…
user1886376
1
vote
4 answers

Why does recvfrom care about who the data comes from

So, I'm creating a server in C which uses UDP, and I want to listen for incoming packets from many sources. Therefore, when I call ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict), the 5th parameter,…
Jerome Carter
  • 237
  • 1
  • 4
  • 18
1
vote
2 answers

recvfrom fills the buffer with zeros

I am trying to implement distance vector routing over udp. I have the following structs: struct cost_info { uint8_t id; uint8_t pad; uint16_t cost; }__attribute__((__packed__)); struct advertisement_packet { uint8_t type; …
Jake Sandler
  • 162
  • 1
  • 8
1
vote
1 answer

Receiving empty payload with recvfrom when using SOCK_DGRAM?

Is it possible to receive any empty payload with recvfrom() with SOCK_DGRAM based socket? The server is only interested in the client header to send it back a message (i.e. single message, send only protocol).
1
vote
0 answers

How to determine how much of the socket receive buffer is filled?

In my application, I am trying to send and receive datagrams to different servers as quickly as possible. I noticed that increasing the sending rate is greatly lowering the percentage of responses I receive for a given # of sends. I believe one…
Joe Johnson
  • 177
  • 1
  • 7
1
vote
1 answer

recvfrom() unblocks when a udp packet is received but returns 0 as size of read bytes (using oscpack)

this is a test to create some temporary interprocess communication between applications using sockets. These applications will later be running on different systems , using a customized embedded communication system, but for now the latter is not…
nass
  • 1,453
  • 1
  • 23
  • 38
1
vote
0 answers

socket udp multiple unicast receiver threads (resuseaddr/port)

With REUSEADDR/REUSEPORT one can create 2 identical sockets bound to the same address and port in a machine. Is it possible to receive the same data on the 2 sockets? My case is that a defined udp port number will produce data on a network. In my…
TomCam
  • 41
  • 3
1
vote
2 answers

C++ recvfrom timeout

I need to implement following behavior: when server starts, it should check for existing servers using broadcast. Then it waits for answer. But, how to set any timeout for waiting? int optval = 1; char buff[BUFF_SIZE]; SOCKADDR_IN addr; int length…
Evgeniy175
  • 324
  • 1
  • 9
  • 23
1 2
3
8 9