summaryrefslogtreecommitdiff
path: root/core/LAN_discovery.c
diff options
context:
space:
mode:
authorcharmlesscoin <charmlesscoin@gmail.com>2013-08-01 16:54:04 -0400
committercharmlesscoin <charmlesscoin@gmail.com>2013-08-01 16:54:04 -0400
commit4a5bc1f0fe8546407670413c953146ed03d9278d (patch)
tree4e752f7c09a0f14a62fa0f2d9878f75edd3692a3 /core/LAN_discovery.c
parent939c4afd2cf7bb4c06e4eb69f4411baf4293bf1b (diff)
removed debugging
Diffstat (limited to 'core/LAN_discovery.c')
-rw-r--r--core/LAN_discovery.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c
index e0da2217..72e00d32 100644
--- a/core/LAN_discovery.c
+++ b/core/LAN_discovery.c
@@ -24,26 +24,28 @@
24#include "LAN_discovery.h" 24#include "LAN_discovery.h"
25 25
26#define MAX_INTERFACES 16 26#define MAX_INTERFACES 16
27#define ERR_IOCTL 0
28 27
29#ifdef __linux 28#ifdef __linux
30/* get the first working broadcast address that's not from "lo" 29/* get the first working broadcast address that's not from "lo"
31 * returns higher than 0 on success 30 * returns higher than 0 on success
32 * returns ERR_IOCTL on error */ 31 * returns 0 on error */
33uint32_t get_broadcast(void) 32uint32_t get_broadcast(void)
34{ 33{
35 /* not sure how many platforms this will 34 /* not sure how many platforms this will
36 * run on, so it's wrapped in __linux for now */ 35 * run on, so it's wrapped in __linux for now */
37 struct sockaddr_in *sock_holder = NULL; 36 struct sockaddr_in *sock_holder = NULL;
38 struct ifreq i_faces[MAX_INTERFACES]; 37 struct ifreq i_faces[MAX_INTERFACES];
39 struct in_addr result;
40 struct ifconf ifconf; 38 struct ifconf ifconf;
41 int count = 0; 39 int count = 0;
42 int sock = 0; 40 int sock = 0;
43 int i = 0; 41 int i = 0;
44 42
45 /* configure ifconf for the ioctl call */ 43 /* configure ifconf for the ioctl call */
46 sock = socket(AF_INET, SOCK_STREAM, 0); 44 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
45 perror("[!] get_broadcast: socket() error");
46 return 0;
47 }
48
47 memset(i_faces, 0, sizeof(struct ifreq) * MAX_INTERFACES); 49 memset(i_faces, 0, sizeof(struct ifreq) * MAX_INTERFACES);
48 50
49 ifconf.ifc_buf = (char *)i_faces; 51 ifconf.ifc_buf = (char *)i_faces;
@@ -51,16 +53,15 @@ uint32_t get_broadcast(void)
51 count = ifconf.ifc_len / sizeof(struct ifreq); 53 count = ifconf.ifc_len / sizeof(struct ifreq);
52 if(ioctl(sock, SIOCGIFCONF, &ifconf) < 0) { 54 if(ioctl(sock, SIOCGIFCONF, &ifconf) < 0) {
53 perror("get_broadcast: ioctl() error"); 55 perror("get_broadcast: ioctl() error");
54 return ERR_IOCTL; 56 return 0;
55 } 57 }
56 58
57 fprintf(stderr, "count: %d\n", count);
58 for(i = 0; i < count; i++) { 59 for(i = 0; i < count; i++) {
59 /* skip the loopback interface, as it's useless */ 60 /* skip the loopback interface, as it's useless */
60 if(strcmp(i_faces[i].ifr_name, "lo") != 0) { 61 if(strcmp(i_faces[i].ifr_name, "lo") != 0) {
61 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { 62 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
62 perror("[!] get_broadcast: ioctl error"); 63 perror("[!] get_broadcast: ioctl error");
63 return ERR_IOCTL; 64 return 0;
64 } 65 }
65 66
66 /* just to clarify where we're getting the values from */ 67 /* just to clarify where we're getting the values from */
@@ -70,13 +71,6 @@ uint32_t get_broadcast(void)
70 } 71 }
71 close(sock); 72 close(sock);
72 73
73 char test[INET_ADDRSTRLEN];
74
75 result.s_addr = sock_holder->sin_addr.s_addr;
76 inet_ntop(AF_INET, &result, test, INET_ADDRSTRLEN);
77 fprintf(stderr, "broadcast address for %s: %s\n", i_faces[i].ifr_name, test);
78 getchar();
79
80 return sock_holder->sin_addr.s_addr; 74 return sock_holder->sin_addr.s_addr;
81} 75}
82#endif 76#endif
@@ -87,8 +81,8 @@ IP broadcast_ip()
87 IP ip; 81 IP ip;
88 #ifdef __linux 82 #ifdef __linux
89 ip.i = get_broadcast(); 83 ip.i = get_broadcast();
90 if(ip.i == ERR_IOCTL) 84 if(ip.i == 0)
91 /* ioctl errored, but try anyway? */ 85 /* error errored, but try anyway? */
92 ip.i = ~0; 86 ip.i = ~0;
93 #else 87 #else
94 ip.i = ~0; 88 ip.i = ~0;