diff options
author | pete <petewicken@gmail.com> | 2013-08-29 22:17:51 +0100 |
---|---|---|
committer | pete <petewicken@gmail.com> | 2013-08-29 22:17:51 +0100 |
commit | 82b8927af7f68bbfbf83bbb5ffbc747de7bc288f (patch) | |
tree | ba83cda597e8146c0d02128fb8424bec9201d730 /toxcore/LAN_discovery.c | |
parent | 792709e4e091ea587a642c548889ddbb866e9b5e (diff) |
Correct a lot of the grammar and spelling. Also spent a few hours fixing the comments so they follow a standard.
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r-- | toxcore/LAN_discovery.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 49f52ce7..736959c5 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -26,13 +26,15 @@ | |||
26 | #define MAX_INTERFACES 16 | 26 | #define MAX_INTERFACES 16 |
27 | 27 | ||
28 | #ifdef __linux | 28 | #ifdef __linux |
29 | /* get the first working broadcast address that's not from "lo" | 29 | /* Get the first working broadcast address that's not from "lo". |
30 | * returns higher than 0 on success | 30 | * returns higher than 0 on success. |
31 | * returns 0 on error */ | 31 | * returns 0 on error. |
32 | */ | ||
32 | static uint32_t get_broadcast(void) | 33 | static uint32_t get_broadcast(void) |
33 | { | 34 | { |
34 | /* not sure how many platforms this will | 35 | /* Not sure how many platforms this will run on, |
35 | * run on, so it's wrapped in __linux for now */ | 36 | * so it's wrapped in __linux for now. |
37 | */ | ||
36 | struct sockaddr_in *sock_holder = NULL; | 38 | struct sockaddr_in *sock_holder = NULL; |
37 | struct ifreq i_faces[MAX_INTERFACES]; | 39 | struct ifreq i_faces[MAX_INTERFACES]; |
38 | struct ifconf ifconf; | 40 | struct ifconf ifconf; |
@@ -40,7 +42,7 @@ static uint32_t get_broadcast(void) | |||
40 | int sock = 0; | 42 | int sock = 0; |
41 | int i = 0; | 43 | int i = 0; |
42 | 44 | ||
43 | /* configure ifconf for the ioctl call */ | 45 | /* Configure ifconf for the ioctl call. */ |
44 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | 46 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
45 | perror("[!] get_broadcast: socket() error"); | 47 | perror("[!] get_broadcast: socket() error"); |
46 | return 0; | 48 | return 0; |
@@ -58,14 +60,14 @@ static uint32_t get_broadcast(void) | |||
58 | } | 60 | } |
59 | 61 | ||
60 | for (i = 0; i < count; i++) { | 62 | for (i = 0; i < count; i++) { |
61 | /* skip the loopback interface, as it's useless */ | 63 | /* Skip the loopback interface, as it's useless. */ |
62 | if (strcmp(i_faces[i].ifr_name, "lo") != 0) { | 64 | if (strcmp(i_faces[i].ifr_name, "lo") != 0) { |
63 | if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { | 65 | if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { |
64 | perror("[!] get_broadcast: ioctl error"); | 66 | perror("[!] get_broadcast: ioctl error"); |
65 | return 0; | 67 | return 0; |
66 | } | 68 | } |
67 | 69 | ||
68 | /* just to clarify where we're getting the values from */ | 70 | /* Just to clarify where we're getting the values from. */ |
69 | sock_holder = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr; | 71 | sock_holder = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr; |
70 | break; | 72 | break; |
71 | } | 73 | } |
@@ -82,7 +84,7 @@ static uint32_t get_broadcast(void) | |||
82 | } | 84 | } |
83 | #endif | 85 | #endif |
84 | 86 | ||
85 | /* Return the broadcast ip */ | 87 | /* Return the broadcast ip. */ |
86 | static IP broadcast_ip(void) | 88 | static IP broadcast_ip(void) |
87 | { | 89 | { |
88 | IP ip; | 90 | IP ip; |
@@ -90,7 +92,7 @@ static IP broadcast_ip(void) | |||
90 | ip.i = get_broadcast(); | 92 | ip.i = get_broadcast(); |
91 | 93 | ||
92 | if (ip.i == 0) | 94 | if (ip.i == 0) |
93 | /* error errored, but try anyway? */ | 95 | /* Error occured, but try anyway? */ |
94 | ip.i = ~0; | 96 | ip.i = ~0; |
95 | 97 | ||
96 | #else | 98 | #else |
@@ -99,23 +101,24 @@ static IP broadcast_ip(void) | |||
99 | return ip; | 101 | return ip; |
100 | } | 102 | } |
101 | 103 | ||
102 | /*return 0 if ip is a LAN ip | 104 | /* return 0 if ip is a LAN ip. |
103 | return -1 if it is not */ | 105 | * return -1 if it is not. |
106 | */ | ||
104 | static int LAN_ip(IP ip) | 107 | static int LAN_ip(IP ip) |
105 | { | 108 | { |
106 | if (ip.c[0] == 127)/* Loopback */ | 109 | if (ip.c[0] == 127) /* Loopback. */ |
107 | return 0; | 110 | return 0; |
108 | 111 | ||
109 | if (ip.c[0] == 10)/* 10.0.0.0 to 10.255.255.255 range */ | 112 | if (ip.c[0] == 10) /* 10.0.0.0 to 10.255.255.255 range. */ |
110 | return 0; | 113 | return 0; |
111 | 114 | ||
112 | if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31)/* 172.16.0.0 to 172.31.255.255 range */ | 115 | if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31) /* 172.16.0.0 to 172.31.255.255 range. */ |
113 | return 0; | 116 | return 0; |
114 | 117 | ||
115 | if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range */ | 118 | if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range. */ |
116 | return 0; | 119 | return 0; |
117 | 120 | ||
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 */ | 121 | 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. */ |
119 | return 0; | 122 | return 0; |
120 | 123 | ||
121 | return -1; | 124 | return -1; |