source: trunk/libtransmission/net.h @ 7195

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

(libT) patch from jhujhiti to add ipv6 support.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.6 KB
Line 
1/******************************************************************************
2 * $Id: net.h 7195 2008-11-30 00:47:18Z 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 typedef int socklen_t;
36 typedef uint16_t tr_port_t;
37#elif defined( __BEOS__ )
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 typedef unsigned short tr_port_t;
41 typedef int socklen_t;
42#else
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 typedef in_port_t tr_port_t;
48#endif
49
50#ifdef WIN32
51 #define ECONNREFUSED WSAECONNREFUSED
52 #define ECONNRESET   WSAECONNRESET
53 #define EHOSTUNREACH WSAEHOSTUNREACH
54 #define EINPROGRESS  WSAEINPROGRESS
55 #define ENOTCONN     WSAENOTCONN
56 #define EWOULDBLOCK  WSAEWOULDBLOCK
57 #define sockerrno WSAGetLastError( )
58#else
59 #include <errno.h>
60 #define sockerrno errno
61#endif
62
63struct tr_session;
64
65#define TR_AF_INET  0
66#define TR_AF_INET6 1
67
68typedef struct tr_address {
69    unsigned short type : 1;
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
90
91/***********************************************************************
92 * Sockets
93 **********************************************************************/
94int  tr_netOpenTCP( struct tr_handle * session,
95                    const tr_address * addr,
96                    tr_port_t          port );
97
98int  tr_netBindTCP( const tr_address * addr,
99                    int                port );
100
101int  tr_netAccept( struct tr_handle * session,
102                   int                bound,
103                   tr_address       * setme_addr,
104                   tr_port_t        * setme_port );
105
106int  tr_netSetTOS( int s,
107                   int tos );
108
109void tr_netClose( int s );
110
111void tr_netInit( void );
112
113#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.