mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 10:48:29 +00:00
Get Cosmopolitan into releasable state
A new rollup tool now exists for flattening out the headers in a way that works better for our purposes than cpp. A lot of the API clutter has been removed. APIs that aren't a sure thing in terms of general recommendation are now marked internal. There's now a smoke test for the amalgamation archive and gigantic header file. So we can now guarantee you can use this project on the easiest difficulty setting without the gigantic repository. A website is being created, which is currently a work in progress: https://justine.storage.googleapis.com/cosmopolitan/index.html
This commit is contained in:
parent
dba7552c1e
commit
ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions
70
libc/sock/ipclassify.internal.h
Normal file
70
libc/sock/ipclassify.internal.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_SOCK_IPCLASSIFY_H_
|
||||
#define COSMOPOLITAN_LIBC_SOCK_IPCLASSIFY_H_
|
||||
#ifndef __STRICT_ANSI__
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/inaddr.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Returns true if address is part of standardized test-only subnet.
|
||||
*/
|
||||
forceinline bool istestip(int sin_family, void *sin_addr) {
|
||||
if (sin_family == AF_INET) {
|
||||
uint32_t ip4net24 = ntohl(*(const uint32_t *)sin_addr) & 0xffffff00u;
|
||||
if (ip4net24 == INADDR_TESTNET1 || ip4net24 == INADDR_TESTNET2 ||
|
||||
ip4net24 == INADDR_TESTNET3) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
eafnosupport();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if address is part of a local-only subnet.
|
||||
*/
|
||||
forceinline bool islocalip(int sin_family, void *sin_addr) {
|
||||
if (sin_family == AF_INET) {
|
||||
uint32_t ip4net8 = ntohl(*(const uint32_t *)sin_addr) & 0xff000000u;
|
||||
if (ip4net8 == 0x7f000000u) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
eafnosupport();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if address is part of a well-known private subnet.
|
||||
*/
|
||||
forceinline bool isprivateip(int sin_family, void *sin_addr) {
|
||||
if (sin_family == AF_INET) {
|
||||
uint32_t ip4 = ntohl(*(const uint32_t *)sin_addr);
|
||||
if ((0x0a000000u <= ip4 && ip4 <= 0x0affffffu) /* 10.0.0.0/8 */ ||
|
||||
(0xac100000u <= ip4 && ip4 <= 0xac1fffffu) /* 172.16.0.0/12 */ ||
|
||||
(0xc0a80000u <= ip4 && ip4 <= 0xc0a8ffffu) /* 192.168.0.0/16 */) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
eafnosupport();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if address is most likely part of the public Internet.
|
||||
*/
|
||||
forceinline bool ispublicip(int sin_family, void *sin_addr) {
|
||||
return !islocalip(sin_family, sin_addr) &&
|
||||
!isprivateip(sin_family, sin_addr) && !istestip(sin_family, sin_addr);
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* !ANSI */
|
||||
#endif /* COSMOPOLITAN_LIBC_SOCK_IPCLASSIFY_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue