libUPnP 1.8.0
|
00001 /************************************************************************** 00002 * 00003 * Copyright (c) 2000-2003 Intel Corporation 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * - Neither name of Intel Corporation nor the names of its contributors 00015 * may be used to endorse or promote products derived from this software 00016 * without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00026 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 **************************************************************************/ 00031 00032 00033 #ifndef GENLIB_NET_SOCK_H 00034 #define GENLIB_NET_SOCK_H 00035 00036 00037 #include "util.h" 00038 00039 00040 #ifdef WIN32 00041 /* Do not #include <netinet/in.h> */ 00042 #else 00043 #include <netinet/in.h> 00044 #endif 00045 00046 00047 /* Following variable is not defined under winsock.h */ 00048 #ifndef SD_RECEIVE 00049 #define SD_RECEIVE 0x00 00050 #define SD_SEND 0x01 00051 #define SD_BOTH 0x02 00052 #endif 00053 00054 00055 typedef struct 00056 { 00057 /* handle/descriptor to a socket */ 00058 SOCKET socket; 00059 00060 /* the following two fields are filled only in incoming requests; */ 00061 struct sockaddr_storage foreign_sockaddr; 00062 } SOCKINFO; 00063 00064 00065 #ifdef __cplusplus 00066 #extern "C" { 00067 #endif 00068 00069 00070 /************************************************************************ 00071 * Function : sock_init 00072 * 00073 * Parameters : 00074 * OUT SOCKINFO* info ; Socket Information Object 00075 * IN SOCKET sockfd ; Socket Descriptor 00076 * 00077 * Description : Assign the passed in socket descriptor to socket 00078 * descriptor in the SOCKINFO structure. 00079 * 00080 * Return : int; 00081 * UPNP_E_SUCCESS 00082 * UPNP_E_OUTOF_MEMORY 00083 * UPNP_E_SOCKET_ERROR 00084 * Note : 00085 ************************************************************************/ 00086 int sock_init(OUT SOCKINFO* info, IN SOCKET sockfd); 00087 00088 /************************************************************************ 00089 * Function : sock_init_with_ip 00090 * 00091 * Parameters : 00092 * OUT SOCKINFO* info ; Socket Information Object 00093 * IN SOCKET sockfd ; Socket Descriptor 00094 * IN struct sockaddr* foreign_sockaddr; Remote socket address 00095 * 00096 * Description : Calls the sock_init function and assigns the passed in 00097 * IP address and port to the IP address and port in the SOCKINFO 00098 * structure. 00099 * 00100 * Return : int; 00101 * UPNP_E_SUCCESS 00102 * UPNP_E_OUTOF_MEMORY 00103 * UPNP_E_SOCKET_ERROR 00104 * 00105 * Note : 00106 ************************************************************************/ 00107 int sock_init_with_ip( 00108 OUT SOCKINFO* info, 00109 IN SOCKET sockfd, 00110 IN struct sockaddr *foreign_sockaddr); 00111 00112 /************************************************************************ 00113 * Function : sock_read 00114 * 00115 * Parameters : 00116 * IN SOCKINFO *info ; Socket Information Object 00117 * OUT char* buffer ; Buffer to get data to 00118 * IN size_t bufsize ; Size of the buffer 00119 * IN int *timeoutSecs ; timeout value 00120 * 00121 * Description : Reads data on socket in sockinfo 00122 * 00123 * Return : int; 00124 * numBytes - On Success, no of bytes received 00125 * UPNP_E_TIMEDOUT - Timeout 00126 * UPNP_E_SOCKET_ERROR - Error on socket calls 00127 * 00128 * Note : 00129 ************************************************************************/ 00130 int sock_read( IN SOCKINFO *info, OUT char* buffer, IN size_t bufsize, 00131 INOUT int *timeoutSecs ); 00132 00133 /************************************************************************ 00134 * Function : sock_write 00135 * 00136 * Parameters : 00137 * IN SOCKINFO *info ; Socket Information Object 00138 * IN char* buffer ; Buffer to send data from 00139 * IN size_t bufsize ; Size of the buffer 00140 * IN int *timeoutSecs ; timeout value 00141 * 00142 * Description : Writes data on the socket in sockinfo 00143 * 00144 * Return : int; 00145 * numBytes - On Success, no of bytes sent 00146 * UPNP_E_TIMEDOUT - Timeout 00147 * UPNP_E_SOCKET_ERROR - Error on socket calls 00148 * 00149 * Note : 00150 ************************************************************************/ 00151 int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize, 00152 INOUT int *timeoutSecs ); 00153 00154 /************************************************************************ 00155 * Function : sock_destroy 00156 * 00157 * Parameters : 00158 * INOUT SOCKINFO* info ; Socket Information Object 00159 * int ShutdownMethod ; How to shutdown the socket. Used by 00160 * sockets's shutdown() 00161 * 00162 * Description : Shutsdown the socket using the ShutdownMethod to 00163 * indicate whether sends and receives on the socket will be 00164 * dis-allowed. After shutting down the socket, closesocket is called 00165 * to release system resources used by the socket calls. 00166 * 00167 * Return : int; 00168 * UPNP_E_SOCKET_ERROR on failure 00169 * UPNP_E_SUCCESS on success 00170 * 00171 * Note : 00172 ************************************************************************/ 00173 int sock_destroy(INOUT SOCKINFO* info, int); 00174 00175 00176 #ifdef __cplusplus 00177 } /* #extern "C" */ 00178 #endif 00179 00180 00181 #endif /* GENLIB_NET_SOCK_H */ 00182