libUPnP 1.14.19
sock.h
Go to the documentation of this file.
1#ifndef GENLIB_NET_SOCK_H
2#define GENLIB_NET_SOCK_H
3
4/**************************************************************************
5 *
6 * Copyright (c) 2000-2003 Intel Corporation
7 * All rights reserved.
8 * Copyright (c) 2012 France Telecom All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither name of Intel Corporation nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 **************************************************************************/
35
44#include "UpnpGlobal.h" /* for UPNP_INLINE */
45#include "UpnpInet.h" /* for SOCKET, netinet/in */
46#include "autoconfig.h"
47#ifdef UPNP_ENABLE_OPEN_SSL
48 #include <openssl/ssl.h>
49#endif
50
51/* The following are not defined under winsock.h */
52#ifndef SD_RECEIVE
53 #define SD_RECEIVE 0x00
54 #define SD_SEND 0x01
55 #define SD_BOTH 0x02
56#endif
57
59typedef struct
60{
64 struct sockaddr_storage foreign_sockaddr;
65#ifdef UPNP_ENABLE_OPEN_SSL
66 SSL *ssl;
67#endif
68} SOCKINFO;
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
81 SOCKET sock)
82{
83 int ret = -1;
84
85 if (sock != INVALID_SOCKET)
86 ret = UpnpCloseSocket(sock);
87
88 return ret;
89}
90
100int sock_init(
102 SOCKINFO *info,
104 SOCKET sockfd);
105
117 SOCKINFO *info,
119 SOCKET sockfd,
121 struct sockaddr *foreign_sockaddr);
122
131#ifdef UPNP_ENABLE_OPEN_SSL
132int sock_ssl_connect(
134 SOCKINFO *info);
135#endif
136
148int sock_destroy(
150 SOCKINFO *info,
152 int ShutdownMethod);
153
162int sock_read(
164 SOCKINFO *info,
166 char *buffer,
168 size_t bufsize,
170 int *timeoutSecs);
171
180int sock_write(
182 SOCKINFO *info,
184 const char *buffer,
186 size_t bufsize,
188 int *timeoutSecs);
189
196 /* [in] socket. */
197 SOCKET sock);
198
205 /* [in] socket. */
206 SOCKET sock);
207
208#ifdef __cplusplus
209} /* #extern "C" */
210#endif
211
212/* @} Sock Network Socket Library */
213
214#endif /* GENLIB_NET_SOCK_H */
Defines constants that for some reason are not defined on some systems.
#define UPNP_INLINE
Declares an inline function.
Definition UpnpGlobal.h:112
Provides a platform independent way to include TCP/IP types and functions.
#define UpnpCloseSocket
Definition UpnpInet.h:57
SOCKET socket
Definition sock.h:62
int sock_write(SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs)
Writes data on the socket in sockinfo.
Definition sock.c:286
#define INVALID_SOCKET
Definition UpnpInet.h:51
int sock_init(SOCKINFO *info, SOCKET sockfd)
Assign the passed in socket descriptor to socket descriptor in the SOCKINFO structure.
Definition sock.c:73
int sock_destroy(SOCKINFO *info, int ShutdownMethod)
Associates an SSL object with the socket and begins the client-side SSL/TLS handshake.
Definition sock.c:119
static UPNP_INLINE int sock_close(SOCKET sock)
Closes the socket if it is different from -1.
Definition sock.h:79
int sock_read(SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs)
Reads data on socket in sockinfo.
Definition sock.c:281
int SOCKET
Definition UpnpInet.h:48
int sock_init_with_ip(SOCKINFO *info, SOCKET sockfd, struct sockaddr *foreign_sockaddr)
Calls the sock_init function and assigns the passed in IP address and port to the IP address and port...
Definition sock.c:83
int sock_make_blocking(SOCKET sock)
Make socket blocking.
Definition sock.c:293
int sock_make_no_blocking(SOCKET sock)
Make socket non-blocking.
Definition sock.c:309
Definition sock.h:60