mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-22 09:11:21 +00:00
Use RFC2732 notation for IPv6 addresses
This fixes keepbody and the connect command (also '-connect' parameter). connect ::1 connect [::1]:5029
This commit is contained in:
parent
f8a749be09
commit
0422870df8
4 changed files with 53 additions and 24 deletions
|
@ -1171,9 +1171,9 @@ static boolean CL_SendJoin(void)
|
|||
|
||||
static INT32 FindRejoinerNum(SINT8 node)
|
||||
{
|
||||
char strippednodeaddress[64];
|
||||
char addressbuffer[64];
|
||||
const char *nodeaddress;
|
||||
char *port;
|
||||
const char *strippednodeaddress;
|
||||
INT32 i;
|
||||
|
||||
// Make sure there is no dead dress before proceeding to the stripping
|
||||
|
@ -1184,10 +1184,8 @@ static INT32 FindRejoinerNum(SINT8 node)
|
|||
return -1;
|
||||
|
||||
// Strip the address of its port
|
||||
strcpy(strippednodeaddress, nodeaddress);
|
||||
port = strchr(strippednodeaddress, ':');
|
||||
if (port)
|
||||
*port = '\0';
|
||||
strcpy(addressbuffer, nodeaddress);
|
||||
strippednodeaddress = I_NetSplitAddress(addressbuffer, NULL);
|
||||
|
||||
// Check if any player matches the stripped address
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
|
@ -3426,14 +3424,13 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
|
|||
|
||||
if (server && I_GetNodeAddress)
|
||||
{
|
||||
char addressbuffer[64];
|
||||
const char *address = I_GetNodeAddress(node);
|
||||
char *port = NULL;
|
||||
if (address) // MI: fix msvcrt.dll!_mbscat crash?
|
||||
{
|
||||
strcpy(playeraddress[newplayernum], address);
|
||||
port = strchr(playeraddress[newplayernum], ':');
|
||||
if (port)
|
||||
*port = '\0';
|
||||
strcpy(addressbuffer, address);
|
||||
strcpy(playeraddress[newplayernum],
|
||||
I_NetSplitAddress(addressbuffer, NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
26
src/d_net.c
26
src/d_net.c
|
@ -1200,26 +1200,34 @@ static void Internal_FreeNodenum(INT32 nodenum)
|
|||
(void)nodenum;
|
||||
}
|
||||
|
||||
char *I_NetSplitAddress(char *host, char **port)
|
||||
{
|
||||
boolean v4 = (strchr(host, '.') != NULL);
|
||||
|
||||
host = strtok(host, v4 ? ":" : "[]");
|
||||
|
||||
if (port)
|
||||
*port = strtok(NULL, ":");
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
SINT8 I_NetMakeNode(const char *hostname)
|
||||
{
|
||||
SINT8 newnode = -1;
|
||||
if (I_NetMakeNodewPort)
|
||||
{
|
||||
char *localhostname = strdup(hostname);
|
||||
char *t = localhostname;
|
||||
const char *port;
|
||||
char *port;
|
||||
if (!localhostname)
|
||||
return newnode;
|
||||
|
||||
// retrieve portnum from address!
|
||||
strtok(localhostname, ":");
|
||||
port = strtok(NULL, ":");
|
||||
hostname = I_NetSplitAddress(localhostname, &port);
|
||||
|
||||
// remove the port in the hostname as we've it already
|
||||
while ((*t != ':') && (*t != '\0'))
|
||||
t++;
|
||||
*t = '\0';
|
||||
CONS_Printf("%s %s\n", hostname, port);
|
||||
|
||||
newnode = I_NetMakeNodewPort(localhostname, port);
|
||||
newnode = I_NetMakeNodewPort(hostname, port);
|
||||
free(localhostname);
|
||||
}
|
||||
return newnode;
|
||||
|
|
11
src/i_net.h
11
src/i_net.h
|
@ -109,6 +109,17 @@ extern boolean (*I_NetCanSend)(void);
|
|||
*/
|
||||
extern void (*I_NetFreeNodenum)(INT32 nodenum);
|
||||
|
||||
/**
|
||||
\brief split a string into address and port
|
||||
|
||||
\param address string to split
|
||||
|
||||
\param port double pointer to hold port component (optional)
|
||||
|
||||
\return address component
|
||||
*/
|
||||
extern char *I_NetSplitAddress(char *address, char **port);
|
||||
|
||||
/** \brief open a connection with specified address
|
||||
|
||||
\param address address to connect to
|
||||
|
|
21
src/i_tcp.c
21
src/i_tcp.c
|
@ -340,8 +340,14 @@ static inline void I_UPnP_rem(const char *port, const char * servicetype)
|
|||
|
||||
static const char *SOCK_AddrToStr(mysockaddr_t *sk)
|
||||
{
|
||||
static char s[64]; // 255.255.255.255:65535 or IPv6:65535
|
||||
static char s[64]; // 255.255.255.255:65535 or
|
||||
// [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535
|
||||
#ifdef HAVE_NTOP
|
||||
#ifdef HAVE_IPV6
|
||||
int v6 = (sk->any.sa_family == AF_INET6);
|
||||
#else
|
||||
int v6 = 0;
|
||||
#endif
|
||||
void *addr;
|
||||
|
||||
if(sk->any.sa_family == AF_INET)
|
||||
|
@ -355,14 +361,21 @@ static const char *SOCK_AddrToStr(mysockaddr_t *sk)
|
|||
|
||||
if(addr == NULL)
|
||||
sprintf(s, "No address");
|
||||
else if(inet_ntop(sk->any.sa_family, addr, s, sizeof (s)) == NULL)
|
||||
else if(inet_ntop(sk->any.sa_family, addr, &s[v6], sizeof (s) - v6) == NULL)
|
||||
sprintf(s, "Unknown family type, error #%u", errno);
|
||||
#ifdef HAVE_IPV6
|
||||
else if(sk->any.sa_family == AF_INET6 && sk->ip6.sin6_port != 0)
|
||||
strcat(s, va(":%d", ntohs(sk->ip6.sin6_port)));
|
||||
else if(sk->any.sa_family == AF_INET6)
|
||||
{
|
||||
s[0] = '[';
|
||||
strcat(s, "]");
|
||||
|
||||
if (sk->ip6.sin6_port != 0)
|
||||
strcat(s, va(":%d", ntohs(sk->ip6.sin6_port)));
|
||||
}
|
||||
#endif
|
||||
else if(sk->any.sa_family == AF_INET && sk->ip4.sin_port != 0)
|
||||
strcat(s, va(":%d", ntohs(sk->ip4.sin_port)));
|
||||
|
||||
#else
|
||||
if (sk->any.sa_family == AF_INET)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue