summaryrefslogtreecommitdiff
path: root/core/LAN_discovery.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/LAN_discovery.c')
-rw-r--r--core/LAN_discovery.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c
index 67dc656b..ad1337ef 100644
--- a/core/LAN_discovery.c
+++ b/core/LAN_discovery.c
@@ -41,7 +41,7 @@ static uint32_t get_broadcast(void)
41 int i = 0; 41 int i = 0;
42 42
43 /* configure ifconf for the ioctl call */ 43 /* configure ifconf for the ioctl call */
44 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { 44 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
45 perror("[!] get_broadcast: socket() error"); 45 perror("[!] get_broadcast: socket() error");
46 return 0; 46 return 0;
47 } 47 }
@@ -51,15 +51,16 @@ static uint32_t get_broadcast(void)
51 ifconf.ifc_buf = (char *)i_faces; 51 ifconf.ifc_buf = (char *)i_faces;
52 ifconf.ifc_len = sizeof(i_faces); 52 ifconf.ifc_len = sizeof(i_faces);
53 count = ifconf.ifc_len / sizeof(struct ifreq); 53 count = ifconf.ifc_len / sizeof(struct ifreq);
54 if(ioctl(sock, SIOCGIFCONF, &ifconf) < 0) { 54
55 if (ioctl(sock, SIOCGIFCONF, &ifconf) < 0) {
55 perror("get_broadcast: ioctl() error"); 56 perror("get_broadcast: ioctl() error");
56 return 0; 57 return 0;
57 } 58 }
58 59
59 for(i = 0; i < count; i++) { 60 for (i = 0; i < count; i++) {
60 /* skip the loopback interface, as it's useless */ 61 /* skip the loopback interface, as it's useless */
61 if(strcmp(i_faces[i].ifr_name, "lo") != 0) { 62 if (strcmp(i_faces[i].ifr_name, "lo") != 0) {
62 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { 63 if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
63 perror("[!] get_broadcast: ioctl error"); 64 perror("[!] get_broadcast: ioctl error");
64 return 0; 65 return 0;
65 } 66 }
@@ -69,8 +70,10 @@ static uint32_t get_broadcast(void)
69 break; 70 break;
70 } 71 }
71 } 72 }
73
72 close(sock); 74 close(sock);
73 if(sock_holder == NULL) { 75
76 if (sock_holder == NULL) {
74 perror("[!] no broadcast device found"); 77 perror("[!] no broadcast device found");
75 return 0; 78 return 0;
76 } 79 }
@@ -83,14 +86,16 @@ static uint32_t get_broadcast(void)
83static IP broadcast_ip(void) 86static IP broadcast_ip(void)
84{ 87{
85 IP ip; 88 IP ip;
86 #ifdef __linux 89#ifdef __linux
87 ip.i = get_broadcast(); 90 ip.i = get_broadcast();
88 if(ip.i == 0) 91
92 if (ip.i == 0)
89 /* error errored, but try anyway? */ 93 /* error errored, but try anyway? */
90 ip.i = ~0; 94 ip.i = ~0;
91 #else 95
96#else
92 ip.i = ~0; 97 ip.i = ~0;
93 #endif 98#endif
94 return ip; 99 return ip;
95} 100}
96 101
@@ -100,14 +105,19 @@ static int LAN_ip(IP ip)
100{ 105{
101 if (ip.c[0] == 127)/* Loopback */ 106 if (ip.c[0] == 127)/* Loopback */
102 return 0; 107 return 0;
108
103 if (ip.c[0] == 10)/* 10.0.0.0 to 10.255.255.255 range */ 109 if (ip.c[0] == 10)/* 10.0.0.0 to 10.255.255.255 range */
104 return 0; 110 return 0;
111
105 if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31)/* 172.16.0.0 to 172.31.255.255 range */ 112 if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31)/* 172.16.0.0 to 172.31.255.255 range */
106 return 0; 113 return 0;
114
107 if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range */ 115 if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range */
108 return 0; 116 return 0;
117
109 if (ip.c[0] == 169 && ip.c[1] == 254 && ip.c[2] != 0 && ip.c[2] != 255)/* 169.254.1.0 to 169.254.254.255 range */ 118 if (ip.c[0] == 169 && ip.c[1] == 254 && ip.c[2] != 0 && ip.c[2] != 255)/* 169.254.1.0 to 169.254.254.255 range */
110 return 0; 119 return 0;
120
111 return -1; 121 return -1;
112} 122}
113 123
@@ -115,8 +125,10 @@ static int handle_LANdiscovery(IP_Port source, uint8_t *packet, uint32_t length)
115{ 125{
116 if (LAN_ip(source.ip) == -1) 126 if (LAN_ip(source.ip) == -1)
117 return 1; 127 return 1;
128
118 if (length != crypto_box_PUBLICKEYBYTES + 1) 129 if (length != crypto_box_PUBLICKEYBYTES + 1)
119 return 1; 130 return 1;
131
120 DHT_bootstrap(source, packet + 1); 132 DHT_bootstrap(source, packet + 1);
121 return 0; 133 return 0;
122} 134}