HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/qlibs/man/socket_recv.3
.TH qlibs: socket_recv 3
.SH NAME
socket_recv \- receive UDP datagrams over IPv4/IPv6 connections
.SH SYNTAX
.B #include \(dqsocket_if.h\(dq

int \fBsocket_recv\fP(int \fIs\fR, const char *\fIbuf\fR, unsigned int \fIlen\fR,
                    const char \fIip\fR[16], uint16 *\fIport\fR, uint32 *\fIscope_id\fR);
.SH DESCRIPTION
.B socket_recv 
reads \fIlen\fR bytes starting at \fIbuf\fR in a UDP datagram 
over the socket \fIs\fR while providing information about the 
remote IP address \fIip\fR and the UDP \fIport\fR and
the perhaps \fIscope_id\fR of the receiving interface.

You can call 
.B socket_recv 
without calling 
.BR socket_bind .  
This has the effect as first calling 
.B socket_bind 
with IP address :: and port 0.
.SH RETURN VALUE
.B socket_recv
returns 
.IR 0 ,
otherwise
.I -1 
and sets 
.I errno 
appropriately.
.SH EXAMPLE
  #include <socket_if.h>
  #include <ip.h>

  int \fIs\fR;
  char \fIlocalip\fR[16];
  char \fIremoteip\fR[16];
  uint16 \fIp\fR, \fIport\fR;
  uint32 \fIscope_id\fR;
  unsigned int \fIlen\fR;
  int \fIr\fR;
  char buf[MTUSIZE+1];

  s = socket_udp();
  socket_bind_reuse(s,localip,p,0);
  r = socket_recv(s,buf,len,remoteip,&port,&scope_id);
.SH SEE ALSO
socket_if(3), 
socket_info(3), 
socket_bind(3), 
socket_connect(3)
socket_send(3), 
socket_setup(3), 
socket_tcp(3), 
socket_udp(3)