aDTN lib  0.2
 All Data Structures Files Functions Variables
Data Structures | Macros | Functions
adtn.h File Reference

Data Structures

struct  sock_addr_t
 

Macros

#define OP_PROC_FLAGS   1
 
#define OP_LIFETIME   2
 
#define OP_BLOCK_FLAGS   3
 
#define OP_DEST   4
 
#define OP_SOURCE   5
 
#define OP_REPORT   6
 
#define OP_CUSTOM   7
 
#define OP_LAST_TIMESTAMP   8
 

Functions

int adtn_socket ()
 Creates a adtn sockets to send or recv information using the adtn platform with the default configuration. More...
 
int adtn_socket (const char *config_file)
 Creates a adtn sockets to send or recv information using the adtn platform. More...
 
int adtn_setcodopt (int fd, int option_name, const char *code)
 Associate codes to a socket. More...
 
int adtn_setcodopt (int fd, int option_name, const char *code, int from_file)
 Associate codes to a socket. More...
 
int adtn_setcodopt (int fd, int option_name, const char *code, int from_file, int replace)
 Associate codes to a socket. More...
 
int adtn_bind (int fd, sock_addr_t *addr)
 Associates the information given to the socket. More...
 
int adtn_close (int fd)
 Closes an adtn_socket and frees the memory associated to the socket. More...
 
int adtn_shutdown (int fd)
 Same as adtn_close(1), deleting also waiting data. More...
 
int adtn_rmcodopt (int fd, const int option)
 Removes an associated code from a socket. More...
 
int adtn_setsockopt (int fd, const int optname, const void *optval)
 Set message options. More...
 
int adtn_getsockopt (int fd, const int optname, void *optval, int *optlen)
 Get message options. More...
 
int adtn_sendto (int fd, const void *buffer, size_t buffer_l, const sock_addr_t addr)
 Sends a message over ADTN platform. More...
 
int adtn_recv (int fd, void *buffer, size_t len)
 Recive a message. More...
 
int adtn_recvfrom (int fd, void *buffer, size_t len, sock_addr_t *addr)
 Recive a message, filling sender information. More...
 

Function Documentation

int adtn_bind ( int  fd,
sock_addr_t address 
)

Associates the information given to the socket.

When adtn socket is created with adtn_socket(1) it exist in the space name but has no address associated. adtn_bind(2) associates the information specified in the structure sock_addr_t of the second argument to the socket represented by the file descriptor.

Parameters
fdThe file descriptor that identifies the adtn_socket. This value can be obtained calling adtn_socket(1).
addressA sock_addr_t structure containing information about the address that must be associated with the socket.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOENT cannot load the shared memory.
  • EACCES the program hasn't enough permissions to create bind the socket.
  • EADDRINUSE the address is already in use.
int adtn_close ( int  fd)

Closes an adtn_socket and frees the memory associated to the socket.

Closes an adtn_socket and frees the memory associated to the socket. The structures associated to the socket in adtn_bind(2) call are freed too.

Parameters
fdA file descriptor identifying the socket.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • EACCES the program hasn't enough permisions to eliminate the socket.
int adtn_getsockopt ( int  fd,
const int  optname,
void *  optval,
int *  optlen 
)

Get message options.

Parameters
fdA file descriptor identifying the socket.
optnamedetermines the option to set, the possible values are listed below.
optvalwhere to save the value obtined.
optlennumber of bytes to get, after calling is set to the number of bytes returned.
Returns
0 on succes, -1 on error. If the function fails errno is set.

Options available:

 OP_PROC_FLAGS       Get the flags for the primary block.
 OP_LIFETIME         Get the lifetime of the messages.
 OP_BLOCK_FLAGS      Get the flags for the rest of blocks.
 OP_DEST             Get the destination of the messages.
 OP_SOURCE           Get the source of the message.
 OP_REPORT           Get the report of the message.
 OP_CUSTOM           Get the custom value of the message.
 OP_LAST_TIMESTAMP   Get the last message timestamp.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOTSUP invalid option.
int adtn_recv ( int  fd,
void *  buffer,
size_t  len 
)

Recive a message.

Recive a message from adtn_socket. If at the moment of perform the call there are no messages adtn_recv(3) will block until can retrieve a message. After get a message it will be deleted from the socket queue.

