source: trunk/libtransmission/net.h @ 12225

Last change on this file since 12225 was 12225, checked in by jordan, 11 years ago

(trunk libT) copyediting: remove a bunch of seemingly-unneeded network headers in net.[ch].

I'm less certain that these are unneeded because networking APIs seem to have more variation between platforms, but it's better to remove the cruft and then add back whatever headers $PLATFORM users complain about, than to not remove the cruft at all...

  • Property svn:keywords set to Date Rev Author Id
File size: 4.8 KB
Line 
1/******************************************************************************
2 * $Id: net.h 12225 2011-03-24 22:57:39Z jordan $
3 *
4 * Copyright (c) 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/socket.h>
37 #include <netinet/in.h>
38#endif
39
40#ifdef WIN32
41 #define EADDRINUSE              WSAEADDRINUSE
42 #define ECONNREFUSED            WSAECONNREFUSED
43 #define ECONNRESET              WSAECONNRESET
44 #define EHOSTUNREACH            WSAEHOSTUNREACH
45 #define EINPROGRESS             WSAEINPROGRESS
46 #define ENOTCONN                WSAENOTCONN
47 #define EWOULDBLOCK             WSAEWOULDBLOCK
48 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
49 #define ENETUNREACH             WSAENETUNREACH
50 #define sockerrno               WSAGetLastError( )
51#else
52 #include <errno.h>
53 #define sockerrno errno
54#endif
55
56struct tr_session;
57
58typedef enum tr_address_type
59{
60    TR_AF_INET,
61    TR_AF_INET6,
62    NUM_TR_AF_INET_TYPES
63}
64tr_address_type;
65
66typedef struct tr_address
67{
68    tr_address_type type;
69    union {
70        /* The order here is important for tr_in{,6}addr_any initialization,
71         * since we can't use C99 designated initializers */
72        struct in6_addr addr6;
73        struct in_addr  addr4;
74    } addr;
75} tr_address;
76
77extern const tr_address tr_inaddr_any;
78extern const tr_address tr_in6addr_any;
79
80bool tr_ssToAddr( tr_address * setme_addr,
81                  tr_port    * setme_port,
82                  const struct sockaddr_storage * from );
83
84const char *tr_ntop( const tr_address * src,
85                     char * dst,
86                     int size );
87const char *tr_ntop_non_ts( const tr_address * src );
88tr_address *tr_pton( const char * src,
89                     tr_address * dst );
90int tr_compareAddresses( const tr_address * a,
91                         const tr_address * b);
92
93bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
94
95static inline bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
96
97bool tr_net_hasIPv6( tr_port );
98
99/***********************************************************************
100 * Sockets
101 **********************************************************************/
102int  tr_netOpenPeerSocket( tr_session       * session,
103                           const tr_address * addr,
104                           tr_port            port,
105                           bool               clientIsSeed );
106
107struct UTPSocket *
108tr_netOpenPeerUTPSocket( tr_session        * session,
109                         const tr_address  * addr,
110                         tr_port             port,
111                         bool                clientIsSeed);
112
113int  tr_netBindTCP( const tr_address * addr,
114                    tr_port            port,
115                    bool               suppressMsgs );
116
117int  tr_netAccept( tr_session * session,
118                   int          bound,
119                   tr_address * setme_addr,
120                   tr_port    * setme_port );
121
122int  tr_netSetTOS( int s,
123                   int tos );
124
125int tr_netSetCongestionControl( int s, const char *algorithm );
126
127void tr_netClose( tr_session * session, int s );
128
129void tr_netCloseSocket( int fd );
130
131void tr_netInit( void );
132
133
134/**
135 * @brief get a human-representable string representing the network error.
136 * @param err an errno on Unix/Linux and an WSAError on win32)
137 */
138char* tr_net_strerror( char * buf, size_t buflen, int err );
139
140const unsigned char *tr_globalIPv6( void );
141
142#if defined( WIN32) && !defined(QT_DLL)
143/* The QT exclusion is because something clashes whith the next include */
144#include <ws2tcpip.h>           /* socklen_t */
145
146#endif
147
148#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.