mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +00:00
- rework the parser to regain support for 1.2 ips. No longer uses
inet_pton for ipv4. These are untested (other than compiling), as I've got issues with the console I need to sort out.
This commit is contained in:
parent
d3e8e4ed11
commit
dcbc9ada26
1 changed files with 37 additions and 25 deletions
|
@ -1178,14 +1178,15 @@ qboolean
|
||||||
SV_StringToFilter (const char *address, ipfilter_t *f)
|
SV_StringToFilter (const char *address, ipfilter_t *f)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
byte b[16];
|
byte b[16] = {};
|
||||||
#else
|
#else
|
||||||
byte b[4];
|
byte b[4] = {};
|
||||||
#endif
|
#endif
|
||||||
int mask;
|
int mask = 0;
|
||||||
int i;
|
int i = 0;
|
||||||
char *s;
|
char *s;
|
||||||
char *slash;
|
char *slash;
|
||||||
|
char *c;
|
||||||
|
|
||||||
Con_Printf ("SV_StringToFilter: '%s'\n", address);
|
Con_Printf ("SV_StringToFilter: '%s'\n", address);
|
||||||
|
|
||||||
|
@ -1193,6 +1194,7 @@ SV_StringToFilter (const char *address, ipfilter_t *f)
|
||||||
if (!s)
|
if (!s)
|
||||||
Sys_Error ("SV_StringToFilter: memory allocation failure\n");
|
Sys_Error ("SV_StringToFilter: memory allocation failure\n");
|
||||||
|
|
||||||
|
// Parse out the mask (the /8 part)
|
||||||
if ((slash = strchr (s, '/'))) {
|
if ((slash = strchr (s, '/'))) {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
*slash = '\0';
|
*slash = '\0';
|
||||||
|
@ -1213,34 +1215,41 @@ SV_StringToFilter (const char *address, ipfilter_t *f)
|
||||||
} else
|
} else
|
||||||
mask = -1;
|
mask = -1;
|
||||||
|
|
||||||
|
// parse the ip for ipv6
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
// FIXME: we *must* fill in the extra bytes here if we're doing ipv6
|
if (inet_pton (AF_INET6, s, b) != 1) {
|
||||||
|
// FIXME: we *must* fill in the prefix bytes here if we're doing ipv6
|
||||||
#error Prefix bytes not set for parsing ipv4 addresses
|
#error Prefix bytes not set for parsing ipv4 addresses
|
||||||
#endif
|
#endif
|
||||||
i = inet_pton (AF_INET, s, b);
|
c = s;
|
||||||
if (i == 1) {
|
|
||||||
if (mask == -1) {
|
// parse for ipv4, as dotted quad, only we have implicit trailing segments
|
||||||
if (!b[3]) { // FIXME: should check a cvar
|
do {
|
||||||
if (!b[2]) {
|
int j;
|
||||||
if (!b[1]) {
|
if (*c == '.')
|
||||||
if (!b[0]) {
|
c++;
|
||||||
mask = 0;
|
j = strtol (c, &c, 10);
|
||||||
} else
|
if (j < 0 || j > 255)
|
||||||
mask = 8;
|
|
||||||
} else
|
|
||||||
mask = 16;
|
|
||||||
} else
|
|
||||||
mask = 24;
|
|
||||||
} else
|
|
||||||
mask = 32;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#ifdef HAVE_IPV6
|
|
||||||
i = inet_pton (AF_INET6, s, b);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (i != 1)
|
|
||||||
goto bad_address;
|
goto bad_address;
|
||||||
|
if (i >= sizeof (b))
|
||||||
|
goto bad_address;
|
||||||
|
b[i++] = j;
|
||||||
|
} while (*c == '.');
|
||||||
|
if (*c)
|
||||||
|
goto bad_address;
|
||||||
|
|
||||||
|
// change trailing 0 segments to be a mask, eg 1.2.0.0 gives a /16 mask
|
||||||
|
// FIXME: should check a cvar
|
||||||
|
if (mask == -1) {
|
||||||
|
i = sizeof (b) - 1;
|
||||||
|
while (i >= 0 && !b[i]) {
|
||||||
|
mask += 8;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if (mask > 128)
|
if (mask > 128)
|
||||||
|
@ -1249,7 +1258,10 @@ SV_StringToFilter (const char *address, ipfilter_t *f)
|
||||||
#endif
|
#endif
|
||||||
goto bad_address;
|
goto bad_address;
|
||||||
|
|
||||||
|
// incase they did 1.2.3.4/16, change it to 1.2.0.0 for easier comparison
|
||||||
SV_MaskIPTrim (b, mask);
|
SV_MaskIPTrim (b, mask);
|
||||||
|
|
||||||
|
// yada :)
|
||||||
f->mask = mask;
|
f->mask = mask;
|
||||||
SV_IPCopy (f->ip, b);
|
SV_IPCopy (f->ip, b);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue