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 // 00031 00032 #ifndef GENLIB_NET_SOCK_H 00033 #define GENLIB_NET_SOCK_H 00034 00035 #include "util.h" 00036 00037 #ifndef WIN32 00038 #include <netinet/in.h> 00039 #endif 00040 00041 //Following variable is not defined under winsock.h 00042 #ifndef SD_RECEIVE 00043 #define SD_RECEIVE 0x00 00044 #define SD_SEND 0x01 00045 #define SD_BOTH 0x02 00046 #endif 00047 00048 00049 typedef struct 00050 { 00051 int socket; // handle/descriptor to a socket 00052 00053 // the following two fields are filled only in incoming requests; 00054 struct in_addr foreign_ip_addr; 00055 unsigned short foreign_ip_port; 00056 00057 } SOCKINFO; 00058 00059 #ifdef __cplusplus 00060 #extern "C" { 00061 #endif 00062 00063 /************************************************************************ 00064 * Function : sock_init 00065 * 00066 * Parameters : 00067 * OUT SOCKINFO* info ; Socket Information Object 00068 * IN int sockfd ; Socket Descriptor 00069 * 00070 * Description : Assign the passed in socket descriptor to socket 00071 * descriptor in the SOCKINFO structure. 00072 * 00073 * Return : int; 00074 * UPNP_E_SUCCESS 00075 * UPNP_E_OUTOF_MEMORY 00076 * UPNP_E_SOCKET_ERROR 00077 * Note : 00078 ************************************************************************/ 00079 int sock_init( OUT SOCKINFO* info, IN int sockfd ); 00080 00081 /************************************************************************ 00082 * Function : sock_init_with_ip 00083 * 00084 * Parameters : 00085 * OUT SOCKINFO* info ; Socket Information Object 00086 * IN int sockfd ; Socket Descriptor 00087 * IN struct in_addr foreign_ip_addr ; Remote IP Address 00088 * IN unsigned short foreign_ip_port ; Remote Port number 00089 * 00090 * Description : Calls the sock_init function and assigns the passed in 00091 * IP address and port to the IP address and port in the SOCKINFO 00092 * structure. 00093 * 00094 * Return : int; 00095 * UPNP_E_SUCCESS 00096 * UPNP_E_OUTOF_MEMORY 00097 * UPNP_E_SOCKET_ERROR 00098 * 00099 * Note : 00100 ************************************************************************/ 00101 int sock_init_with_ip( OUT SOCKINFO* info, IN int sockfd, 00102 IN struct in_addr foreign_ip_addr, IN unsigned short foreign_ip_port ); 00103 00104 /************************************************************************ 00105 * Function : sock_read 00106 * 00107 * Parameters : 00108 * IN SOCKINFO *info ; Socket Information Object 00109 * OUT char* buffer ; Buffer to get data to 00110 * IN size_t bufsize ; Size of the buffer 00111 * IN int *timeoutSecs ; timeout value 00112 * 00113 * Description : Reads data on socket in sockinfo 00114 * 00115 * Return : int; 00116 * numBytes - On Success, no of bytes received 00117 * UPNP_E_TIMEDOUT - Timeout 00118 * UPNP_E_SOCKET_ERROR - Error on socket calls 00119 * 00120 * Note : 00121 ************************************************************************/ 00122 int sock_read( IN SOCKINFO *info, OUT char* buffer, IN size_t bufsize, 00123 INOUT int *timeoutSecs ); 00124 00125 00126 // check is socket is ok for writing 00127 int sock_check_w( IN SOCKINFO * info ); 00128 00129 /************************************************************************ 00130 * Function : sock_write 00131 * 00132 * Parameters : 00133 * IN SOCKINFO *info ; Socket Information Object 00134 * IN char* buffer ; Buffer to send data from 00135 * IN size_t bufsize ; Size of the buffer 00136 * IN int *timeoutSecs ; timeout value 00137 * 00138 * Description : Writes data on the socket in sockinfo 00139 * 00140 * Return : int; 00141 * numBytes - On Success, no of bytes sent 00142 * UPNP_E_TIMEDOUT - Timeout 00143 * UPNP_E_SOCKET_ERROR - Error on socket calls 00144 * 00145 * Note : 00146 ************************************************************************/ 00147 int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize, 00148 INOUT int *timeoutSecs ); 00149 00150 /************************************************************************ 00151 * Function : sock_destroy 00152 * 00153 * Parameters : 00154 * INOUT SOCKINFO* info ; Socket Information Object 00155 * int ShutdownMethod ; How to shutdown the socket. Used by 00156 * sockets's shutdown() 00157 * 00158 * Description : Shutsdown the socket using the ShutdownMethod to 00159 * indicate whether sends and receives on the socket will be 00160 * dis-allowed. After shutting down the socket, closesocket is called 00161 * to release system resources used by the socket calls. 00162 * 00163 * Return : int; 00164 * UPNP_E_SOCKET_ERROR on failure 00165 * UPNP_E_SUCCESS on success 00166 * 00167 * Note : 00168 ************************************************************************/ 00169 int sock_destroy( INOUT SOCKINFO* info,int ); 00170 00171 #ifdef __cplusplus 00172 } // #extern "C" 00173 #endif 00174 00175 00176 #endif // GENLIB_NET_SOCK_H
1.6.1