source: trunk/libtransmission/net.h @ 8091

Last change on this file since 8091 was 8091, checked in by jhujhiti, 13 years ago

(trunk libT) remove tr_suspectAddress() since all seems well

  • Property svn:keywords set to Date Rev Author Id
File size: 5.0 KB
Line 
1/******************************************************************************
2 * $Id: net.h 8091 2009-03-27 01:14:25Z jhujhiti $
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);
89void tr_normalizeV4Mapped( tr_address * const addr );
90
91tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
92
93static TR_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 * Socket list housekeeping
99 **********************************************************************/
100typedef struct tr_socketList tr_socketList;
101tr_socketList *tr_socketListAppend( tr_socketList * const head,
102                                    const tr_address * const addr );
103tr_socketList *tr_socketListNew( const tr_address * const addr );
104void tr_socketListFree( tr_socketList * const head );
105void tr_socketListRemove( tr_socketList * const head,
106                          tr_socketList * const el);
107void tr_socketListTruncate( tr_socketList * const head,
108                            tr_socketList * const start );
109int tr_socketListGetSocket( const tr_socketList * const el );
110const tr_address *tr_socketListGetAddress( const tr_socketList * const el );
111void tr_socketListForEach( tr_socketList * const head,
112                           void ( * cb ) ( int * const,
113                                           tr_address * const,
114                                           void * const ),
115                           void * const userData);
116
117/***********************************************************************
118 * Sockets
119 **********************************************************************/
120int  tr_netOpenTCP( tr_session       * session,
121                    const tr_address * addr,
122                    tr_port            port );
123
124int  tr_netBindTCP( const tr_address * addr,
125                    tr_port            port,
126                    tr_bool            suppressMsgs );
127
128int  tr_netAccept( tr_session * session,
129                   int          bound,
130                   tr_address * setme_addr,
131                   tr_port    * setme_port );
132
133int  tr_netSetTOS( int s,
134                   int tos );
135
136void tr_netClose( int s );
137
138void tr_netInit( void );
139
140#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.