source: branches/1.5x/libtransmission/net.h @ 8204

Last change on this file since 8204 was 8204, checked in by charles, 13 years ago

(1.5x libT) various backports for 1.52:
(1) recognize Aria2 as a client
(2) remove jhujhiti's tr_suspectAddress(), since he removed it from trunka
(3) on Mac, better detection of where the Web UI files are located
(4) reintroduce the web task queue
(5) various minor formatting changes to reduce the diffs between 1.52 and trunk

  • Property svn:keywords set to Date Rev Author Id
File size: 5.0 KB
Line 
1/******************************************************************************
2 * $Id: net.h 8204 2009-04-10 17:34:25Z 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 <winsock2.h>
35 #include <WS2tcpip.h>
36 typedef int socklen_t;
37#else
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42#endif
43
44#ifdef WIN32
45 #define ECONNREFUSED            WSAECONNREFUSED
46 #define ECONNRESET              WSAECONNRESET
47 #define EHOSTUNREACH            WSAEHOSTUNREACH
48 #define EINPROGRESS             WSAEINPROGRESS
49 #define ENOTCONN                WSAENOTCONN
50 #define EWOULDBLOCK             WSAEWOULDBLOCK
51 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
52 #define ENETUNREACH             WSAENETUNREACH
53 #define sockerrno               WSAGetLastError( )
54#else
55 #include <errno.h>
56 #define sockerrno errno
57#endif
58
59struct tr_session;
60
61typedef enum tr_address_type
62{
63    TR_AF_INET,
64    TR_AF_INET6
65} tr_address_type;
66
67typedef struct tr_address
68{
69    tr_address_type type;
70    union {
71        /* The order here is important for tr_in{,6}addr_any initialization,
72         * since we can't use C99 designated initializers */
73        struct in6_addr addr6;
74        struct in_addr  addr4;
75    } addr;
76} tr_address;
77
78extern const tr_address tr_inaddr_any;
79extern const tr_address tr_in6addr_any;
80
81const char *tr_ntop( const tr_address * src,
82                     char * dst,
83                     int size );
84const char *tr_ntop_non_ts( const tr_address * src );
85tr_address *tr_pton( const char * src,
86                     tr_address * dst );
87int tr_compareAddresses( const tr_address * a,
88                         const tr_address * b);
89
90tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
91
92static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
93
94tr_bool tr_net_hasIPv6( tr_port );
95
96/***********************************************************************
97 * Socket list housekeeping
98 **********************************************************************/
99typedef struct tr_socketList tr_socketList;
100tr_socketList *tr_socketListAppend( tr_socketList * const head,
101                                    const tr_address * const addr );
102tr_socketList *tr_socketListNew( const tr_address * const addr );
103void tr_socketListFree( tr_socketList * const head );
104void tr_socketListRemove( tr_socketList * const head,
105                          tr_socketList * const el);
106void tr_socketListTruncate( tr_socketList * const head,
107                            tr_socketList * const start );
108int tr_socketListGetSocket( const tr_socketList * const el );
109const tr_address *tr_socketListGetAddress( const tr_socketList * const el );
110void tr_socketListForEach( tr_socketList * const head,
111                           void ( * cb ) ( int * const,
112                                           tr_address * const,
113                                           void * const ),
114                           void * const userData);
115
116/***********************************************************************
117 * Sockets
118 **********************************************************************/
119int  tr_netOpenTCP( tr_session       * session,
120                    const tr_address * addr,
121                    tr_port            port );
122
123int  tr_netBindTCP( const tr_address * addr,
124                    tr_port            port,
125                    tr_bool            suppressMsgs );
126
127int  tr_netAccept( tr_session * session,
128                   int          bound,
129                   tr_address * setme_addr,
130                   tr_port    * setme_port );
131
132int  tr_netSetTOS( int s,
133                   int tos );
134
135void tr_netClose( int s );
136
137void tr_netInit( void );
138
139#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.