---
name: "socket_recv4"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/socket_recv4"
---

# socket\_recv4(3)

receive a UDP datagram

## NAME

socket\_recv4 - receive a UDP datagram

## SYNTAX

**#include \<libowfat/socket.h\>**

ssize\_t **socket\_recv4**(int *s*, char\* *buf*, size\_t *len*,\
                  char *ip*\[4\],uint16\* *port*);

## DESCRIPTION

socket\_recv4 receives up to *len* bytes starting at *buf* from a UDP datagram coming in on the socket *s*.  It writes the UDP port to *port* and the IP address to *ip*, and returns the number of bytes actually received (or -1 if anything went wrong).

## RETURN VALUE

socket\_recv4 returns the number of bytes in the datagram if one was received.  If not, it returns -1 and sets errno appropriately.

## EXAMPLE

  \#include \<libowfat/socket.h\>

  int *s*;\
   char *ip*\[4\];\
   uint16 *p*;\
   char buf\[1000\];\
   int len;

  *s* = socket\_tcp4();\
   socket\_bind4(s,ip,p);\
   len = socket\_recv4(s,buf,sizeof(buf),ip,&p);

## SEE ALSO

[socket\_recv6(3)](/socket_recv6/3.md)
