Coverage Report

Created: 2026-08-13 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pupnp/upnp/src/inc/sock.h
Line
Count
Source
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
36
/*!
37
 * \defgroup Sock Network Socket Library
38
 *
39
 * @{
40
 *
41
 * \file
42
 */
43
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
0
  #define SD_BOTH 0x02
56
#endif
57
58
/*! */
59
typedef struct
60
{
61
  /*! Handle/descriptor to a socket. */
62
  SOCKET socket;
63
  /*! The following two fields are filled only in incoming requests. */
64
  struct sockaddr_storage foreign_sockaddr;
65
#ifdef UPNP_ENABLE_OPEN_SSL
66
  SSL *ssl;
67
#endif
68
} SOCKINFO;
69
70
#ifdef __cplusplus
71
extern "C" {
72
#endif
73
74
/*!
75
 * \brief Closes the socket if it is different from -1.
76
 *
77
 * \return -1 if an error occurred or if the socket is -1.
78
 */
79
static UPNP_INLINE int sock_close(
80
  /*! Socket descriptor. */
81
  SOCKET sock)
82
0
{
83
0
  int ret = -1;
84
85
0
  if (sock != INVALID_SOCKET)
86
0
    ret = UpnpCloseSocket(sock);
87
88
0
  return ret;
89
0
}
Unexecuted instantiation: upnpapi.c:sock_close
Unexecuted instantiation: miniserver.c:sock_close
Unexecuted instantiation: sock.c:sock_close
Unexecuted instantiation: httpreadwrite.c:sock_close
Unexecuted instantiation: webserver.c:sock_close
Unexecuted instantiation: urlconfig.c:sock_close
Unexecuted instantiation: gena_callback2.c:sock_close
Unexecuted instantiation: gena_ctrlpt.c:sock_close
Unexecuted instantiation: gena_device.c:sock_close
Unexecuted instantiation: soap_ctrlpt.c:sock_close
Unexecuted instantiation: soap_device.c:sock_close
Unexecuted instantiation: ssdp_ctrlpt.c:sock_close
Unexecuted instantiation: ssdp_server.c:sock_close
Unexecuted instantiation: soap_common.c:sock_close
Unexecuted instantiation: ssdp_device.c:sock_close
90
91
/*!
92
 * \brief Assign the passed in socket descriptor to socket descriptor in the
93
 * SOCKINFO structure.
94
 *
95
 * \return Integer:
96
 * \li \c UPNP_E_SUCCESS
97
 * \li \c UPNP_E_OUTOF_MEMORY
98
 * \li \c UPNP_E_SOCKET_ERROR
99
 */
100
int sock_init(
101
  /*! [out] Socket Information Object. */
102
  SOCKINFO *info,
103
  /*! [in] Socket Descriptor. */
104
  SOCKET sockfd);
105
106
/*!
107
 * \brief Calls the sock_init function and assigns the passed in IP address
108
 * and port to the IP address and port in the SOCKINFO structure.
109
 *
110
 * \return Integer:
111
 * \li \c UPNP_E_SUCCESS
112
 * \li \c UPNP_E_OUTOF_MEMORY
113
 * \li \c UPNP_E_SOCKET_ERROR
114
 */
115
int sock_init_with_ip(
116
  /*! [out] Socket Information Object. */
117
  SOCKINFO *info,
118
  /*! [in] Socket Descriptor. */
119
  SOCKET sockfd,
120
  /*! [in] Remote socket address. */
121
  struct sockaddr *foreign_sockaddr);
122
123
/*!
124
 * \brief Associates an SSL object with the socket and begins
125
 * the client-side SSL/TLS handshake.
126
 *
127
 * \return Integer:
128
 * \li \c UPNP_E_SUCCESS
129
 * \li \c UPNP_E_SOCKET_ERROR
130
 */
131
#ifdef UPNP_ENABLE_OPEN_SSL
132
int sock_ssl_connect(
133
  /*! [out] Socket Information Object. */
134
  SOCKINFO *info);
135
#endif
136
137
/*!
138
 * \brief Shutsdown the socket using the ShutdownMethod to indicate whether
139
 * sends and receives on the socket will be dis-allowed.
140
 *
141
 * After shutting down the socket, closesocket is called to release system
142
 * resources used by the socket calls.
143
 *
144
 * \return Integer:
145
 * \li \c UPNP_E_SOCKET_ERROR on failure.
146
 * \li \c UPNP_E_SUCCESS on success.
147
 */
148
int sock_destroy(
149
  /*! [in,out] Socket Information Object. */
150
  SOCKINFO *info,
151
  /*! [in] How to shutdown the socket. Used by sockets's shutdown(). */
152
  int ShutdownMethod);
153
154
/*!
155
 * \brief Reads data on socket in sockinfo.
156
 *
157
 * \return Integer:
158
 * \li \c numBytes - On Success, no of bytes received.
159
 * \li \c UPNP_E_TIMEDOUT - Timeout.
160
 * \li \c UPNP_E_SOCKET_ERROR - Error on socket calls.
161
 */
162
int sock_read(
163
  /*! [in] Socket Information Object. */
164
  SOCKINFO *info,
165
  /*! [out] Buffer to get data to. */
166
  char *buffer,
167
  /*! [in] Size of the buffer. */
168
  size_t bufsize,
169
  /*! [in,out] timeout value. */
170
  int *timeoutSecs);
171
172
/*!
173
 * \brief Writes data on the socket in sockinfo.
174
 *
175
 * \return Integer:
176
 * \li \c numBytes - On Success, no of bytes received.
177
 * \li \c UPNP_E_TIMEDOUT - Timeout.
178
 * \li \c UPNP_E_SOCKET_ERROR - Error on socket calls.
179
 */
180
int sock_write(
181
  /*! [in] Socket Information Object. */
182
  SOCKINFO *info,
183
  /*! [in] Buffer to send data from. */
184
  const char *buffer,
185
  /*! [in] Size of the buffer. */
186
  size_t bufsize,
187
  /*! [in,out] timeout value. */
188
  int *timeoutSecs);
189
190
/*!
191
 * \brief Make socket blocking.
192
 *
193
 * \return 0 if successful, -1 otherwise.
194
 */
195
int sock_make_blocking(
196
  /* [in] socket. */
197
  SOCKET sock);
198
199
/*!
200
 * \brief Make socket non-blocking.
201
 *
202
 * \return 0 if successful, -1 otherwise.
203
 */
204
int sock_make_no_blocking(
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 */