RetroArch
net_compat.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (net_compat.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef LIBRETRO_SDK_NETPLAY_COMPAT_H__
24 #define LIBRETRO_SDK_NETPLAY_COMPAT_H__
25 
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include <boolean.h>
31 #include <retro_inline.h>
32 #include <stdint.h>
33 
34 #if defined(_WIN32) && !defined(_XBOX)
35 #ifndef _WIN32_WINNT
36 #define _WIN32_WINNT 0x0501
37 #endif
38 
39 #define WIN32_LEAN_AND_MEAN
40 
41 #include <winsock2.h>
42 #include <windows.h>
43 #include <ws2tcpip.h>
44 
45 #ifndef MSG_NOSIGNAL
46 #define MSG_NOSIGNAL 0
47 #endif
48 
49 
50 #elif defined(_XBOX)
51 
52 #define NOD3D
53 #include <xtl.h>
54 #include <io.h>
55 
56 #elif defined(GEKKO)
57 
58 #include <network.h>
59 
60 #elif defined(VITA)
61 
62 #include <psp2/net/net.h>
63 #include <psp2/net/netctl.h>
64 
65 #define sockaddr_in SceNetSockaddrIn
66 #define sockaddr SceNetSockaddr
67 #define sendto sceNetSendto
68 #define recvfrom sceNetRecvfrom
69 #define socket(a,b,c) sceNetSocket("unknown",a,b,c)
70 #define bind sceNetBind
71 #define accept sceNetAccept
72 #define setsockopt sceNetSetsockopt
73 #define connect sceNetConnect
74 #define listen sceNetListen
75 #define send sceNetSend
76 #define recv sceNetRecv
77 #define MSG_DONTWAIT SCE_NET_MSG_DONTWAIT
78 #define AF_INET SCE_NET_AF_INET
79 #define AF_UNSPEC 0
80 #define INADDR_ANY SCE_NET_INADDR_ANY
81 #define INADDR_NONE 0xffffffff
82 #define SOCK_STREAM SCE_NET_SOCK_STREAM
83 #define SOCK_DGRAM SCE_NET_SOCK_DGRAM
84 #define SOL_SOCKET SCE_NET_SOL_SOCKET
85 #define SO_REUSEADDR SCE_NET_SO_REUSEADDR
86 #define SO_SNDBUF SCE_NET_SO_SNDBUF
87 #define SO_SNDTIMEO SCE_NET_SO_SNDTIMEO
88 #define SO_NBIO SCE_NET_SO_NBIO
89 #define htonl sceNetHtonl
90 #define ntohl sceNetNtohl
91 #define htons sceNetHtons
92 #define socklen_t unsigned int
93 
94 struct hostent
95 {
96  char *h_name;
97  char **h_aliases;
98  int h_addrtype;
99  int h_length;
100  char **h_addr_list;
101  char *h_addr;
102 };
103 
104 struct SceNetInAddr inet_aton(const char *ip_addr);
105 
106 #else
107 #include <sys/select.h>
108 #include <sys/types.h>
109 #include <sys/socket.h>
110 #include <netinet/in.h>
111 
112 #ifndef __PSL1GHT__
113 #include <netinet/tcp.h>
114 #endif
115 
116 #include <arpa/inet.h>
117 #include <netdb.h>
118 #include <fcntl.h>
119 
120 #if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
121 #include <cell/sysmodule.h>
122 #include <netex/net.h>
123 #include <netex/libnetctl.h>
124 #include <sys/timer.h>
125 
126 #ifndef EWOULDBLOCK
127 #define EWOULDBLOCK SYS_NET_EWOULDBLOCK
128 #endif
129 
130 #else
131 #include <signal.h>
132 #endif
133 
134 #endif
135 
136 #include <errno.h>
137 
138 #ifdef GEKKO
139 #define sendto(s, msg, len, flags, addr, tolen) net_sendto(s, msg, len, 0, addr, 8)
140 #define socket(domain, type, protocol) net_socket(domain, type, protocol)
141 #define bind(s, name, namelen) net_bind(s, name, namelen)
142 #define listen(s, backlog) net_listen(s, backlog)
143 #define accept(s, addr, addrlen) net_accept(s, addr, addrlen)
144 #define connect(s, addr, addrlen) net_connect(s, addr, addrlen)
145 #define send(s, data, size, flags) net_send(s, data, size, flags)
146 #define recv(s, mem, len, flags) net_recv(s, mem, len, flags)
147 #define recvfrom(s, mem, len, flags, from, fromlen) net_recvfrom(s, mem, len, flags, from, fromlen)
148 #define select(maxfdp1, readset, writeset, exceptset, timeout) net_select(maxfdp1, readset, writeset, exceptset, timeout)
149 #endif
150 
151 static INLINE bool isagain(int bytes)
152 {
153 #if defined(_WIN32)
154  if (bytes != SOCKET_ERROR)
155  return false;
156  if (WSAGetLastError() != WSAEWOULDBLOCK)
157  return false;
158  return true;
159 #elif defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
160  return (sys_net_errno == SYS_NET_EWOULDBLOCK) || (sys_net_errno == SYS_NET_EAGAIN);//35
161 #elif defined(VITA)
162  return (bytes<0 && (bytes == SCE_NET_ERROR_EAGAIN || bytes == SCE_NET_ERROR_EWOULDBLOCK));
163 #elif defined(WIIU)
164  return (bytes == -1) && ((socketlasterr() == SO_SUCCESS) || (socketlasterr() == SO_EWOULDBLOCK));
165 #else
166  return (bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
167 #endif
168 }
169 
170 #ifdef _XBOX
171 #define socklen_t int
172 
173 #ifndef h_addr
174 #define h_addr h_addr_list[0] /* for backward compatibility */
175 #endif
176 
177 #ifndef SO_KEEPALIVE
178 #define SO_KEEPALIVE 0 /* verify if correct */
179 #endif
180 #endif
181 
182 #ifndef MSG_NOSIGNAL
183 #define MSG_NOSIGNAL 0
184 #endif
185 
186 #ifndef _WIN32
187 #include <sys/time.h>
188 #include <unistd.h>
189 #endif
190 
191 /* Compatibility layer for legacy or incomplete BSD socket implementations.
192  * Only for IPv4. Mostly useful for the consoles which do not support
193  * anything reasonably modern on the socket API side of things. */
194 
195 #ifdef HAVE_SOCKET_LEGACY
196 
197 #define sockaddr_storage sockaddr_in
198 #define addrinfo addrinfo_retro__
199 
200 struct addrinfo
201 {
202  int ai_flags;
203  int ai_family;
204  int ai_socktype;
205  int ai_protocol;
206  size_t ai_addrlen;
207  struct sockaddr *ai_addr;
208  char *ai_canonname;
209  struct addrinfo *ai_next;
210 };
211 
212 #ifndef AI_PASSIVE
213 #define AI_PASSIVE 1
214 #endif
215 
216 /* gai_strerror() not used, so we skip that. */
217 
218 #endif
219 
220 uint16_t inet_htons(uint16_t hostshort);
221 
222 int inet_ptrton(int af, const char *src, void *dst);
223 
224 int getaddrinfo_retro(const char *node, const char *service,
225  struct addrinfo *hints, struct addrinfo **res);
226 
227 void freeaddrinfo_retro(struct addrinfo *res);
228 
236 bool network_init(void);
237 
243 void network_deinit(void);
244 
245 const char *inet_ntop_compat(int af, const void *src, char *dst, socklen_t cnt);
246 
247 bool udp_send_packet(const char *host, uint16_t port, const char *msg);
248 
249 #endif
#define h_addr
Definition: network.h:187
int getaddrinfo_retro(const char *node, const char *service, struct addrinfo *hints, struct addrinfo **res)
Definition: net_compat.c:168
#define const
Definition: zconf.h:217
#define INLINE
Definition: retro_inline.h:35
char ** h_aliases
Definition: network.h:232
Configuration options (set of defines)
Definition: ip_addr.h:41
int ai_family
Definition: netdb.h:24
GLuint res
Definition: glext.h:10520
includes all by default used to find thumbnails Please choose a single playlist first Add Entry Add Folder Select Files< multiple > Please fill out all required fields RetroArch updated successfully Please restart the application for the changes to take effect Contributors Move Down Load Remove Add Pass No shader passes Reset All Passes Download thumbnail Start on Download All Thumbnails This Playlist Configured in port
Definition: msg_hash_us.h:7699
#define EAGAIN
Definition: need_errno.h:42
Definition: network.h:230
int ai_flags
Definition: netdb.h:22
char ** h_addr_list
Definition: network.h:235
int inet_ptrton(int af, const char *src, void *dst)
Definition: net_compat.c:397
char * h_name
Definition: network.h:231
uint16_t inet_htons(uint16_t hostshort)
Definition: net_compat.c:380
void freeaddrinfo_retro(struct addrinfo *res)
Definition: net_compat.c:252
#define SO_EWOULDBLOCK
Definition: socket.h:30
#define SOCKET_ERROR
Definition: net_retropad_core.c:30
static const unsigned char msg[]
Definition: ccm.c:375
Definition: sockets.h:46
GLenum src
Definition: glext.h:6980
#define SO_SUCCESS
Definition: socket.h:29
static INLINE bool isagain(int bytes)
Definition: net_compat.h:151
bool udp_send_packet(const char *host, uint16_t port, const char *msg)
Definition: net_compat.c:601
struct addrinfo * ai_next
Definition: netdb.h:30
int socketlasterr(void)
int ai_protocol
Definition: netdb.h:26
s8_t inet_aton(const char *cp, struct in_addr *addr)
Definition: network_common.c:42
char * ai_canonname
Definition: netdb.h:28
struct sockaddr * ai_addr
Definition: netdb.h:29
bool network_init(void)
Definition: net_compat.c:269
#define EWOULDBLOCK
Definition: socket.h:33
Definition: netdb.h:21
int ai_addrlen
Definition: netdb.h:27
GLenum GLenum dst
Definition: glext.h:6980
int ai_socktype
Definition: netdb.h:25
const char * inet_ntop_compat(int af, const void *src, char *dst, socklen_t cnt)
Definition: net_compat.c:563
u16 h_addrtype
Definition: network.h:233
int errno
unsigned short uint16_t
Definition: stdint.h:125
uint32_t socklen_t
Definition: netdb.h:10
u16 h_length
Definition: network.h:234
void network_deinit(void)
Definition: net_compat.c:350