libUPnP  1.6.20
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 "UpnpInet.h" /* for SOCKET, netinet/in */
45 #include "UpnpGlobal.h" /* for UPNP_INLINE */
46 
47 /* The following are not defined under winsock.h */
48 #ifndef SD_RECEIVE
49  #define SD_RECEIVE 0x00
50  #define SD_SEND 0x01
51  #define SD_BOTH 0x02
52 #endif
53 
55 typedef struct
56 {
60  struct sockaddr_storage foreign_sockaddr;
61 } SOCKINFO;
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
74  SOCKET sock)
75 {
76  int ret = -1;
77 
78  if (sock != INVALID_SOCKET)
79  ret = UpnpCloseSocket(sock);
80 
81  return ret;
82 }
83 
93 int sock_init(
95  SOCKINFO *info,
97  SOCKET sockfd);
98 
110  SOCKINFO* info,
112  SOCKET sockfd,
114  struct sockaddr *foreign_sockaddr);
115 
127 int sock_destroy(
129  SOCKINFO* info,
131  int ShutdownMethod);
132 
141 int sock_read(
143  SOCKINFO *info,
145  char* buffer,
147  size_t bufsize,
149  int *timeoutSecs);
150 
159 int sock_write(
161  SOCKINFO *info,
163  const char *buffer,
165  size_t bufsize,
167  int *timeoutSecs);
168 
175  /* [in] socket. */
176  SOCKET sock);
177 
184  /* [in] socket. */
185  SOCKET sock);
186 
187 #ifdef __cplusplus
188 } /* #extern "C" */
189 #endif
190 
191 /* @} Sock Network Socket Library */
192 
193 #endif /* GENLIB_NET_SOCK_H */
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:74
int sock_make_blocking(SOCKET sock)
Make socket blocking.
Definition: sock.c:224
int sock_write(SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs)
Writes data on the socket in sockinfo.
Definition: sock.c:218
#define INVALID_SOCKET
Definition: UpnpInet.h:56
int sock_read(SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs)
Reads data on socket in sockinfo.
Definition: sock.c:213
#define UpnpCloseSocket
Definition: UpnpInet.h:62
int sock_destroy(SOCKINFO *info, int ShutdownMethod)
Shutsdown the socket using the ShutdownMethod to indicate whether sends and receives on the socket wi...
Definition: sock.c:90
Provides a platform independent way to include TCP/IP types and functions.
Definition: sock.h:55
int SOCKET
Definition: UpnpInet.h:53
SOCKET socket
Definition: sock.h:58
static UPNP_INLINE int sock_close(SOCKET sock)
Closes the socket if it is different from -1.
Definition: sock.h:72
int sock_make_no_blocking(SOCKET sock)
Make socket non-blocking.
Definition: sock.c:241
int sock_init(SOCKINFO *info, SOCKET sockfd)
Assign the passed in socket descriptor to socket descriptor in the SOCKINFO structure.
Definition: sock.c:64
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:93
Defines constants that for some reason are not defined on some systems.