/*
* File Name: udp.h
* Author: Jade Cheng
* Date: March 29, 2009
* Course: ICS 451
* Assignment: Project 2
*/
#ifndef UDP_H_
#define UDP_H_
/**
* Returns the socket descriptor for the UDP socket. This is needed by the
* select function.
*
* @return The socket descriptor.
*/
extern int udp_fd(void);
/**
* Receives a datagram from the UDP socket.
*
* @param buffer The destination buffer.
* @param max The maximum size of the data stored into the buffer.
* @param actual The actual number of bytes stored into the buffer.
* @param from The address and port of the peer.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/
extern int udp_recv(
void * buffer,
size_t max,
size_t * actual,
peer_t * from);
/**
* Sends a datagrame through the UDP socket.
*
* @param to The peer address and port.
* @param buffer The buffer to send.
* @param size The number of bytes to send.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/
extern int udp_send(const peer_t * to, const void * buffer, size_t size);
/**
* Creates the UDP socket and starts listening on a given port.
*
* @param port The port number.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/
extern int udp_start(u_short port);
/**
* Stops listening and closes the UDP socket.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/
extern int udp_stop(void);
#endif /* UDP_H_ */