summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/LAN_discovery.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c
index 85a9e7ef..e0da2217 100644
--- a/core/LAN_discovery.c
+++ b/core/LAN_discovery.c
@@ -27,17 +27,20 @@
27#define ERR_IOCTL 0 27#define ERR_IOCTL 0
28 28
29#ifdef __linux 29#ifdef __linux
30/* get the first working broadcast address that's not from "lo"
31 * returns higher than 0 on success
32 * returns ERR_IOCTL on error */
30uint32_t get_broadcast(void) 33uint32_t get_broadcast(void)
31{ 34{
32 /* not sure how many platforms this will 35 /* not sure how many platforms this will
33 * run on, so it's wrapped in __linux for now */ 36 * run on, so it's wrapped in __linux for now */
34 struct ifconf ifconf; 37 struct sockaddr_in *sock_holder = NULL;
35 struct ifreq i_faces[MAX_INTERFACES]; 38 struct ifreq i_faces[MAX_INTERFACES];
39 struct in_addr result;
40 struct ifconf ifconf;
36 int count = 0; 41 int count = 0;
37 int sock = 0; 42 int sock = 0;
38 int i = 0; 43 int i = 0;
39 struct sockaddr_in *sock_holder = NULL;
40 struct in_addr result;
41 44
42 /* configure ifconf for the ioctl call */ 45 /* configure ifconf for the ioctl call */
43 sock = socket(AF_INET, SOCK_STREAM, 0); 46 sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -55,7 +58,6 @@ uint32_t get_broadcast(void)
55 for(i = 0; i < count; i++) { 58 for(i = 0; i < count; i++) {
56 /* skip the loopback interface, as it's useless */ 59 /* skip the loopback interface, as it's useless */
57 if(strcmp(i_faces[i].ifr_name, "lo") != 0) { 60 if(strcmp(i_faces[i].ifr_name, "lo") != 0) {
58 fprintf(stderr, "device name: %s\n", i_faces[i].ifr_name);
59 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { 61 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
60 perror("[!] get_broadcast: ioctl error"); 62 perror("[!] get_broadcast: ioctl error");
61 return ERR_IOCTL; 63 return ERR_IOCTL;
@@ -72,7 +74,7 @@ uint32_t get_broadcast(void)
72 74
73 result.s_addr = sock_holder->sin_addr.s_addr; 75 result.s_addr = sock_holder->sin_addr.s_addr;
74 inet_ntop(AF_INET, &result, test, INET_ADDRSTRLEN); 76 inet_ntop(AF_INET, &result, test, INET_ADDRSTRLEN);
75 fputs(test, stderr); 77 fprintf(stderr, "broadcast address for %s: %s\n", i_faces[i].ifr_name, test);
76 getchar(); 78 getchar();
77 79
78 return sock_holder->sin_addr.s_addr; 80 return sock_holder->sin_addr.s_addr;