Parameters
fdA file descriptor identifying the socket.
bufferarray where the mssg value will be stored.
lenThe maximum number of bytes that will be written into buffer.
Returns
The number of bytes received on succes or -1 on error. If the function fails errno is set.

errno can take the values below:

  • EINVAL invalid buffer or len.
  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOENT cannot load the shared memory.
int adtn_recvfrom ( int  fd,
void *  buffer,
size_t  len,
sock_addr_t addr 
)

Recive a message, filling sender information.

Recive a message from adtn_socket. If at the moment of perform the call there are no messages adtn_recvfrom(4) will block until can retrieve a message. After get a message it will be deleted from the socket queue. A sock_addr_t struct will be fill with sender information like ip or port.

Parameters
fdA file descriptor identifying the socket.
bufferarray where the mssg value will be stored.
lenThe maximum number of bytes that will be written into buffer.
addrAn empty structure that will be filled with information about the sender.
Returns
The number of bytes received on succes or -1 on error. If the function fails errno is set.

errno can take the values below:

  • EINVAL invalid buffer or len.
  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOENT cannot load the shared memory.
int adtn_rmcodopt ( int  fd,
const int  option 
)

Removes an associated code from a socket.

Allows to remove an associated code from a socket. See documentation of adtn_setcodopt(1) for more information.

Parameters
fdA file descriptor identifying the socket.
option_namedetermines what kind of code will be removed. If the code doesn't exist nothing happens.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • EINVAL invalid code option.
int adtn_sendto ( int  fd,
const void *  buffer,
size_t  buffer_l,
const sock_addr_t  addr 
)

Sends a message over ADTN platform.

Sends a message over ADTN platform. The fact that adtn_sendto call returns a success value doesn't mean that the message has been sent through the network. adtn_sendto(3) only puts the message in queue to be sent. The platform will manage the send through the network. In opportunistic networks the time until adtn_sendto(3) returns a succes value and the message is really send is impossible to determine.

Parameters
fdA file descriptor identifying the socket.
bufferA buffer with the message to send.
buffer_lthe length to send of the buffer.
addrsock_addr_t structure containing the destination information. Must contain, the application port and ip of the destination.
Returns
The number of bytes written on succes or -1 on error. If the function fails errno is set.

errno can take the values below:

  • EINVAL invalid address or null buffer.
  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOENT cannot load the shared memory.
  • EMSGSIZE message size is too big.
int adtn_setcodopt ( int  fd,
int  option_name,
const char *  code 
)

Associate codes to a socket.

Over ADTN platform the messages can carry codes with him to perform different tasks. This function allows to add code options to the socket. Each code linked with the socket will be added to outcoming messages sent through the socket. The kind of code associated to the socket is specified by the parameter option_name.

Parameters
fdA file descriptor identifying the socket.
option_namedetermines what kind of code will be associated to the socket. R_CODE will add a routing code. This code will be executed in each hop of the network to determine the next hop. L_CODE will add a life time code. This code will be executed in each node of the network to decide if the message is lapsed or not. P_CODE will add a prioritzation code. This code will affect only to the messages in other nodes that pertain to same application. Is not possible for a code to priorize messages from other applications.
codeThis parameter must contain the full code to associate to socket.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • EINVAL invalid code or from_file value.
  • EOPNOTSUPP existing code binded.
int adtn_setcodopt ( int  fd,
int  option_name,
const char *  code,
int  from_file 
)

Associate codes to a socket.

Over ADTN platform the messages can carry codes with him to perform different tasks. This function allows to add code options to the socket. Each code linked with the socket will be added to outcoming messages sent through the socket. The kind of code associated to the socket is specified by the parameter option_name.

Parameters
fdA file descriptor identifying the socket.
option_namedetermines what kind of code will be associated to the socket. R_CODE will add a routing code. This code will be executed in each hop of the network to determine the next hop. L_CODE will add a life time code. This code will be executed in each node of the network to decide if the message is lapsed or not. P_CODE will add a prioritzation code. This code will affect only to the messages in other nodes that pertain to same application. Is not possible for a code to priorize messages from other applications.
codeThis parameter must contain a filename where the code is stored or the full code to associate to socket. The content of this parameter is associated with parameter from_file.
from_fileIf is set to 1 the param code will contain a filename where the routing code is stored. If is set to 0 the param code must contain all code. Default value is 0.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • EINVAL invalid code or from_file value.
  • EOPNOTSUPP existing code binded.
