GNUnet  0.11.x
gnunet_network_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
31 #ifndef GNUNET_NETWORK_LIB_H
32 #define GNUNET_NETWORK_LIB_H
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0 /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41 
42 
47 
48 
53 {
57  int nsds;
58 
62  fd_set sds;
63 
64 };
65 
66 #include "gnunet_disk_lib.h"
67 #include "gnunet_time_lib.h"
68 
75 int
76 GNUNET_NETWORK_test_pf (int pf);
77 
78 
88 char *
89 GNUNET_NETWORK_shorten_unixpath (char *unixpath);
90 
91 
101 void
102 GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un);
103 
104 
115 struct GNUNET_NETWORK_Handle *
117  struct sockaddr *address,
118  socklen_t *address_len);
119 
120 
127 struct GNUNET_NETWORK_Handle *
129 
130 
138 int
140  int doBlock);
141 
142 
151 int
153  const struct sockaddr *address,
154  socklen_t address_len);
155 
162 int
164 
165 
171 void
173 
174 
183 int
185  const struct sockaddr *address,
186  socklen_t address_len);
187 
188 
199 int
201  int level,
202  int optname,
203  void *optval,
204  socklen_t *optlen);
205 
206 
214 int
216  int backlog);
217 
218 
225 ssize_t
227  GNUNET_NETWORK_Handle *desc);
228 
229 
240 ssize_t
242  void *buffer,
243  size_t length,
244  struct sockaddr *src_addr,
245  socklen_t *addrlen);
246 
247 
256 ssize_t
258  void *buffer,
259  size_t length);
260 
261 
271 int
273  struct GNUNET_NETWORK_FDSet *wfds,
274  struct GNUNET_NETWORK_FDSet *efds,
276 
277 
286 ssize_t
288  const void *buffer,
289  size_t length);
290 
291 
303 ssize_t
305  const void *message,
306  size_t length,
307  const struct sockaddr *dest_addr,
308  socklen_t dest_len);
309 
310 
321 int
323  int level,
324  int option_name,
325  const void *option_value,
326  socklen_t option_len);
327 
328 
336 int
338  int how);
339 
340 
350 int
352 
353 
364 struct GNUNET_NETWORK_Handle *
365 GNUNET_NETWORK_socket_create (int domain,
366  int type,
367  int protocol);
368 
369 
375 void
377 
378 
385 void
387  const struct GNUNET_NETWORK_Handle *desc);
388 
389 
397 int
399  const struct GNUNET_NETWORK_Handle *desc);
400 
401 
408 void
410  const struct GNUNET_NETWORK_FDSet *src);
411 
412 
419 void
421  const struct GNUNET_NETWORK_FDSet *from);
422 
423 
430 int
431 GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc);
432 
433 
440 struct sockaddr*
442 
443 
450 socklen_t
452 
453 
461 void
463  const fd_set *from,
464  int nfds);
465 
466 
473 void
475  int nfd);
476 
477 
485 int
487  int nfd);
488 
489 
496 void
498  const struct GNUNET_DISK_FileHandle *h);
499 
500 
508 void
510  const struct GNUNET_DISK_FileHandle *h);
511 
512 
520 int
522  const struct GNUNET_DISK_FileHandle *h);
523 
524 
532 int
534  const struct GNUNET_NETWORK_FDSet *fds2);
535 
536 
542 struct GNUNET_NETWORK_FDSet *
544 
545 
551 void
553 
554 
562 int
563 GNUNET_NETWORK_test_port_free (int ipproto,
564  uint16_t port);
565 
566 
567 #if 0 /* keep Emacsens' auto-indent happy */
568 {
569 #endif
570 #ifdef __cplusplus
571 }
572 #endif
573 
574 #endif /* GNUNET_NETWORK_LIB_H */
575  /* end of group */
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:708
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:883
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
int GNUNET_NETWORK_fdset_overlap(const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2)
Checks if two fd sets overlap.
Definition: network.c:1224
int GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, int doBlock)
Set if a socket should use blocking or non-blocking IO.
Definition: network.c:255
struct sockaddr * GNUNET_NETWORK_get_addr(const struct GNUNET_NETWORK_Handle *desc)
Return the sockaddr for this network handle.
Definition: network.c:1093
int nsds
Maximum number of any socket descriptor in the set (plus one)
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:816
socklen_t GNUNET_NETWORK_get_addrlen(const struct GNUNET_NETWORK_Handle *desc)
Return sockaddr length for this network handle.
Definition: network.c:1106
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition: network.c:1137
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, socklen_t *optlen)
Get socket options.
Definition: network.c:683
int GNUNET_NETWORK_socket_disable_corking(struct GNUNET_NETWORK_Handle *desc)
Disable the "CORK" feature for communication with the given socket, forcing the OS to immediately flu...
Definition: network.c:961
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:485
int GNUNET_NETWORK_fdset_test_native(const struct GNUNET_NETWORK_FDSet *to, int nfd)
Test native fd in a set.
Definition: network.c:1155
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:940
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1120
void GNUNET_NETWORK_socket_free_memory_only_(struct GNUNET_NETWORK_Handle *desc)
Only free memory of a socket, keep the file descriptor untouched.
Definition: network.c:622
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:850
collection of IO descriptors
int GNUNET_NETWORK_socket_select(struct GNUNET_NETWORK_FDSet *rfds, struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, struct GNUNET_TIME_Relative timeout)
Check if sockets meet certain conditions.
Definition: network.c:1340
void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
Reset FD set (clears all file descriptors).
Definition: network.c:997
fd_set sds
Bitset with the descriptors.
void GNUNET_NETWORK_fdset_handle_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h)
Add a file handle to the fd set.
Definition: network.c:1171
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
Definition: network.c:1011
int GNUNET_NETWORK_fdset_handle_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h)
Check if a file handle is part of an fd set.
Definition: network.c:1208
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to, const struct GNUNET_NETWORK_FDSet *from)
Copy one fd set to another.
Definition: network.c:1064
socklen_t addrlen
Number of bytes in addr.
Definition: network.c:69
int GNUNET_NETWORK_test_port_free(int ipproto, uint16_t port)
Test if the given port is available.
Definition: network.c:1280
handle to a socket
Definition: network.c:52
char * GNUNET_NETWORK_shorten_unixpath(char *unixpath)
Given a unixpath that is too long (larger than UNIX_PATH_MAX), shorten it to an acceptable length whi...
Definition: network.c:158
ssize_t GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
How much data is available to be read on this descriptor?
Definition: network.c:727
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un)
If services crash, they can leave a unix domain socket file on the disk.
Definition: network.c:202
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
Definition: network.c:636
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1029
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition: network.c:754
void GNUNET_NETWORK_fdset_add(struct GNUNET_NETWORK_FDSet *dst, const struct GNUNET_NETWORK_FDSet *src)
Add one fd set to another (computes the union).
Definition: network.c:1044
static char * address
GNS address for this phone.
Handle used to access files (and pipes).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
void GNUNET_NETWORK_fdset_handle_set_first(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h)
Add a file handle to the fd set On W32: ensure that the handle is first in the array.
Definition: network.c:1193