libUPnP  1.8.0
sock.h
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 
33 #ifndef GENLIB_NET_SOCK_H
34 #define GENLIB_NET_SOCK_H
35 
36 
37 #include "util.h"
38 
39 
40 #ifdef WIN32
41  /* Do not #include <netinet/in.h> */
42 #else
43  #include <netinet/in.h>
44 #endif
45 
46 
47 /* Following variable is not defined under winsock.h */
48 #ifndef SD_RECEIVE
49 #define SD_RECEIVE 0x00
50 #define SD_SEND 0x01
51 #define SD_BOTH 0x02
52 #endif
53 
54 
55 typedef struct
56 {
57  /* handle/descriptor to a socket */
58  SOCKET socket;
59 
60  /* the following two fields are filled only in incoming requests; */
61  struct sockaddr_storage foreign_sockaddr;
62 } SOCKINFO;
63 
64 
65 #ifdef __cplusplus
66 #extern "C" {
67 #endif
68 
69 
70 /************************************************************************
71 * Function : sock_init
72 *
73 * Parameters :
74 * OUT SOCKINFO* info ; Socket Information Object
75 * IN SOCKET sockfd ; Socket Descriptor
76 *
77 * Description : Assign the passed in socket descriptor to socket
78 * descriptor in the SOCKINFO structure.
79 *
80 * Return : int;
81 * UPNP_E_SUCCESS
82 * UPNP_E_OUTOF_MEMORY
83 * UPNP_E_SOCKET_ERROR
84 * Note :
85 ************************************************************************/
86 int sock_init(OUT SOCKINFO* info, IN SOCKET sockfd);
87 
88 /************************************************************************
89 * Function : sock_init_with_ip
90 *
91 * Parameters :
92 * OUT SOCKINFO* info ; Socket Information Object
93 * IN SOCKET sockfd ; Socket Descriptor
94 * IN struct sockaddr* foreign_sockaddr; Remote socket address
95 *
96 * Description : Calls the sock_init function and assigns the passed in
97 * IP address and port to the IP address and port in the SOCKINFO
98 * structure.
99 *
100 * Return : int;
101 * UPNP_E_SUCCESS
102 * UPNP_E_OUTOF_MEMORY
103 * UPNP_E_SOCKET_ERROR
104 *
105 * Note :
106 ************************************************************************/
107 int sock_init_with_ip(
108  OUT SOCKINFO* info,
109  IN SOCKET sockfd,
110  IN struct sockaddr *foreign_sockaddr);
111 
112 /************************************************************************
113 * Function : sock_read
114 *
115 * Parameters :
116 * IN SOCKINFO *info ; Socket Information Object
117 * OUT char* buffer ; Buffer to get data to
118 * IN size_t bufsize ; Size of the buffer
119 * IN int *timeoutSecs ; timeout value
120 *
121 * Description : Reads data on socket in sockinfo
122 *
123 * Return : int;
124 * numBytes - On Success, no of bytes received
125 * UPNP_E_TIMEDOUT - Timeout
126 * UPNP_E_SOCKET_ERROR - Error on socket calls
127 *
128 * Note :
129 ************************************************************************/
130 int sock_read( IN SOCKINFO *info, OUT char* buffer, IN size_t bufsize,
131  INOUT int *timeoutSecs );
132 
133 /************************************************************************
134 * Function : sock_write
135 *
136 * Parameters :
137 * IN SOCKINFO *info ; Socket Information Object
138 * IN char* buffer ; Buffer to send data from
139 * IN size_t bufsize ; Size of the buffer
140 * IN int *timeoutSecs ; timeout value
141 *
142 * Description : Writes data on the socket in sockinfo
143 *
144 * Return : int;
145 * numBytes - On Success, no of bytes sent
146 * UPNP_E_TIMEDOUT - Timeout
147 * UPNP_E_SOCKET_ERROR - Error on socket calls
148 *
149 * Note :
150 ************************************************************************/
151 int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize,
152  INOUT int *timeoutSecs );
153 
154 /************************************************************************
155 * Function : sock_destroy
156 *
157 * Parameters :
158 * INOUT SOCKINFO* info ; Socket Information Object
159 * int ShutdownMethod ; How to shutdown the socket. Used by
160 * sockets's shutdown()
161 *
162 * Description : Shutsdown the socket using the ShutdownMethod to
163 * indicate whether sends and receives on the socket will be
164 * dis-allowed. After shutting down the socket, closesocket is called
165 * to release system resources used by the socket calls.
166 *
167 * Return : int;
168 * UPNP_E_SOCKET_ERROR on failure
169 * UPNP_E_SUCCESS on success
170 *
171 * Note :
172 ************************************************************************/
173 int sock_destroy(INOUT SOCKINFO* info, int);
174 
175 
176 #ifdef __cplusplus
177 } /* #extern "C" */
178 #endif
179 
180 
181 #endif /* GENLIB_NET_SOCK_H */
182 
Definition: sock.h:55