Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
udp_socket.c File Reference

Easily create and use UDP sockets. More...

#include "udp_socket.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
+ Include dependency graph for udp_socket.c:

Go to the source code of this file.

Macros

#define TRACE(type, fmt, args...)
 
#define TRACE_ERROR   1
 

Functions

int udp_socket_create (struct UdpSocket *sock, char *host, int port_out, int port_in, bool_t broadcast)
 Create UDP socket and bind it. More...
 
int udp_socket_send (struct UdpSocket *sock, uint8_t *buffer, uint32_t len)
 Send a packet from buffer, blocking. More...
 
int udp_socket_send_dontwait (struct UdpSocket *sock, uint8_t *buffer, uint32_t len)
 Send a packet from buffer, non-blocking. More...
 
int udp_socket_recv_dontwait (struct UdpSocket *sock, uint8_t *buffer, uint32_t len)
 Receive a UDP packet, dont wait. More...
 
int udp_socket_recv (struct UdpSocket *sock, uint8_t *buffer, uint32_t len)
 Receive one UDP packet, blocking. More...
 
int udp_socket_subscribe_multicast (struct UdpSocket *sock, const char *multicast_addr)
 
int udp_socket_set_recvbuf (struct UdpSocket *sock, int buf_size)
 

Detailed Description

Easily create and use UDP sockets.

Definition in file udp_socket.c.

Macro Definition Documentation

#define TRACE (   type,
  fmt,
  args... 
)

Definition at line 37 of file udp_socket.c.

Referenced by udp_socket_recv_dontwait(), and udp_socket_send().

#define TRACE_ERROR   1

Definition at line 38 of file udp_socket.c.

Referenced by udp_socket_recv_dontwait(), and udp_socket_send().

Function Documentation

int udp_socket_create ( struct UdpSocket sock,
char *  host,
int  port_out,
int  port_in,
bool_t  broadcast 
)

Create UDP socket and bind it.

Create UDP network (in/out sockets).

Parameters
[out]sockpointer to already allocated UdpSocket struct
[in]hostip address or hostname (hostname not possible if static linking)
[in]port_outoutput port
[in]port_ininput port (set to < 0 to disable)
[in]broadcastif TRUE enable broadcasting
Returns
-1 on error, otherwise 0

Definition at line 49 of file udp_socket.c.

References UdpSocket::addr_in, UdpSocket::addr_out, and UdpSocket::sockfd.

Referenced by bebop_front_camera_thread(), udp_arch_periph_init(), and viewvideo_init().

+ Here is the caller graph for this function:

int udp_socket_recv ( struct UdpSocket sock,
uint8_t buffer,
uint32_t  len 
)

Receive one UDP packet, blocking.

Receive one UDP packet.

Parameters
[in]sockpointer to UdpSocket struct
[out]bufferbuffer to write received packet to
[in]lenbuffer length in bytes (maximum bytes to read)
Returns
number of bytes received (-1 on error)

Definition at line 184 of file udp_socket.c.

References UdpSocket::addr_in, and UdpSocket::sockfd.

int udp_socket_recv_dontwait ( struct UdpSocket sock,
uint8_t buffer,
uint32_t  len 
)

Receive a UDP packet, dont wait.

Sets the MSG_DONTWAIT flag, returns 0 if no data is available.

Parameters
[in]sockpointer to UdpSocket struct
[out]bufferbuffer to write received packet to
[in]lenbuffer length in bytes
Returns
number of bytes received (-1 on error)

Definition at line 159 of file udp_socket.c.

References UdpSocket::addr_in, UdpSocket::sockfd, TRACE, and TRACE_ERROR.

int udp_socket_send ( struct UdpSocket sock,
uint8_t buffer,
uint32_t  len 
)

Send a packet from buffer, blocking.

Parameters
[in]sockpointer to UdpSocket struct
[in]bufferbuffer to send
[in]lenbuffer length in bytes
Returns
number of bytes sent (-1 on error)

Definition at line 119 of file udp_socket.c.

References UdpSocket::addr_out, UdpSocket::sockfd, TRACE, and TRACE_ERROR.

int udp_socket_send_dontwait ( struct UdpSocket sock,
uint8_t buffer,
uint32_t  len 
)

Send a packet from buffer, non-blocking.

Parameters
[in]sockpointer to UdpSocket struct
[in]bufferbuffer to send
[in]lenbuffer length in bytes
Returns
number of bytes sent (-1 on error)

Definition at line 140 of file udp_socket.c.

References UdpSocket::addr_out, and UdpSocket::sockfd.

Referenced by rtp_packet_send().

+ Here is the caller graph for this function:

int udp_socket_set_recvbuf ( struct UdpSocket sock,
int  buf_size 
)

Definition at line 203 of file udp_socket.c.

References UdpSocket::sockfd.

int udp_socket_subscribe_multicast ( struct UdpSocket sock,
const char *  multicast_addr 
)

Definition at line 193 of file udp_socket.c.

References UdpSocket::sockfd.