1 /* Copyright  (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (net_natt.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_NET_NATT_H
24 #define _LIBRETRO_SDK_NET_NATT_H
25 
26 #include <net/net_compat.h>
27 #include <net/net_socket.h>
28 
29 #include <retro_common_api.h>
30 
31 RETRO_BEGIN_DECLS
32 
33 struct natt_status
34 {
35    /** nfds for select when checking for input */
36    int nfds;
37 
38    /** The fdset to be selected upon to check for responses */
39    fd_set fds;
40 
41    /** True if there might be a request outstanding */
42    bool request_outstanding;
43 
44    /** True if we've resolved an external IPv4 address */
45    bool have_inet4;
46 
47    /** External IPv4 address */
48    struct sockaddr_in ext_inet4_addr;
49 
50    /** True if we've resolved an external IPv6 address */
51    bool have_inet6;
52 
53 #if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY)
54    /** External IPv6 address */
55    struct sockaddr_in6 ext_inet6_addr;
56 #endif
57 
58    /** Internal status (currently unused) */
59    void *internal;
60 };
61 
62 /**
63  * Initialize global NAT traversal structures (must be called once to use other
64  * functions) */
65 void natt_init(void);
66 
67 /** Initialize a NAT traversal status object */
68 bool natt_new(struct natt_status *status);
69 
70 /** Free a NAT traversal status object */
71 void natt_free(struct natt_status *status);
72 
73 /**
74  * Make a port forwarding request when only the port is known. Forwards any
75  * address it can find. */
76 bool natt_open_port_any(struct natt_status *status, uint16_t port,
77    enum socket_protocol proto);
78 
79 /** Check for port forwarding responses */
80 bool natt_read(struct natt_status *status);
81 
82 RETRO_END_DECLS
83 
84 #endif
85