Freeciv-3.1: /fast/freeciv/nightly/S3_1/utility/netintf.h Source File

Freeciv-3.1

Loading...
Searching...
No Matches
netintf.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__NETINTF_H
15#define FC__NETINTF_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21#include <freeciv_config.h>
22
23/***********************************************************************
24 Common network interface.
25***********************************************************************/
26
27#ifdef FREECIV_HAVE_NETINET_IN_H
28#include <netinet/in.h>
29#endif
30#ifdef FREECIV_HAVE_SYS_SELECT_H
31#include <sys/select.h>
32#endif
33#ifdef FREECIV_HAVE_SYS_SOCKET_H
34#include <sys/socket.h>
35#endif
36#ifdef FREECIV_HAVE_SYS_TIME_H
37#include <sys/time.h>
38#endif
39#ifdef FREECIV_HAVE_SYS_TYPES_H
40#include <sys/types.h>
41#endif
42#ifdef FREECIV_HAVE_UNISTD_H
43#include <unistd.h>
44#endif
45#ifdef FREECIV_HAVE_WS2TCPIP_H
46#include <ws2tcpip.h>
47#endif
48
49/* utility */
50#include "ioz.h"
51#include "net_types.h"
52#include "support.h" /* bool type */
53
54#ifdef FD_ZERO
55#define FC_FD_ZERO FD_ZERO
56#else
57#define FC_FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
58#endif
59
60#ifdef IPV6_ADD_MEMBERSHIP
61#define FC_IPV6_ADD_MEMBERSHIP IPV6_ADD_MEMBERSHIP
62#else
63#define FC_IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
64#endif
65
66#ifndef FREECIV_HAVE_SOCKLEN_T
67 typedef int socklen_t;
68#endif /* FREECIV_HAVE_SOCKLEN_T */
69
70 union fc_sockaddr {
71 struct sockaddr saddr;
72 struct sockaddr_in saddr_in4;
73#ifdef FREECIV_IPV6_SUPPORT
74 struct sockaddr_in6 saddr_in6;
75#endif /* FREECIV_IPV6_SUPPORT */
76};
77
78/* get 'struct sockaddr_list' and related functions: */
79#define SPECLIST_TAG fc_sockaddr
80#define SPECLIST_TYPE union fc_sockaddr
81#include "speclist.h"
82
83#define fc_sockaddr_list_iterate(sockaddrlist, paddr) \
84 TYPED_LIST_ITERATE(union fc_sockaddr, sockaddrlist, paddr)
85#define fc_sockaddr_list_iterate_end LIST_ITERATE_END
86
87#ifdef FREECIV_MSWINDOWS
88typedef TIMEVAL fc_timeval;
89#else /* FREECIV_MSWINDOWS */
90 typedef struct timeval fc_timeval;
91#endif /* FREECIV_MSWINDOWS */
92
93int fc_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);
94int fc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
95 fc_timeval *timeout);
96int fc_readsocket(int sock, void *buf, size_t size);
97int fc_writesocket(int sock, const void *buf, size_t size);
98void fc_closesocket(int sock);
99
100void fc_nonblock(int sockfd);
101struct fc_sockaddr_list *net_lookup_service(const char *name, int port,
102 enum fc_addr_family family);
103bool fc_inet_aton(const char *cp, struct in_addr *inp, bool addr_none_ok);
104 fz_FILE *fc_querysocket(int sock, void *buf, size_t size);
105int find_next_free_port(int starting_port, int highest_port,
106 enum fc_addr_family family,
107 char *net_interface, bool not_avail_ok);
108
109void sockaddr_debug(union fc_sockaddr *addr, enum log_level lvl);
110int sockaddr_size(union fc_sockaddr *addr);
111bool sockaddr_ipv6(union fc_sockaddr *addr);
112
113#ifdef __cplusplus
114}
115#endif /* __cplusplus */
116
117#endif /* FC__NETINTF_H */
n
#define n
Definition astring.c:77
name
const char * name
Definition inputfile.c:127
ioz.h
log_level
log_level
Definition log.h:28
net_types.h
fc_addr_family
fc_addr_family
Definition net_types.h:61
fc_timeval
struct timeval fc_timeval
Definition netintf.h:90
socklen_t
int socklen_t
Definition netintf.h:67
fc_inet_aton
bool fc_inet_aton(const char *cp, struct in_addr *inp, bool addr_none_ok)
Definition netintf.c:466
sockaddr_ipv6
bool sockaddr_ipv6(union fc_sockaddr *addr)
Definition netintf.c:330
net_lookup_service
struct fc_sockaddr_list * net_lookup_service(const char *name, int port, enum fc_addr_family family)
Definition netintf.c:411
fc_closesocket
void fc_closesocket(int sock)
Definition netintf.c:186
sockaddr_debug
void sockaddr_debug(union fc_sockaddr *addr, enum log_level lvl)
Definition netintf.c:269
find_next_free_port
int find_next_free_port(int starting_port, int highest_port, enum fc_addr_family family, char *net_interface, bool not_avail_ok)
Definition netintf.c:553
sockaddr_size
int sockaddr_size(union fc_sockaddr *addr)
Definition netintf.c:305
fc_connect
int fc_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
Definition netintf.c:107
fc_readsocket
int fc_readsocket(int sock, void *buf, size_t size)
Definition netintf.c:144
fc_writesocket
int fc_writesocket(int sock, const void *buf, size_t size)
Definition netintf.c:163
fc_nonblock
void fc_nonblock(int sockfd)
Definition netintf.c:227
fc_select
int fc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fc_timeval *timeout)
Definition netintf.c:125
fc_querysocket
fz_FILE * fc_querysocket(int sock, void *buf, size_t size)
Definition netintf.c:493
speclist.h
size
size_t size
Definition specvec.h:72
fz_FILE_s
Definition ioz.c:149
support.h
fc_sockaddr
Definition netintf.h:70
fc_sockaddr::saddr
struct sockaddr saddr
Definition netintf.h:71
fc_sockaddr::saddr_in4
struct sockaddr_in saddr_in4
Definition netintf.h:72