~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to tombupnp/upnp/src/inc/sock.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// Copyright (c) 2000-2003 Intel Corporation 
 
4
// All rights reserved. 
 
5
//
 
6
// Redistribution and use in source and binary forms, with or without 
 
7
// modification, are permitted provided that the following conditions are met: 
 
8
//
 
9
// * Redistributions of source code must retain the above copyright notice, 
 
10
// this list of conditions and the following disclaimer. 
 
11
// * Redistributions in binary form must reproduce the above copyright notice, 
 
12
// this list of conditions and the following disclaimer in the documentation 
 
13
// and/or other materials provided with the distribution. 
 
14
// * Neither name of Intel Corporation nor the names of its contributors 
 
15
// may be used to endorse or promote products derived from this software 
 
16
// without specific prior written permission.
 
17
// 
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
 
22
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 
25
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
 
26
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
27
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 
28
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
//
 
30
///////////////////////////////////////////////////////////////////////////
 
31
 
 
32
#ifndef GENLIB_NET_SOCK_H
 
33
#define GENLIB_NET_SOCK_H
 
34
 
 
35
#include "util.h"
 
36
 
 
37
#ifndef WIN32
 
38
 #include <netinet/in.h>
 
39
#endif
 
40
 
 
41
//Following variable is not defined under winsock.h
 
42
#ifndef SD_RECEIVE
 
43
#define SD_RECEIVE      0x00
 
44
#define SD_SEND         0x01
 
45
#define SD_BOTH         0x02
 
46
#endif
 
47
 
 
48
 
 
49
typedef struct 
 
50
{
 
51
        int socket;             // handle/descriptor to a socket
 
52
 
 
53
    // the following two fields are filled only in incoming requests;
 
54
    struct in_addr foreign_ip_addr;
 
55
    unsigned short foreign_ip_port;
 
56
    
 
57
} SOCKINFO;
 
58
 
 
59
#ifdef __cplusplus
 
60
#extern "C" {
 
61
#endif
 
62
 
 
63
/************************************************************************
 
64
*       Function :      sock_init
 
65
*
 
66
*       Parameters :
 
67
*               OUT SOCKINFO* info ;    Socket Information Object
 
68
*               IN int sockfd ;                 Socket Descriptor
 
69
*
 
70
*       Description :   Assign the passed in socket descriptor to socket 
 
71
*               descriptor in the SOCKINFO structure.
 
72
*
 
73
*       Return : int;
 
74
*               UPNP_E_SUCCESS  
 
75
*               UPNP_E_OUTOF_MEMORY
 
76
*               UPNP_E_SOCKET_ERROR
 
77
*       Note :
 
78
************************************************************************/
 
79
int sock_init( OUT SOCKINFO* info, IN int sockfd );
 
80
 
 
81
/************************************************************************
 
82
*       Function :      sock_init_with_ip
 
83
*
 
84
*       Parameters :
 
85
*               OUT SOCKINFO* info ;                            Socket Information Object
 
86
*               IN int sockfd ;                                         Socket Descriptor
 
87
*               IN struct in_addr foreign_ip_addr ;     Remote IP Address
 
88
*               IN unsigned short foreign_ip_port ;     Remote Port number
 
89
*
 
90
*       Description :   Calls the sock_init function and assigns the passed in
 
91
*               IP address and port to the IP address and port in the SOCKINFO
 
92
*               structure.
 
93
*
 
94
*       Return : int;
 
95
*               UPNP_E_SUCCESS  
 
96
*               UPNP_E_OUTOF_MEMORY
 
97
*               UPNP_E_SOCKET_ERROR
 
98
*
 
99
*       Note :
 
100
************************************************************************/
 
101
int sock_init_with_ip( OUT SOCKINFO* info, IN int sockfd, 
 
102
        IN struct in_addr foreign_ip_addr, IN unsigned short foreign_ip_port );
 
103
 
 
104
/************************************************************************
 
105
*       Function :      sock_read
 
106
*
 
107
*       Parameters :
 
108
*               IN SOCKINFO *info ;     Socket Information Object
 
109
*               OUT char* buffer ;      Buffer to get data to  
 
110
*               IN size_t bufsize ;     Size of the buffer
 
111
*           IN int *timeoutSecs ;       timeout value
 
112
*
 
113
*       Description :   Reads data on socket in sockinfo
 
114
*
 
115
*       Return : int;
 
116
*               numBytes - On Success, no of bytes received             
 
117
*               UPNP_E_TIMEDOUT - Timeout
 
118
*               UPNP_E_SOCKET_ERROR - Error on socket calls
 
119
*
 
120
*       Note :
 
121
************************************************************************/
 
122
int sock_read( IN SOCKINFO *info, OUT char* buffer, IN size_t bufsize,
 
123
                                 INOUT int *timeoutSecs );
 
124
 
 
125
/************************************************************************
 
126
*       Function :      sock_write
 
127
*
 
128
*       Parameters :
 
129
*               IN SOCKINFO *info ;     Socket Information Object
 
130
*               IN char* buffer ;       Buffer to send data from 
 
131
*               IN size_t bufsize ;     Size of the buffer
 
132
*           IN int *timeoutSecs ;       timeout value
 
133
*
 
134
*       Description :   Writes data on the socket in sockinfo
 
135
*
 
136
*       Return : int;
 
137
*               numBytes - On Success, no of bytes sent         
 
138
*               UPNP_E_TIMEDOUT - Timeout
 
139
*               UPNP_E_SOCKET_ERROR - Error on socket calls
 
140
*
 
141
*       Note :
 
142
************************************************************************/
 
143
int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize,
 
144
                                 INOUT int *timeoutSecs );
 
145
 
 
146
/************************************************************************
 
147
*       Function :      sock_destroy
 
148
*
 
149
*       Parameters :
 
150
*               INOUT SOCKINFO* info ;  Socket Information Object
 
151
*               int ShutdownMethod ;    How to shutdown the socket. Used by  
 
152
*                                                               sockets's shutdown() 
 
153
*
 
154
*       Description :   Shutsdown the socket using the ShutdownMethod to 
 
155
*               indicate whether sends and receives on the socket will be 
 
156
*               dis-allowed. After shutting down the socket, closesocket is called
 
157
*               to release system resources used by the socket calls.
 
158
*
 
159
*       Return : int;
 
160
*               UPNP_E_SOCKET_ERROR on failure
 
161
*               UPNP_E_SUCCESS on success
 
162
*
 
163
*       Note :
 
164
************************************************************************/
 
165
int sock_destroy( INOUT SOCKINFO* info,int );
 
166
 
 
167
#ifdef __cplusplus
 
168
}       // #extern "C"
 
169
#endif
 
170
 
 
171
 
 
172
#endif // GENLIB_NET_SOCK_H