source: trunk/libtransmission/net.h @ 11709

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

Update the copyright year in the source code comments.

The Berne Convention says that the copyright year is moot, so instead of adding another year to each file as in previous years, I've removed the year altogether from the source code comments in libtransmission, gtk, qt, utils, daemon, and cli.

Juliusz's copyright notice in tr-dht and Johannes' copyright notice in tr-lpd have been left alone; it didn't seem appropriate to modify them.

  • Property svn:keywords set to Date Rev Author Id
File size: 4.7 KB
Line 
1/******************************************************************************
2 * $Id: net.h 11709 2011-01-19 13:48:47Z 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/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
125/**
126 * @brief get a human-representable string representing the network error.
127 * @param err an errno on Unix/Linux and an WSAError on win32)
128 */
129char* tr_net_strerror( char * buf, size_t buflen, int err );
130
131const unsigned char *tr_globalIPv6( void );
132
133#if defined( WIN32) && !defined(QT_DLL)
134/* The QT exclusion is because something clashes whith the next include */
135#include <ws2tcpip.h>           /* socklen_t */
136
137/** @brief Missing in Windows and Mingw */
138const char *inet_ntop( int af, const void *src, char *dst, socklen_t cnt );
139int inet_pton(int af, const char *src, void *dst);
140#endif
141
142#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.