int adtn_setcodopt ( int  fd,
int  option_name,
const char *  code,
int  from_file,
int  replace 
)

Associate codes to a socket.

Over ADTN platform the messages can carry codes with him to perform different tasks. This function allows to add code options to the socket. Each code linked with the socket will be added to outcoming messages sent through the socket. The kind of code associated to the socket is specified by the parameter option_name.

Parameters
fdA file descriptor identifying the socket.
option_namedetermines what kind of code will be associated to the socket. R_CODE will add a routing code. This code will be executed in each hop of the network to determine the next hop. L_CODE will add a life time code. This code will be executed in each node of the network to decide if the message is lapsed or not. P_CODE will add a prioritzation code. This code will affect only to the messages in other nodes that pertain to same application. Is not possible for a code to priorize messages from other applications.
codeThis parameter must contain a filename where the code is stored or the full code to associate to socket. The content of this parameter is associated with parameter from_file.
from_fileIf is set to 1 the param code will contain a filename where the routing code is stored. If is set to 0 the param code must contain all code. Default value is 0.
replaceIf is set to 1 and exists an older code associated to the socket it will be replaced. If is set to 0 and a code is already binded with the socket this function will return an error. Replace is 0 by default.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • EINVAL invalid code or from_file value.
  • EOPNOTSUPP existing code binded.
int adtn_setsockopt ( int  fd,
const int  optname,
const void *  optval 
)

Set message options.

In ADTN messages is posible specify the lifetime of the message and diferents options for headers. These options can be associated to a socket using this function. After calling it, all messages send through the socket will ahve the specified options.

Parameters
fdA file descriptor identifying the socket.
optnamedetermines the option to set, the possible values are listed below.
optvalthe value to set.
Returns
0 on succes, -1 on error. If the function fails errno is set.

Options available:

 OP_PROC_FLAGS       Set the flags for the primary block.
 OP_LIFETIME         Set the lifetime of the messages.
 OP_BLOCK_FLAGS      Set the flags for the rest of blocks.
 OP_DEST             Set the destination of the messages.
 OP_SOURCE           Set the source of the message.
 OP_REPORT           Set the report of the message.
 OP_CUSTOM           Set the custom value of the message.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOTSUP invalid option.
int adtn_shutdown ( int  fd)

Same as adtn_close(1), deleting also waiting data.

Closes an adtn_socket and frees the memory associated to the socket. The structures associated to the socket in adtn_bind(2) call are freed too. If some data are waiting to be readed it will be deleted.

Parameters
fdA file descriptor identifying the socket.
Returns
0 on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • ENOTSOCK the file descriptor is not a valid adtn_socket descriptor.
  • ENOENT cannot load the shared memory.
  • EACCES the program hasn't enough permisions to eliminate the socket
int adtn_socket ( )

Creates a adtn sockets to send or recv information using the adtn platform with the default configuration.

aDTN is divided in two parts, one is the API for developers that allow to use functions to send and receive messages. The other one is the core that manages and sends the messages.

The Core makes posible resilience to delay, disruptions and big taxes of errors. The implementation of the platform allow more than one core to cohexist in the same node(device).

Returns
a descriptor identifiyng the socket on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • EBUSY Cannot allocate socket.
  • ENOENT global configuration missing in configuration file.
  • EBADRQC data field missing in configuration file.
int adtn_socket ( const char *  config_file)

Creates a adtn sockets to send or recv information using the adtn platform.

aDTN is divided in two parts, one is the API for developers that allow to use functions to send and receive messages. The other one is the core that manages and sends the messages.

The Core makes posible resilience to delay, disruptions and big taxes of errors. The implementation of the platform allow more than one core to cohexist in the same node(device).

Parameters
config_fileThe configuration file path.
Returns
a descriptor identifiyng the socket on succes, -1 on error. If the function fails errno is set.

errno can take the values below:

  • EBUSY Cannot allocate socket.
  • ENOENT global configuration missing in configuration file.
  • EBADRQC data field missing in configuration file.