source: trunk/libtransmission/net.h @ 10816

Last change on this file since 10816 was 10816, checked in by charles, 11 years ago

(trunk) more win32 fixes from rb07 in #3311

  • Property svn:keywords set to Date Rev Author Id
File size: 4.2 KB
Line 
1/******************************************************************************
2 * $Id: net.h 10816 2010-06-22 00:12:52Z charles $
3 *
4 * Copyright (c) 2005-2008 Transmission authors and contributors
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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 *****************************************************************************/
24
25#ifndef __TRANSMISSION__
26#error only libtransmission should #include this header.
27#endif
28
29#ifndef _TR_NET_H_
30#define _TR_NET_H_
31
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
41
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
57
58struct tr_session;
59
60typedef enum tr_address_type
61{
62    TR_AF_INET,
63    TR_AF_INET6,
64    NUM_TR_AF_INET_TYPES
65}
66tr_address_type;
67
68typedef struct tr_address
69{
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;
78
79extern const tr_address tr_inaddr_any;
80extern const tr_address tr_in6addr_any;
81
82const char *tr_ntop( const tr_address * src,
83                     char * dst,
84                     int size );
85const char *tr_ntop_non_ts( const tr_address * src );
86tr_address *tr_pton( const char * src,
87                     tr_address * dst );
88int tr_compareAddresses( const tr_address * a,
89                         const tr_address * b);
90
91tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
92
93static inline tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
94
95tr_bool tr_net_hasIPv6( tr_port );
96
97/***********************************************************************
98 * Sockets
99 **********************************************************************/
100int  tr_netOpenPeerSocket( tr_session       * session,
101                           const tr_address * addr,
102                           tr_port            port,
103                           tr_bool            clientIsSeed );
104
105int  tr_netBindTCP( const tr_address * addr,
106                    tr_port            port,
107                    tr_bool            suppressMsgs );
108
109int  tr_netAccept( tr_session * session,
110                   int          bound,
111                   tr_address * setme_addr,
112                   tr_port    * setme_port );
113
114int  tr_netSetTOS( int s,
115                   int tos );
116
117int tr_netSetCongestionControl( int s, const char *algorithm );
118
119void tr_netClose( tr_session * session, int s );
120
121void tr_netCloseSocket( int fd );
122
123void tr_netInit( void );
124
125const unsigned char *tr_globalIPv6( void );
126
127
128#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.