mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
Adding copyright headers and support for specifying protocol (TCP/UDP)
This commit is contained in:
parent
65355994b3
commit
da406c3abb
@ -1,4 +1,30 @@
|
||||
/* Copyright (C) 2016 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (net_natt.h).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _LIBRETRO_SDK_NET_NATT_H
|
||||
#define _LIBRETRO_SDK_NET_NATT_H
|
||||
|
||||
#include <net/net_compat.h>
|
||||
#include <net/net_socket.h>
|
||||
|
||||
struct natt_status {
|
||||
/** The fdset to be selected upon to check for responses */
|
||||
@ -36,12 +62,16 @@ void natt_free(struct natt_status *status);
|
||||
/**
|
||||
* Make a port forwarding request. This may finish immediately or just send a
|
||||
* request to the network. */
|
||||
bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t addrlen);
|
||||
bool natt_open_port(struct natt_status *status, struct sockaddr *addr,
|
||||
socklen_t addrlen, enum socket_protocol proto);
|
||||
|
||||
/**
|
||||
* Make a port forwarding request when only the port is known. Forwards any
|
||||
* address it can find. */
|
||||
bool natt_open_port_any(struct natt_status *status, uint16_t port);
|
||||
bool natt_open_port_any(struct natt_status *status, uint16_t port,
|
||||
enum socket_protocol proto);
|
||||
|
||||
/** Check for port forwarding responses */
|
||||
bool natt_read(struct natt_status *status);
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,25 @@
|
||||
/* Copyright (C) 2016 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (net_natt.c).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -64,11 +86,12 @@ void natt_free(struct natt_status *status)
|
||||
/* Nothing */
|
||||
}
|
||||
|
||||
bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t addrlen)
|
||||
bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t addrlen, enum socket_protocol proto)
|
||||
{
|
||||
#if HAVE_MINIUPNPC
|
||||
char host[PATH_MAX_LENGTH], ext_host[PATH_MAX_LENGTH],
|
||||
port_str[6], ext_port_str[6];
|
||||
const char *proto_str;
|
||||
struct addrinfo hints = {0}, *ext_addrinfo;
|
||||
int r;
|
||||
|
||||
@ -79,16 +102,17 @@ bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t
|
||||
/* figure out the internal info */
|
||||
if (getnameinfo(addr, addrlen, host, PATH_MAX_LENGTH, port_str, 6, 0) != 0)
|
||||
return false;
|
||||
proto_str = (proto == SOCKET_PROTOCOL_UDP) ? "UDP" : "TCP";
|
||||
|
||||
/* add the port mapping */
|
||||
r = UPNP_AddAnyPortMapping(urls.controlURL, data.first.servicetype, port_str,
|
||||
port_str, host, "retroarch", "TCP", NULL, "3600", ext_port_str);
|
||||
port_str, host, "retroarch", proto_str, NULL, "3600", ext_port_str);
|
||||
if (r == 501 /* Action Failed */)
|
||||
{
|
||||
/* try the older AddPortMapping */
|
||||
memcpy(ext_port_str, port_str, 6);
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port_str,
|
||||
port_str, host, "retroarch", "TCP", NULL, "3600");
|
||||
port_str, host, "retroarch", proto_str, NULL, "3600");
|
||||
}
|
||||
fprintf(stderr, "ERROR: %d\n", r);
|
||||
if (r != 0)
|
||||
@ -130,7 +154,7 @@ bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t
|
||||
#endif
|
||||
}
|
||||
|
||||
bool natt_open_port_any(struct natt_status *status, uint16_t port)
|
||||
bool natt_open_port_any(struct natt_status *status, uint16_t port, enum socket_protocol proto)
|
||||
{
|
||||
struct net_ifinfo list;
|
||||
bool ret = false;
|
||||
@ -156,7 +180,7 @@ bool natt_open_port_any(struct natt_status *status, uint16_t port)
|
||||
/* make a request for this host */
|
||||
if (getaddrinfo_retro(entry->host, port_str, &hints, &addr) == 0)
|
||||
{
|
||||
ret = natt_open_port(status, addr->ai_addr, addr->ai_addrlen) || ret;
|
||||
ret = natt_open_port(status, addr->ai_addr, addr->ai_addrlen, proto) || ret;
|
||||
freeaddrinfo_retro(addr);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user