Manpage logo

socket_send -

ROUTINES  SYNTAX  DESCRIPTION  RETURN VALUE  EXAMPLE  SEE ALSO 

ROUTINES

socket_send − sending data over a UDP socket

SYNTAX

#include "socket_if.h"

int socket_send4(int s,const char *buf,unsigned int len,
const char ip[4],uint16 port);
int socket_send6(int s,const char *buf,unsigned int len,
const char ip[16],uint16 port,uint32 scope_id);
int socket_send(int s,const char *buf,unsigned int len,
const char ip[16],uint16 port,uint32 scope_id);

DESCRIPTION

socket_send4 sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IPv4 address ip.

socket_send6 sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IPv6 address ip and perhaps using scope_id as outging interface.

For link-local IPv6 (LLU) addresses scope_id specifies the outgoing interface index. socket_id can be queried for the given name of the interface (e.g. "eth0") by means of socket_getifidx. scope_id should normally be set to 0 except for link local IPv6 addresses

socket_send sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IP address ip and perhaps using scope_id as outging interface.

You can call socket_send* without calling socket_bind*. This has the effect as first calling socket_bind4 with IP address 0.0.0.0 and port 0 or socket_bind6 with IP address :: and port 0.

RETURN VALUE

socket_send* returns 0 if the datagram was sent successfully. If not, it returns -1 and sets errno appropriately.

EXAMPLE

#include <socket_if.h>

int s;
char ip[4];
uint16 p;

s = socket_udp();
socket_bind(s,ip,p);
socket_send(s,"hello, world",12,ip,p,0);

SEE ALSO

socket_if(3), socket_info(3), socket_bind(3), socket_connect(3), socket_recv(3), socket_setup(3), socket_tcp(3), socket_udp(3)


Updated 2026-06-01 - jenkler.se | uex.se