~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to libtransmission/net.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2007-09-15 18:58:42 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20070915185842-cagev5gre27re7ko
Tags: upstream-0.82.dfsg
ImportĀ upstreamĀ versionĀ 0.82.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: net.h 1579 2007-03-23 08:28:01Z joshe $
 
2
 * $Id: net.h 2615 2007-08-04 01:34:00Z charles $
3
3
 *
4
4
 * Copyright (c) 2005-2006 Transmission authors and contributors
5
5
 *
22
22
 * DEALINGS IN THE SOFTWARE.
23
23
 *****************************************************************************/
24
24
 
 
25
#ifndef _TR_NET_H_
 
26
#define _TR_NET_H_
 
27
 
 
28
#ifdef WIN32
 
29
    #include <inttypes.h>
 
30
    #include <winsock2.h>
 
31
    typedef int socklen_t;
 
32
    typedef uint16_t tr_port_t;
 
33
#elif defined(__BEOS__)
 
34
    #include <sys/socket.h>
 
35
    #include <netinet/in.h>
 
36
    typedef unsigned short tr_port_t;
 
37
    typedef int socklen_t;
 
38
#else
 
39
    #include <sys/socket.h>
 
40
    #include <netinet/in.h>
 
41
    #include <arpa/inet.h>
 
42
    typedef in_port_t tr_port_t;
 
43
#endif
 
44
 
 
45
#ifdef WIN32
 
46
    #define ECONNREFUSED WSAECONNREFUSED
 
47
    #define ECONNRESET   WSAECONNRESET
 
48
    #define EHOSTUNREACH WSAEHOSTUNREACH
 
49
    #define EINPROGRESS  WSAEINPROGRESS
 
50
    #define ENOTCONN     WSAENOTCONN
 
51
    #define EWOULDBLOCK  WSAEWOULDBLOCK
 
52
    #define sockerrno WSAGetLastError( )
 
53
#else
 
54
    #include <errno.h>
 
55
    #define sockerrno errno
 
56
#endif
 
57
 
 
58
#ifndef INADDR_NONE
 
59
#define INADDR_NONE 0xffffffff
 
60
#endif
 
61
 
 
62
struct in_addr;
 
63
struct sockaddr_in;
25
64
 
26
65
/***********************************************************************
27
66
 * DNS resolution
29
68
int tr_netResolve( const char *, struct in_addr * );
30
69
 
31
70
typedef struct tr_resolve_s tr_resolve_t;
32
 
void           tr_netResolveThreadInit();
33
 
void           tr_netResolveThreadClose();
34
 
tr_resolve_t * tr_netResolveInit( const char * );
 
71
void           tr_netResolveThreadInit( void );
 
72
void           tr_netResolveThreadClose( void );
 
73
tr_resolve_t * tr_netResolveInit( const char * address );
35
74
tr_tristate_t  tr_netResolvePulse( tr_resolve_t *, struct in_addr * );
36
75
void           tr_netResolveClose( tr_resolve_t * );
37
76
 
39
78
/***********************************************************************
40
79
 * TCP and UDP sockets
41
80
 **********************************************************************/
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 );
 
81
int  tr_netOpenTCP  ( const struct in_addr * addr, tr_port_t port, int priority );
 
82
int  tr_netOpenUDP  ( const struct in_addr * addr, tr_port_t port, int priority );
 
83
int  tr_netMcastOpen( int port, const struct in_addr * addr );
 
84
int  tr_netBindTCP  ( int port );
 
85
int  tr_netBindUDP  ( int port );
 
86
int  tr_netAccept   ( int s, struct in_addr *, tr_port_t * );
 
87
void tr_netClose    ( int s );
54
88
 
55
89
#define TR_NET_BLOCK 0x80000000
56
90
#define TR_NET_CLOSE 0x40000000
57
 
int  tr_netSend    ( int s, uint8_t * buf, int size );
 
91
int  tr_netSend    ( int s, const void * buf, int size );
58
92
#define tr_netRecv( s, buf, size ) tr_netRecvFrom( (s), (buf), (size), NULL )
59
93
int  tr_netRecvFrom( int s, uint8_t * buf, int size, struct sockaddr_in * );
60
94
 
61
95
void tr_netNtop( const struct in_addr * addr, char * buf, int len );
62
96
 
 
97
void tr_netInit ( void );
 
98
 
63
99
 
64
100
#define tr_addrcmp( aa, bb )    memcmp( ( void * )(aa), ( void * )(bb), 4)
 
101
 
 
102
#endif /* _TR_NET_H_ */