aDTN lib  0.2
 All Data Structures Files Functions Variables
adtn.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014 SeNDA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 
19 #include <errno.h>
20 #include <stdint.h>
21 #include <sys/types.h>
29 typedef struct {
30  int adtn_port;
31  // sem_t *semaphore; ///< semaphore to add bundles to queue
32  char *id;
33 } sock_addr_t;
34 
36 typedef struct {
37  uint32_t lifetime;
38  uint32_t proc_flags;
39  uint32_t block_flags;
40  char *report;
41  char *custom;
42  char *dest;
43  char *source;
44 } sock_opt_t;
45 
46 typedef struct {
47  int fd;
48  int option_name;
49  const char *code;
50  int from_file;
51  int replace;
52 } set_opt_args;
53 
54 typedef struct {
55  const char *config_file;
56 } socket_params;
57 
58 typedef struct {
59  uint64_t last_timestamp;
60 } sock_get_t;
63 /* Option codes */
64 #define OP_PROC_FLAGS 1
65 #define OP_LIFETIME 2
66 #define OP_BLOCK_FLAGS 3
67 #define OP_DEST 4
68 #define OP_SOURCE 5
69 #define OP_REPORT 6
70 #define OP_CUSTOM 7
71 #define OP_LAST_TIMESTAMP 8
72 
74 /* MACROS */
75 #ifndef DOX
76 #define adtn_setcodopt(...) adtn_var_setcodopt((set_opt_args){__VA_ARGS__});
77 #define adtn_socket(...) adtn_var_socket((socket_params){__VA_ARGS__});
78 #endif
79 
81 /* FUNCTIONS */
82 
84 int adtn_var_socket(socket_params in);
86 #ifdef DOX
87 int adtn_socket();
88 int adtn_socket(const char *config_file);
89 int adtn_setcodopt(int fd, int option_name, const char *code);
90 int adtn_setcodopt(int fd, int option_name, const char *code, int from_file);
91 int adtn_setcodopt(int fd, int option_name, const char *code, int from_file, int replace);
92 #endif
93 
94 int adtn_bind(int fd, sock_addr_t *addr);
95 int adtn_close(int fd);
96 int adtn_shutdown(int fd);
97 
98 int adtn_rmcodopt(int fd, const int option);
100 int adtn_var_setcodopt(set_opt_args in);
103 int adtn_setsockopt(int fd, const int optname, const void *optval);
104 int adtn_getsockopt(int fd, const int optname, void *optval, int *optlen);
105 
106 int adtn_sendto(int fd, const void *buffer, size_t buffer_l, const sock_addr_t addr);
107 int adtn_recv(int fd, void *buffer, size_t len);
108 int adtn_recvfrom(int fd, void *buffer, size_t len, sock_addr_t *addr);
109 
110 
int adtn_bind(int fd, sock_addr_t *addr)
Associates the information given to the socket.
int adtn_rmcodopt(int fd, const int option)
Removes an associated code from a socket.
int adtn_recv(int fd, void *buffer, size_t len)
Recive a message.
int adtn_close(int fd)
Closes an adtn_socket and frees the memory associated to the socket.
int adtn_getsockopt(int fd, const int optname, void *optval, int *optlen)
Get message options.
int adtn_port
Port to identify the own application.
Definition: adtn.h:30
int adtn_recvfrom(int fd, void *buffer, size_t len, sock_addr_t *addr)
Recive a message, filling sender information.
int adtn_setsockopt(int fd, const int optname, const void *optval)
Set message options.
int adtn_shutdown(int fd)
Same as adtn_close(1), deleting also waiting data.
int adtn_socket()
Creates a adtn sockets to send or recv information using the adtn platform with the default configura...
int adtn_setcodopt(int fd, int option_name, const char *code)
Associate codes to a socket.
int adtn_sendto(int fd, const void *buffer, size_t buffer_l, const sock_addr_t addr)
Sends a message over ADTN platform.
char * id
IP addres that is associated with the socket.
Definition: adtn.h:32