1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2000-2003 Intel Corporation
4
// All rights reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
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.
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.
30
///////////////////////////////////////////////////////////////////////////
32
#ifndef GENLIB_NET_SOCK_H
33
#define GENLIB_NET_SOCK_H
38
#include <netinet/in.h>
41
//Following variable is not defined under winsock.h
43
#define SD_RECEIVE 0x00
51
int socket; // handle/descriptor to a socket
53
// the following two fields are filled only in incoming requests;
54
struct in_addr foreign_ip_addr;
55
unsigned short foreign_ip_port;
63
/************************************************************************
64
* Function : sock_init
67
* OUT SOCKINFO* info ; Socket Information Object
68
* IN int sockfd ; Socket Descriptor
70
* Description : Assign the passed in socket descriptor to socket
71
* descriptor in the SOCKINFO structure.
78
************************************************************************/
79
int sock_init( OUT SOCKINFO* info, IN int sockfd );
81
/************************************************************************
82
* Function : sock_init_with_ip
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
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
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 );
104
/************************************************************************
105
* Function : sock_read
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
113
* Description : Reads data on socket in sockinfo
116
* numBytes - On Success, no of bytes received
117
* UPNP_E_TIMEDOUT - Timeout
118
* UPNP_E_SOCKET_ERROR - Error on socket calls
121
************************************************************************/
122
int sock_read( IN SOCKINFO *info, OUT char* buffer, IN size_t bufsize,
123
INOUT int *timeoutSecs );
125
/************************************************************************
126
* Function : sock_write
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
134
* Description : Writes data on the socket in sockinfo
137
* numBytes - On Success, no of bytes sent
138
* UPNP_E_TIMEDOUT - Timeout
139
* UPNP_E_SOCKET_ERROR - Error on socket calls
142
************************************************************************/
143
int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize,
144
INOUT int *timeoutSecs );
146
/************************************************************************
147
* Function : sock_destroy
150
* INOUT SOCKINFO* info ; Socket Information Object
151
* int ShutdownMethod ; How to shutdown the socket. Used by
152
* sockets's shutdown()
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.
160
* UPNP_E_SOCKET_ERROR on failure
161
* UPNP_E_SUCCESS on success
164
************************************************************************/
165
int sock_destroy( INOUT SOCKINFO* info,int );
172
#endif // GENLIB_NET_SOCK_H