1 | /****************************************************************************** |
---|
2 | * $Id: net.h 1579 2007-03-23 08:28:01Z joshe $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2006 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 | |
---|
26 | /*********************************************************************** |
---|
27 | * DNS resolution |
---|
28 | **********************************************************************/ |
---|
29 | int tr_netResolve( const char *, struct in_addr * ); |
---|
30 | |
---|
31 | typedef struct tr_resolve_s tr_resolve_t; |
---|
32 | void tr_netResolveThreadInit(); |
---|
33 | void tr_netResolveThreadClose(); |
---|
34 | tr_resolve_t * tr_netResolveInit( const char * ); |
---|
35 | tr_tristate_t tr_netResolvePulse( tr_resolve_t *, struct in_addr * ); |
---|
36 | void tr_netResolveClose( tr_resolve_t * ); |
---|
37 | |
---|
38 | |
---|
39 | /*********************************************************************** |
---|
40 | * TCP and UDP sockets |
---|
41 | **********************************************************************/ |
---|
42 | #define tr_netOpenTCP( addr, port, priority ) \ |
---|
43 | tr_netOpen( (addr), (port), SOCK_STREAM, (priority) ) |
---|
44 | #define tr_netOpenUDP( addr, port, priority ) \ |
---|
45 | tr_netOpen( (addr), (port), SOCK_DGRAM, (priority) ) |
---|
46 | int tr_netOpen ( struct in_addr addr, in_port_t port, int type, |
---|
47 | int priority ); |
---|
48 | int tr_netMcastOpen( int port, struct in_addr addr ); |
---|
49 | #define tr_netBindTCP( port ) tr_netBind( (port), SOCK_STREAM ) |
---|
50 | #define tr_netBindUDP( port ) tr_netBind( (port), SOCK_DGRAM ) |
---|
51 | int tr_netBind ( int port, int type ); |
---|
52 | int tr_netAccept ( int s, struct in_addr *, in_port_t * ); |
---|
53 | void tr_netClose ( int s ); |
---|
54 | |
---|
55 | #define TR_NET_BLOCK 0x80000000 |
---|
56 | #define TR_NET_CLOSE 0x40000000 |
---|
57 | int tr_netSend ( int s, uint8_t * buf, int size ); |
---|
58 | #define tr_netRecv( s, buf, size ) tr_netRecvFrom( (s), (buf), (size), NULL ) |
---|
59 | int tr_netRecvFrom( int s, uint8_t * buf, int size, struct sockaddr_in * ); |
---|
60 | |
---|
61 | void tr_netNtop( const struct in_addr * addr, char * buf, int len ); |
---|
62 | |
---|
63 | |
---|
64 | #define tr_addrcmp( aa, bb ) memcmp( ( void * )(aa), ( void * )(bb), 4) |
---|