mirror of
https://github.com/ChronosX88/netsukuku.git
synced 2024-11-22 10:12:18 +00:00
netsplit.c format fix
This commit is contained in:
parent
f8a151e7fb
commit
37deedce61
368
src/netsplit.c
368
src/netsplit.c
@ -5,43 +5,52 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include "getaddrinfodnstest.c"
|
#include "getaddrinfodnstest.c"
|
||||||
|
|
||||||
int isValidIpv6Address(char *ipAddress)
|
int
|
||||||
|
isValidIpv6Address (char *ipAddress)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 sa;
|
struct sockaddr_in6 sa;
|
||||||
int result = inet_pton(AF_INET6, ipAddress, &(sa.sin6_addr));
|
int result = inet_pton (AF_INET6, ipAddress, &(sa.sin6_addr));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isValidIpv4Address(char *ipAddress)
|
int
|
||||||
|
isValidIpv4Address (char *ipAddress)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
int result = inet_pton(AF_INET, ipAddress, &(sa.sin_addr));
|
int result = inet_pton (AF_INET, ipAddress, &(sa.sin_addr));
|
||||||
if(result == 0) {
|
if (result == 0)
|
||||||
if(isValidIpv6Address(ipAddress) == 1)
|
{
|
||||||
return 11;
|
if (isValidIpv6Address (ipAddress) == 1)
|
||||||
else
|
return 11;
|
||||||
return 0;
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forwards packets to this IP through the inet
|
/* Forwards packets to this IP through the inet
|
||||||
* iptables forwarding rule. */
|
* iptables forwarding rule. */
|
||||||
void inetipForwarding(char *ipAddress, int family) {
|
void
|
||||||
return;
|
inetipForwarding (char *ipAddress, int family)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forwards packets to this IP through the ntk
|
/* Forwards packets to this IP through the ntk
|
||||||
* iptables forwarding rule. */
|
* iptables forwarding rule. */
|
||||||
void ntkipForwarding(char *ipAddress, int family) {
|
void
|
||||||
return;
|
ntkipForwarding (char *ipAddress, int family)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolves the ntk domain name in ANDNA,
|
/* Resolves the ntk domain name in ANDNA,
|
||||||
* Forwarding the originally desired packets
|
* Forwarding the originally desired packets
|
||||||
* through the ntk iptables forwarding rule. */
|
* through the ntk iptables forwarding rule. */
|
||||||
void ntkDNSResolution(char *domain) {
|
void
|
||||||
return;
|
ntkDNSResolution (char *domain)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolves the inet domain name via the commented out name servers
|
/* Resolves the inet domain name via the commented out name servers
|
||||||
@ -49,170 +58,193 @@ void ntkDNSResolution(char *domain) {
|
|||||||
* through the inet iptables forwarding rule.
|
* through the inet iptables forwarding rule.
|
||||||
* Then, Forwards the originally desired packets
|
* Then, Forwards the originally desired packets
|
||||||
* through the inet iptables forwarding rule. */
|
* through the inet iptables forwarding rule. */
|
||||||
void inetDNSResolution(char *domain) {
|
void
|
||||||
printf("Inet Domain name %s resolves to:\n", domain);
|
inetDNSResolution (char *domain)
|
||||||
getaddrinfodnsresolution(domain);
|
{
|
||||||
return;
|
printf ("Inet Domain name %s resolves to:\n", domain);
|
||||||
|
getaddrinfodnsresolution (domain);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inet_mode(char *domain) {
|
void
|
||||||
|
inet_mode (char *domain)
|
||||||
printf("inet_mode: %s\n", domain);
|
{
|
||||||
|
|
||||||
char *ret;
|
printf ("inet_mode: %s\n", domain);
|
||||||
char *ret1;
|
|
||||||
char new_domain[MAXNAMLEN];
|
char *ret;
|
||||||
int rt_value;
|
char *ret1;
|
||||||
|
char new_domain[MAXNAMLEN];
|
||||||
strcpy(new_domain, domain);
|
int rt_value;
|
||||||
|
|
||||||
ret = strstr(new_domain, ".ntk");
|
strcpy (new_domain, domain);
|
||||||
|
|
||||||
if(ret != NULL) {
|
ret = strstr (new_domain, ".ntk");
|
||||||
printf("inet_mode .ntk\n");
|
|
||||||
goto inet_mode_ntk_rslv;
|
if (ret != NULL)
|
||||||
|
{
|
||||||
|
printf ("inet_mode .ntk\n");
|
||||||
|
goto inet_mode_ntk_rslv;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strstr(new_domain, ".inet");
|
ret = strstr (new_domain, ".inet");
|
||||||
ret1 = strstr(new_domain, ".inet");
|
ret1 = strstr (new_domain, ".inet");
|
||||||
|
|
||||||
if(ret1 != NULL) {
|
if (ret1 != NULL)
|
||||||
new_domain[strlen(new_domain)-6] = '\0';
|
{
|
||||||
printf("inet_mode abbrevate: %s\n", new_domain);
|
new_domain[strlen (new_domain) - 6] = '\0';
|
||||||
|
printf ("inet_mode abbrevate: %s\n", new_domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret == NULL || ret1 != NULL) {
|
if (ret == NULL || ret1 != NULL)
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
{
|
||||||
if(rt_value == 1)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
inetipForwarding(new_domain, AF_INET);
|
if (rt_value == 1)
|
||||||
if(rt_value == 11)
|
inetipForwarding (new_domain, AF_INET);
|
||||||
inetipForwarding(new_domain, AF_INET6);
|
if (rt_value == 11)
|
||||||
if(rt_value == 0)
|
inetipForwarding (new_domain, AF_INET6);
|
||||||
inetDNSResolution(new_domain);
|
if (rt_value == 0)
|
||||||
printf("inet_mode normal\n");
|
inetDNSResolution (new_domain);
|
||||||
|
printf ("inet_mode normal\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strstr(new_domain, ".ntk");
|
ret = strstr (new_domain, ".ntk");
|
||||||
|
|
||||||
if(ret != NULL) {
|
if (ret != NULL)
|
||||||
inet_mode_ntk_rslv:
|
{
|
||||||
new_domain[strlen(new_domain)-5] = '\0';
|
inet_mode_ntk_rslv:
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
new_domain[strlen (new_domain) - 5] = '\0';
|
||||||
if(rt_value == 1)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
ntkipForwarding(new_domain, AF_INET);
|
if (rt_value == 1)
|
||||||
if(rt_value == 11)
|
ntkipForwarding (new_domain, AF_INET);
|
||||||
ntkipForwarding(new_domain, AF_INET6);
|
if (rt_value == 11)
|
||||||
if(rt_value == 0)
|
ntkipForwarding (new_domain, AF_INET6);
|
||||||
ntkDNSResolution(new_domain);
|
if (rt_value == 0)
|
||||||
printf("inet_mode abnormal\n");
|
ntkDNSResolution (new_domain);
|
||||||
|
printf ("inet_mode abnormal\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ntk_mode(char *domain) {
|
void
|
||||||
|
ntk_mode (char *domain)
|
||||||
printf("ntk_mode: %s\n", domain);
|
{
|
||||||
|
|
||||||
char *ret;
|
printf ("ntk_mode: %s\n", domain);
|
||||||
char *ret1;
|
|
||||||
char new_domain[MAXNAMLEN];
|
char *ret;
|
||||||
int rt_value;
|
char *ret1;
|
||||||
|
char new_domain[MAXNAMLEN];
|
||||||
strcpy(new_domain, domain);
|
int rt_value;
|
||||||
|
|
||||||
ret = strstr(new_domain, ".inet");
|
strcpy (new_domain, domain);
|
||||||
|
|
||||||
if(ret != NULL) {
|
ret = strstr (new_domain, ".inet");
|
||||||
printf("ntk_mode .inet\n");
|
|
||||||
goto ntk_mode_inet_rslv;
|
if (ret != NULL)
|
||||||
|
{
|
||||||
|
printf ("ntk_mode .inet\n");
|
||||||
|
goto ntk_mode_inet_rslv;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strstr(new_domain, ".ntk");
|
ret = strstr (new_domain, ".ntk");
|
||||||
ret1 = strstr(new_domain, ".ntk");
|
ret1 = strstr (new_domain, ".ntk");
|
||||||
|
|
||||||
if(ret1 != NULL) {
|
if (ret1 != NULL)
|
||||||
new_domain[strlen(new_domain)-5] = '\0';
|
{
|
||||||
printf("ntk_mode abbrevate: %s\n", new_domain);
|
new_domain[strlen (new_domain) - 5] = '\0';
|
||||||
|
printf ("ntk_mode abbrevate: %s\n", new_domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret == NULL || ret1 != NULL) {
|
if (ret == NULL || ret1 != NULL)
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
{
|
||||||
if(rt_value == 1)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
ntkipForwarding(new_domain, AF_INET);
|
if (rt_value == 1)
|
||||||
if(rt_value == 11)
|
ntkipForwarding (new_domain, AF_INET);
|
||||||
ntkipForwarding(new_domain, AF_INET6);
|
if (rt_value == 11)
|
||||||
if(rt_value == 0)
|
ntkipForwarding (new_domain, AF_INET6);
|
||||||
ntkDNSResolution(new_domain);
|
if (rt_value == 0)
|
||||||
printf("ntk_mode normal\n");
|
ntkDNSResolution (new_domain);
|
||||||
|
printf ("ntk_mode normal\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strstr(new_domain, ".inet");
|
ret = strstr (new_domain, ".inet");
|
||||||
|
|
||||||
if(ret != NULL) {
|
if (ret != NULL)
|
||||||
ntk_mode_inet_rslv:
|
{
|
||||||
new_domain[strlen(new_domain)-6] = '\0';
|
ntk_mode_inet_rslv:
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
new_domain[strlen (new_domain) - 6] = '\0';
|
||||||
if(rt_value == 1)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
inetipForwarding(new_domain, AF_INET);
|
if (rt_value == 1)
|
||||||
if(rt_value == 11)
|
inetipForwarding (new_domain, AF_INET);
|
||||||
inetipForwarding(new_domain, AF_INET6);
|
if (rt_value == 11)
|
||||||
if(rt_value == 0)
|
inetipForwarding (new_domain, AF_INET6);
|
||||||
inetDNSResolution(new_domain);
|
if (rt_value == 0)
|
||||||
printf("ntk_mode abnormal\n");
|
inetDNSResolution (new_domain);
|
||||||
|
printf ("ntk_mode abnormal\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void domain_ip_processing(char *domain) {
|
void
|
||||||
char *ret;
|
domain_ip_processing (char *domain)
|
||||||
char new_domain[MAXNAMLEN];
|
{
|
||||||
int rt_value;
|
char *ret;
|
||||||
int i;
|
char new_domain[MAXNAMLEN];
|
||||||
ret = strstr(domain, ".inet");
|
int rt_value;
|
||||||
strcpy(new_domain, domain);
|
int i;
|
||||||
if(ret != NULL) {
|
ret = strstr (domain, ".inet");
|
||||||
new_domain[strlen(new_domain)-6] = '\0';
|
strcpy (new_domain, domain);
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
if (ret != NULL)
|
||||||
if(rt_value == 1)
|
{
|
||||||
inetipForwarding(new_domain, AF_INET);
|
new_domain[strlen (new_domain) - 6] = '\0';
|
||||||
if(rt_value == 11)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
inetipForwarding(new_domain, AF_INET6);
|
if (rt_value == 1)
|
||||||
if(rt_value == 0)
|
inetipForwarding (new_domain, AF_INET);
|
||||||
inetDNSResolution(new_domain);
|
if (rt_value == 11)
|
||||||
|
inetipForwarding (new_domain, AF_INET6);
|
||||||
printf("This domain/ip address is an inet domain/ip address. %d\n", rt_value);
|
if (rt_value == 0)
|
||||||
|
inetDNSResolution (new_domain);
|
||||||
|
|
||||||
|
printf ("This domain/ip address is an inet domain/ip address. %d\n",
|
||||||
|
rt_value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strstr(domain, ".ntk");
|
ret = strstr (domain, ".ntk");
|
||||||
if(ret != NULL) {
|
if (ret != NULL)
|
||||||
new_domain[strlen(new_domain)-5] = '\0';
|
{
|
||||||
rt_value = isValidIpv4Address(new_domain);
|
new_domain[strlen (new_domain) - 5] = '\0';
|
||||||
if(rt_value == 1)
|
rt_value = isValidIpv4Address (new_domain);
|
||||||
ntkipForwarding(new_domain, AF_INET);
|
if (rt_value == 1)
|
||||||
if(rt_value == 11)
|
ntkipForwarding (new_domain, AF_INET);
|
||||||
ntkipForwarding(new_domain, AF_INET6);
|
if (rt_value == 11)
|
||||||
if(rt_value == 0)
|
ntkipForwarding (new_domain, AF_INET6);
|
||||||
ntkDNSResolution(new_domain);
|
if (rt_value == 0)
|
||||||
|
ntkDNSResolution (new_domain);
|
||||||
printf("This domain/ip address is an ntk domain/ip address. %d\n", rt_value);
|
|
||||||
|
printf ("This domain/ip address is an ntk domain/ip address. %d\n",
|
||||||
|
rt_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Domain/IP: %s %s\n", new_domain, domain);
|
printf ("Domain/IP: %s %s\n", new_domain, domain);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int
|
||||||
for (;;) {
|
main (void)
|
||||||
char *request = (char *)malloc(100);
|
{
|
||||||
printf("\n> ");
|
for (;;)
|
||||||
fgets(request, 100, stdin);
|
{
|
||||||
if(strcmp(request, "quit\n") == 0 || strcmp(request, "exit\n") == 0)
|
char *request = (char *) malloc (100);
|
||||||
exit(0);
|
printf ("\n> ");
|
||||||
fflush(stdin);
|
fgets (request, 100, stdin);
|
||||||
inet_mode(request);
|
if (strcmp (request, "quit\n") == 0 || strcmp (request, "exit\n") == 0)
|
||||||
free(request);
|
exit (0);
|
||||||
}
|
fflush (stdin);
|
||||||
|
inet_mode (request);
|
||||||
return 0;
|
free (request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user