source: trunk/libtransmission/net.h @ 7231

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

(libT) re-apply jhujhiti's IPv6 patch. This merges in my tr_port cleanup, so any new bugs are mine :/

  • Property svn:keywords set to Date Rev Author Id
File size: 3.5 KB
Line 
1/******************************************************************************
2 * $Id: net.h 7231 2008-12-02 03:41:58Z 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#elif defined( __BEOS__ )
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 typedef int socklen_t;
40#else
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
45#endif
46
47#ifdef WIN32
48 #define ECONNREFUSED WSAECONNREFUSED
49 #define ECONNRESET   WSAECONNRESET
50 #define EHOSTUNREACH WSAEHOSTUNREACH
51 #define EINPROGRESS  WSAEINPROGRESS
52 #define ENOTCONN     WSAENOTCONN
53 #define EWOULDBLOCK  WSAEWOULDBLOCK
54 #define sockerrno WSAGetLastError( )
55#else
56 #include <errno.h>
57 #define sockerrno errno
58#endif
59
60struct tr_session;
61
62#define TR_AF_INET  0
63#define TR_AF_INET6 1
64 
65typedef struct tr_address { 
66    unsigned short type : 1; 
67    union { 
68        /* The order here is important for tr_in{,6}addr_any initialization,
69         * since we can't use C99 designated initializers */ 
70        struct in6_addr addr6; 
71        struct in_addr  addr4; 
72    } addr; 
73} tr_address; 
74 
75extern const tr_address tr_inaddr_any; 
76extern const tr_address tr_in6addr_any; 
77 
78const char *tr_ntop( const tr_address * src, 
79                     char * dst, 
80                     int size ); 
81const char *tr_ntop_non_ts( const tr_address * src ); 
82tr_address *tr_pton( const char * src, 
83                     tr_address * dst ); 
84int tr_compareAddresses( const tr_address * a, 
85                         const tr_address * b); 
86
87/***********************************************************************
88 * Sockets
89 **********************************************************************/
90int  tr_netOpenTCP( struct tr_handle * session,
91                    const tr_address * addr,
92                    tr_port            port );
93
94int  tr_netBindTCP( const tr_address * addr,
95                    tr_port            port );
96
97int  tr_netAccept( struct tr_handle  * session,
98                   int                 bound,
99                   tr_address        * setme_addr,
100                   tr_port           * setme_port );
101
102int  tr_netSetTOS( int s,
103                   int tos );
104
105void tr_netClose( int s );
106
107void tr_netInit( void );
108
109#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.