source: trunk/libtransmission/net.h @ 7413

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

(trunk libT) more runtime safety checks

  • Property svn:keywords set to Date Rev Author Id
File size: 4.6 KB
Line 
1/******************************************************************************
2 * $Id: net.h 7413 2008-12-16 21:06:47Z 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#else
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41#endif
42
43#ifdef WIN32
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 sockerrno WSAGetLastError( )
51#else
52 #include <errno.h>
53 #define sockerrno errno
54#endif
55
56struct tr_session;
57
58#define TR_AF_INET  0
59#define TR_AF_INET6 1
60
61typedef struct tr_address {
62    uint8_t type;
63    union {
64        /* The order here is important for tr_in{,6}addr_any initialization,
65         * since we can't use C99 designated initializers */
66        struct in6_addr addr6;
67        struct in_addr  addr4;
68    } addr;
69} tr_address;
70
71extern const tr_address tr_inaddr_any;
72extern const tr_address tr_in6addr_any;
73
74const char *tr_ntop( const tr_address * src,
75                     char * dst,
76                     int size );
77const char *tr_ntop_non_ts( const tr_address * src );
78tr_address *tr_pton( const char * src,
79                     tr_address * dst );
80int tr_compareAddresses( const tr_address * a,
81                         const tr_address * b);
82void tr_normalizeV4Mapped( tr_address * const addr );
83
84tr_bool tr_isAddress( const tr_address * a );
85
86/***********************************************************************
87 * Socket list housekeeping
88 **********************************************************************/
89typedef struct tr_socketList tr_socketList;
90tr_socketList *tr_socketListAppend( tr_socketList * const head,
91                                    const tr_address * const addr );
92tr_socketList *tr_socketListNew( const tr_address * const addr );
93void tr_socketListFree( tr_socketList * const head );
94void tr_socketListRemove( tr_socketList * const head,
95                          tr_socketList * const el);
96void tr_socketListTruncate( tr_socketList * const head,
97                            tr_socketList * const start );
98int tr_socketListGetSocket( const tr_socketList * const el );
99const tr_address *tr_socketListGetAddress( const tr_socketList * const el );
100void tr_socketListForEach( tr_socketList * const head,
101                           void ( * cb ) ( int * const,
102                                           tr_address * const,
103                                           void * const ),
104                           void * const userData);
105
106/***********************************************************************
107 * Sockets
108 **********************************************************************/
109int  tr_netOpenTCP( struct tr_handle * session,
110                    const tr_address * addr,
111                    tr_port            port );
112
113int  tr_netBindTCP( const tr_address * addr,
114                    tr_port            port,
115                    tr_bool            suppressMsgs );
116
117int  tr_netAccept( struct tr_handle  * session,
118                   int                 bound,
119                   tr_address        * setme_addr,
120                   tr_port           * setme_port );
121
122int  tr_netSetTOS( int s,
123                   int tos );
124
125void tr_netClose( int s );
126
127void tr_netInit( void );
128
129#endif /* _TR_NET_H_ */
Note: See TracBrowser for help on using the repository browser.