Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
UDP_OPEN_MEM(3)		   libdill Library Functions	       UDP_OPEN_MEM(3)

NAME
       udp_open_mem - opens an UDP socket

SYNOPSIS
	      #include <libdill.h>

	      int udp_open_mem(
		  struct ipaddr* local,
		  struct ipaddr* remote,
		  struct udp_storage* mem);

DESCRIPTION
       UDP  is	an  unreliable message-based protocol defined in RFC 768.  The
       size of the message is limited.	The protocol has no initial or	termi-
       nal handshake.  A single	socket can be used to different	destinations.

       This function creates an	UDP socket.

       This  function allows to	avoid one dynamic memory allocation by storing
       the object in user-supplied memory.  Unless  you	 are  hyper-optimizing
       use udp_open instead.

       local: IP address to be used to set source IP address in	outgoing pack-
       ets.   Also,  the socket	will receive packets sent to this address.  If
       port in the address is set to zero an ephemeral port will be chosen and
       filled into the local address.

       remote: IP address used as default destination  for  outbound  packets.
       It  is  used  when  destination	address	in udp_send function is	set to
       NULL.  It is also used by msend and mrecv functions which  don't	 allow
       to  specify the destination address explicitly.	Furthermore, if	remote
       address is set, all the packets arriving	from different addresses  will
       be silently dropped.

       mem:  The  structure to store the newly created object in.  It must not
       be deallocated before the object	is closed.

       To close	this socket use	hclose function.

       This function is	not available  if  libdill  is	compiled  with	--dis-
       able-sockets option.

RETURN VALUE
       In  case	 of  success the function returns newly	created	socket handle.
       In case of error	it returns -1 and sets errno to	one of the values  be-
       low.

ERRORS
        EADDRINUSE: The local address is already in use.

        EADDRNOTAVAIL:	 The specified address is not available	from the local
	 machine.

        EINVAL: Invalid argument.

        EMFILE: The maximum number of file descriptors	in the process are al-
	 ready open.

        ENFILE: The maximum number of file descriptors	in the system are  al-
	 ready open.

        ENOMEM: Not enough memory.

EXAMPLE
	      struct ipaddr local;
	      ipaddr_local(&local, NULL, 5555, 0);
	      struct ipaddr remote;
	      ipaddr_remote(&remote, "server.example.org", 5555, 0, -1);
	      int s = udp_open(&local, &remote);
	      udp_send(s1, NULL, "ABC",	3);
	      char buf[2000];
	      ssize_t sz = udp_recv(s, NULL, buf, sizeof(buf), -1);
	      hclose(s);

SEE ALSO
       hclose(3) mrecv(3) mrecvl(3) msend(3) msendl(3) udp_open(3) udp_recv(3)
       udp_recvl(3) udp_send(3)	udp_sendl(3)

libdill							       UDP_OPEN_MEM(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=udp_open_mem&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help