GNUnet  0.19.3
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 
56 #include <sys/select.h>
57 //#endif
58 #ifdef HAVE_SYS_SOCKET_H
59 #include <sys/socket.h>
60 #endif
61 #ifdef HAVE_SYS_UN_H
62 #include <sys/un.h>
63 #endif
64 
69 
70 
75 {
79  int nsds;
80 
84  fd_set sds;
85 
86 };
87 
88 #include "gnunet_disk_lib.h"
89 #include "gnunet_time_lib.h"
90 
98 GNUNET_NETWORK_test_pf (int pf);
99 
100 
110 char *
111 GNUNET_NETWORK_shorten_unixpath (char *unixpath);
112 
113 
123 void
124 GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un);
125 
126 
137 struct GNUNET_NETWORK_Handle *
139  struct sockaddr *address,
140  socklen_t *address_len);
141 
142 
149 struct GNUNET_NETWORK_Handle *
151 
152 
160 int
162  int doBlock);
163 
164 
175  const struct sockaddr *address,
176  socklen_t address_len);
177 
186 
187 
193 void
195 
196 
207  const struct sockaddr *address,
208  socklen_t address_len);
209 
210 
223  int level,
224  int optname,
225  void *optval,
226  socklen_t *optlen);
227 
228 
238  int backlog);
239 
240 
247 ssize_t
249  GNUNET_NETWORK_Handle *desc);
250 
251 
262 ssize_t
264  void *buffer,
265  size_t length,
266  struct sockaddr *src_addr,
267  socklen_t *addrlen);
268 
269 
278 ssize_t
280  void *buffer,
281  size_t length);
282 
283 
293 int
295  struct GNUNET_NETWORK_FDSet *wfds,
296  struct GNUNET_NETWORK_FDSet *efds,
298 
299 
308 ssize_t
310  const void *buffer,
311  size_t length);
312 
313 
325 ssize_t
327  const void *message,
328  size_t length,
329  const struct sockaddr *dest_addr,
330  socklen_t dest_len);
331 
332 
343 int
345  int level,
346  int option_name,
347  const void *option_value,
348  socklen_t option_len);
349 
350 
360  int how);
361 
362 
374 
375 
386 struct GNUNET_NETWORK_Handle *
387 GNUNET_NETWORK_socket_create (int domain,
388  int type,
389  int protocol);
390 
391 
397 void
399 
400 
407 void
409  const struct GNUNET_NETWORK_Handle *desc);
410 
411 
419 int
421  const struct GNUNET_NETWORK_Handle *desc);
422 
423 
430 void
432  const struct GNUNET_NETWORK_FDSet *src);
433 
434 
441 void
443  const struct GNUNET_NETWORK_FDSet *from);
444 
445 
452 int
453 GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc);
454 
455 
462 struct sockaddr*
464 
465 
472 socklen_t
474 
475 
483 void
485  const fd_set *from,
486  int nfds);
487 
488 
495 void
497  int nfd);
498 
499 
507 int
509  int nfd);
510 
511 
518 void
520  const struct GNUNET_DISK_FileHandle *h);
521 
522 
530 void
532  const struct GNUNET_DISK_FileHandle *h);
533 
534 
542 int
544  const struct GNUNET_DISK_FileHandle *h);
545 
546 
554 int
556  const struct GNUNET_NETWORK_FDSet *fds2);
557 
558 
564 struct GNUNET_NETWORK_FDSet *
566 
567 
573 void
575 
576 
584 int
585 GNUNET_NETWORK_test_port_free (int ipproto,
586  uint16_t port);
587 
588 
589 #if 0 /* keep Emacsens' auto-indent happy */
590 {
591 #endif
592 #ifdef __cplusplus
593 }
594 #endif
595 
596 #endif /* GNUNET_NETWORK_LIB_H */
597  /* end of group */
599  /* end of group addition */
601  /* 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.
struct sockaddr * GNUNET_NETWORK_get_addr(const struct GNUNET_NETWORK_Handle *desc)
Return the sockaddr for this network handle.
Definition: network.c:1013
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:1113
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:626
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1170
void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
Reset FD set (clears all file descriptors).
Definition: network.c:917
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:1186
socklen_t GNUNET_NETWORK_get_addrlen(const struct GNUNET_NETWORK_Handle *desc)
Return sockaddr length for this network handle.
Definition: network.c:1026
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1000
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:1040
int GNUNET_NETWORK_test_port_free(int ipproto, uint16_t port)
Test if the given port is available.
Definition: network.c:1200
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:1144
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:716
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:687
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:964
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition: network.c:1057
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:984
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:601
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:670
int GNUNET_NETWORK_fdset_test_native(const struct GNUNET_NETWORK_FDSet *to, int nfd)
Test native fd in a set.
Definition: network.c:1075
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
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:931
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:565
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:737
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:651
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:1128
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:1260
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:860
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:805
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:771
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:949
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:881
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:1091
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:579
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