source: trunk/libtransmission/net.h @ 9778

Last change on this file since 9778 was 9778, checked in by charles, 12 years ago

(trunk libT) #2667 "ignore martian addresses" -- modified this ticket. previously we ignored them from LTEP; now we ignore them regardless of the source. this commit implements this filtering change.

  • Property svn:keywords set to Date Rev Author Id
File size: 4.2 KB
Line 
1/******************************************************************************
2 * $Id: net.h 9778 2009-12-15 17:39:19Z 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    NUM_TR_AF_INET_TYPES
66}
67tr_address_type;
68
69typedef struct tr_address
70{
71    tr_address_type type;
72    union {
73        /* The order here is important for tr_in{,6}addr_any initialization,
74         * since we can't use C99 designated initializers */
75        struct in6_addr addr6;
76        struct in_addr  addr4;
77    } addr;
78} tr_address;
79
80extern const tr_address tr_inaddr_any;
81extern const tr_address tr_in6addr_any;
82
83const char *tr_ntop( const tr_address * src,
84                     char * dst,
85                     int size );
86const char *tr_ntop_non_ts( const tr_address * src );
87tr_address *tr_pton( const char * src,
88                     tr_address * dst );
89int tr_compareAddresses( const tr_address * a,
90                         const tr_address * b);
91
92tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
93
94static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
95
96tr_bool tr_net_hasIPv6( tr_port );
97
98/***********************************************************************
99 * Sockets
100 **********************************************************************/
101int  tr_netOpenPeerSocket( tr_session       * session,
102                           const tr_address * addr,
103                           tr_port            port,
104                           tr_bool            clientIsSeed );
105
106int  tr_netBindTCP( const tr_address * addr,
107                    tr_port            port,
108                    tr_bool            suppressMsgs );
109
110int  tr_netAccept( tr_session * session,
111                   int          bound,
112                   tr_address * setme_addr,
113                   tr_port    * setme_port );
114
115int  tr_netSetTOS( int s,
116                   int tos );
117
118void tr_netClose( tr_session * session, int s );
119
120void tr_netCloseSocket( int fd );
121
122void tr_netInit( void );
123
124int tr_globalAddress(int af, void *addr, int *addr_len);
125
126const unsigned char *tr_globalIPv6( void );
127
128
129#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.