GNUnet  0.17.6
gnunet_network_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013, 2022 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 
39 #ifndef GNUNET_NETWORK_LIB_H
40 #define GNUNET_NETWORK_LIB_H
41 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #if 0 /* keep Emacsens' auto-indent happy */
46 }
47 #endif
48 #endif
49 
50 //#ifdef HAVE_SYS_SELECT_H
51 /*
52  * Include "sys/select.h" because it is required to use
53  * "fd_set" in "struct GNUNET_NETWORK_FDSet"!
54  */
55 #include <sys/select.h>
56 //#endif
57 #ifdef HAVE_SYS_SOCKET_H
58 #include <sys/socket.h>
59 #endif
60 #ifdef HAVE_SYS_UN_H
61 #include <sys/un.h>
62 #endif
63 
68 
69 
74 {
78  int nsds;
79 
83  fd_set sds;
84 
85 };
86 
87 #include "gnunet_disk_lib.h"
88 #include "gnunet_time_lib.h"
89 
97 GNUNET_NETWORK_test_pf (int pf);
98 
99 
109 char *
110 GNUNET_NETWORK_shorten_unixpath (char *unixpath);
111 
112 
122 void
123 GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un);
124 
125 
136 struct GNUNET_NETWORK_Handle *
138  struct sockaddr *address,
139  socklen_t *address_len);
140 
141 
148 struct GNUNET_NETWORK_Handle *
150 
151 
159 int
161  int doBlock);
162 
163 
174  const struct sockaddr *address,
175  socklen_t address_len);
176 
185 
186 
192 void
194 
195 
206  const struct sockaddr *address,
207  socklen_t address_len);
208 
209 
222  int level,
223  int optname,
224  void *optval,
225  socklen_t *optlen);
226 
227 
237  int backlog);
238 
239 
246 ssize_t
248  GNUNET_NETWORK_Handle *desc);
249 
250 
261 ssize_t
263  void *buffer,
264  size_t length,
265  struct sockaddr *src_addr,
266  socklen_t *addrlen);
267 
268 
277 ssize_t
279  void *buffer,
280  size_t length);
281 
282 
292 int
294  struct GNUNET_NETWORK_FDSet *wfds,
295  struct GNUNET_NETWORK_FDSet *efds,
297 
298 
307 ssize_t
309  const void *buffer,
310  size_t length);
311 
312 
324 ssize_t
326  const void *message,
327  size_t length,
328  const struct sockaddr *dest_addr,
329  socklen_t dest_len);
330 
331 
342 int
344  int level,
345  int option_name,
346  const void *option_value,
347  socklen_t option_len);
348 
349 
359  int how);
360 
361 
373 
374 
385 struct GNUNET_NETWORK_Handle *
386 GNUNET_NETWORK_socket_create (int domain,
387  int type,
388  int protocol);
389 
390 
396 void
398 
399 
406 void
408  const struct GNUNET_NETWORK_Handle *desc);
409 
410 
418 int
420  const struct GNUNET_NETWORK_Handle *desc);
421 
422 
429 void
431  const struct GNUNET_NETWORK_FDSet *src);
432 
433 
440 void
442  const struct GNUNET_NETWORK_FDSet *from);
443 
444 
451 int
452 GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc);
453 
454 
461 struct sockaddr*
463 
464 
471 socklen_t
473 
474 
482 void
484  const fd_set *from,
485  int nfds);
486 
487 
494 void
496  int nfd);
497 
498 
506 int
508  int nfd);
509 
510 
517 void
519  const struct GNUNET_DISK_FileHandle *h);
520 
521 
529 void
531  const struct GNUNET_DISK_FileHandle *h);
532 
533 
541 int
543  const struct GNUNET_DISK_FileHandle *h);
544 
545 
553 int
555  const struct GNUNET_NETWORK_FDSet *fds2);
556 
557 
563 struct GNUNET_NETWORK_FDSet *
565 
566 
572 void
574 
575 
583 int
584 GNUNET_NETWORK_test_port_free (int ipproto,
585  uint16_t port);
586 
587 
588 #if 0 /* keep Emacsens' auto-indent happy */
589 {
590 #endif
591 #ifdef __cplusplus
592 }
593 #endif
594 
595 #endif /* GNUNET_NETWORK_LIB_H */
596  /* end of group */
598  /* end of group addition */
600  /* end of group addition */
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static char * address
GNS address for this phone.
Disk IO APIs.
Functions related to time.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
struct sockaddr * GNUNET_NETWORK_get_addr(const struct GNUNET_NETWORK_Handle *desc)
Return the sockaddr for this network handle.
Definition: network.c:1036
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:1136
enum GNUNET_GenericReturnValue 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:631
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1193
void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
Reset FD set (clears all file descriptors).
Definition: network.c:940
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1209
socklen_t GNUNET_NETWORK_get_addrlen(const struct GNUNET_NETWORK_Handle *desc)
Return sockaddr length for this network handle.
Definition: network.c:1049
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1023
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:1063
int GNUNET_NETWORK_test_port_free(int ipproto, uint16_t port)
Test if the given port is available.
Definition: network.c:1223
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:1167
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:731
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:702
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:987
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition: network.c:1080
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:1007
enum GNUNET_GenericReturnValue 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:606
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:392
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:675
int GNUNET_NETWORK_fdset_test_native(const struct GNUNET_NETWORK_FDSet *to, int nfd)
Test native fd in a set.
Definition: network.c:1098
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:855
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:954
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:224
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:570
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:143
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:760
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
enum GNUNET_GenericReturnValue 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:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:656
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:178
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:1151
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:1283
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:883
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:828
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:794
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:972
enum GNUNET_GenericReturnValue 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:904
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:1114
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:584
Handle used to access files (and pipes).
collection of IO descriptors
int nsds
Maximum number of any socket descriptor in the set (plus one)
fd_set sds
Bitset with the descriptors.
handle to a socket
Definition: network.c:53
socklen_t addrlen
Number of bytes in addr.
Definition: network.c:69
Time for relative time used by GNUnet, in microseconds.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model