transmission: update from 2.13 to 2.22
[tomato.git] / release / src / router / transmission / libtransmission / net.h
blob4cc80b71983a865888de2f3d84bd661944250c2b
1 /******************************************************************************
2 * $Id: net.h 11709 2011-01-19 13:48:47Z jordan $
4 * Copyright (c) Transmission authors and contributors
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
25 #ifndef __TRANSMISSION__
26 #error only libtransmission should #include this header.
27 #endif
29 #ifndef _TR_NET_H_
30 #define _TR_NET_H_
32 #ifdef WIN32
33 #include <inttypes.h>
34 #include <ws2tcpip.h>
35 #else
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
40 #endif
42 #ifdef WIN32
43 #define EADDRINUSE WSAEADDRINUSE
44 #define ECONNREFUSED WSAECONNREFUSED
45 #define ECONNRESET WSAECONNRESET
46 #define EHOSTUNREACH WSAEHOSTUNREACH
47 #define EINPROGRESS WSAEINPROGRESS
48 #define ENOTCONN WSAENOTCONN
49 #define EWOULDBLOCK WSAEWOULDBLOCK
50 #define EAFNOSUPPORT WSAEAFNOSUPPORT
51 #define ENETUNREACH WSAENETUNREACH
52 #define sockerrno WSAGetLastError( )
53 #else
54 #include <errno.h>
55 #define sockerrno errno
56 #endif
58 struct tr_session;
60 typedef enum tr_address_type
62 TR_AF_INET,
63 TR_AF_INET6,
64 NUM_TR_AF_INET_TYPES
66 tr_address_type;
68 typedef struct tr_address
70 tr_address_type type;
71 union {
72 /* The order here is important for tr_in{,6}addr_any initialization,
73 * since we can't use C99 designated initializers */
74 struct in6_addr addr6;
75 struct in_addr addr4;
76 } addr;
77 } tr_address;
79 extern const tr_address tr_inaddr_any;
80 extern const tr_address tr_in6addr_any;
82 const char *tr_ntop( const tr_address * src,
83 char * dst,
84 int size );
85 const char *tr_ntop_non_ts( const tr_address * src );
86 tr_address *tr_pton( const char * src,
87 tr_address * dst );
88 int tr_compareAddresses( const tr_address * a,
89 const tr_address * b);
91 tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
93 static inline tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
95 tr_bool tr_net_hasIPv6( tr_port );
97 /***********************************************************************
98 * Sockets
99 **********************************************************************/
100 int tr_netOpenPeerSocket( tr_session * session,
101 const tr_address * addr,
102 tr_port port,
103 tr_bool clientIsSeed );
105 int tr_netBindTCP( const tr_address * addr,
106 tr_port port,
107 tr_bool suppressMsgs );
109 int tr_netAccept( tr_session * session,
110 int bound,
111 tr_address * setme_addr,
112 tr_port * setme_port );
114 int tr_netSetTOS( int s,
115 int tos );
117 int tr_netSetCongestionControl( int s, const char *algorithm );
119 void tr_netClose( tr_session * session, int s );
121 void tr_netCloseSocket( int fd );
123 void tr_netInit( void );
126 * @brief get a human-representable string representing the network error.
127 * @param err an errno on Unix/Linux and an WSAError on win32)
129 char* tr_net_strerror( char * buf, size_t buflen, int err );
131 const unsigned char *tr_globalIPv6( void );
133 #if defined( WIN32) && !defined(QT_DLL)
134 /* The QT exclusion is because something clashes whith the next include */
135 #include <ws2tcpip.h> /* socklen_t */
137 /** @brief Missing in Windows and Mingw */
138 const char *inet_ntop( int af, const void *src, char *dst, socklen_t cnt );
139 int inet_pton(int af, const char *src, void *dst);
140 #endif
142 #endif /* _TR_NET_H_ */