GNUnet  0.10.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 {
54 
58  int nsds;
59 
63  fd_set sds;
64 
65 #ifdef WINDOWS
66 
71  const struct GNUNET_DISK_FileHandle **handles;
72 
76  unsigned int handles_size;
77 
82  unsigned int handles_pos;
83 
84 #endif
85 
86 };
87 
88 #include "gnunet_disk_lib.h"
89 #include "gnunet_time_lib.h"
90 
97 int
98 GNUNET_NETWORK_test_pf (int pf);
99 
100 
110 char *
111 GNUNET_NETWORK_shorten_unixpath (char *unixpath);
112 
113 
114 #ifndef WINDOWS
115 
124 void
125 GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un);
126 #endif
127 
128 
139 struct GNUNET_NETWORK_Handle *
141  struct sockaddr *address,
142  socklen_t *address_len);
143 
144 
151 struct GNUNET_NETWORK_Handle *
153 
154 
162 int
164  int doBlock);
165 
166 
175 int
177  const struct sockaddr *address,
178  socklen_t address_len);
179 
186 int
188 
189 
195 void
197 
198 
207 int
209  const struct sockaddr *address,
210  socklen_t address_len);
211 
212 
223 int
225  int level,
226  int optname,
227  void *optval,
228  socklen_t *optlen);
229 
230 
238 int
240  int backlog);
241 
242 
249 ssize_t
251 
252 
263 ssize_t
265  void *buffer,
266  size_t length,
267  struct sockaddr *src_addr,
268  socklen_t *addrlen);
269 
270 
279 ssize_t
281  void *buffer,
282  size_t length);
283 
284 
294 int
296  struct GNUNET_NETWORK_FDSet *wfds,
297  struct GNUNET_NETWORK_FDSet *efds,
299 
300 
309 ssize_t
311  const void *buffer,
312  size_t length);
313 
314 
326 ssize_t
328  const void *message,
329  size_t length,
330  const struct sockaddr *dest_addr,
331  socklen_t dest_len);
332 
333 
344 int
346  int level,
347  int option_name,
348  const void *option_value,
349  socklen_t option_len);
350 
351 
359 int
361  int how);
362 
363 
373 int
375 
376 
387 struct GNUNET_NETWORK_Handle *
388 GNUNET_NETWORK_socket_create (int domain,
389  int type,
390  int protocol);
391 
392 
398 void
400 
401 
408 void
410  const struct GNUNET_NETWORK_Handle *desc);
411 
412 
413 #if WINDOWS
414 
420 void
421 GNUNET_NETWORK_fdset_handle_set_native_w32_handle (struct GNUNET_NETWORK_FDSet *fds,
422  HANDLE h);
423 #endif
424 
425 
433 int
435  const struct GNUNET_NETWORK_Handle *desc);
436 
437 
444 void
446  const struct GNUNET_NETWORK_FDSet *src);
447 
448 
455 void
457  const struct GNUNET_NETWORK_FDSet *from);
458 
459 
466 int
467 GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc);
468 
469 
476 struct sockaddr*
478 
479 
486 socklen_t
488 
489 
497 void
499  const fd_set *from,
500  int nfds);
501 
502 
509 void
511  int nfd);
512 
513 
521 int
523  int nfd);
524 
525 
532 void
534  const struct GNUNET_DISK_FileHandle *h);
535 
536 
544 void
546  const struct GNUNET_DISK_FileHandle *h);
547 
548 
556 int
558  const struct GNUNET_DISK_FileHandle *h);
559 
560 
568 int
570  const struct GNUNET_NETWORK_FDSet *fds2);
571 
572 
578 struct GNUNET_NETWORK_FDSet *
580 
581 
587 void
589 
590 
598 int
599 GNUNET_NETWORK_test_port_free (int ipproto,
600  uint16_t port);
601 
602 
603 #if 0 /* keep Emacsens' auto-indent happy */
604 {
605 #endif
606 #ifdef __cplusplus
607 }
608 #endif
609 
610 #endif /* GNUNET_NETWORK_LIB_H */
611  /* end of group */
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:796
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:1005
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1268
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:1466
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:256
struct sockaddr * GNUNET_NETWORK_get_addr(const struct GNUNET_NETWORK_Handle *desc)
Return the sockaddr for this network handle.
Definition: network.c:1281
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:927
#define SOCKTYPE
Definition: platform.h:276
socklen_t GNUNET_NETWORK_get_addrlen(const struct GNUNET_NETWORK_Handle *desc)
Return sockaddr length for this network handle.
Definition: network.c:1294
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition: network.c:1325
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:894
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:763
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:1089
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:522
int GNUNET_NETWORK_fdset_test_native(const struct GNUNET_NETWORK_FDSet *to, int nfd)
Test native fd in a set.
Definition: network.c:1343
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:1065
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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:1308
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:680
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:468
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
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:731
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(SOCKTYPE fd)
Box a native socket (and check that it is a socket).
Definition: network.c:694
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:968
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:1812
void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
Reset FD set (clears all file descriptors).
Definition: network.c:1146
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:1359
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:1163
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:1419
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
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:1242
socklen_t addrlen
Number of bytes in addr.
Definition: network.c:67
int GNUNET_NETWORK_test_port_free(int ipproto, uint16_t port)
Test if the given port is available.
Definition: network.c:1751
handle to a socket
Definition: network.c:46
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:157
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:818
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:201
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:1181
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:856
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:1196
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:604
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:84
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:1037
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:1389