summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-01 11:41:05 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-01 11:41:05 -0400
commitd534a052648cc0085d6d6e40c22701e2feb5b416 (patch)
treebe3d13f6d3bc21af1090b24c8f3d6f039dad35a6
parent7a08681af57254b9d6831de8321956f09b77b9fa (diff)
Removed code that didn't work.
-rw-r--r--core/LAN_discovery.c58
-rw-r--r--core/LAN_discovery.h8
2 files changed, 2 insertions, 64 deletions
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c
index 6170f2fb..0a23914d 100644
--- a/core/LAN_discovery.c
+++ b/core/LAN_discovery.c
@@ -23,67 +23,13 @@
23 23
24#include "LAN_discovery.h" 24#include "LAN_discovery.h"
25 25
26#define MAX_INTERFACES 16
27#define ERR_INTERFACES 0
28#define ERR_IOCTL 1
29 26
30#ifdef __linux 27/*Return the broadcast ip
31/* get the first running interface's broadcast IP, 28 TODO: make it return the real one, not the 255.255.255.255 one.*/
32 * return is higher than 0 on success
33 * ERR_IOCTL on an ioctl error
34 * ERR_INTERFACES on general error */
35uint32_t get_broadcast(void)
36{
37 /* not sure how many platforms this will
38 * run on, so it's wrapped in __linux for now */
39 struct ifconf ifconf;
40 struct ifreq i_faces[MAX_INTERFACES];
41 int count = 0;
42 int sock = 0;
43 int i = 0;
44 struct sockaddr_in *sock_holder = NULL;
45
46 /* configure ifconf for the ioctl call */
47 sock = socket(AF_INET, SOCK_STREAM, 0);
48 ifconf.ifc_buf = (char *)i_faces;
49 ifconf.ifc_len = sizeof(i_faces);
50 count = ifconf.ifc_len / sizeof(i_faces[0]);
51
52 for(i = 0; i < count; i++) {
53 /* skip the loopback interface, as it's useless */
54 if(strcmp(i_faces[i].ifr_name, "lo") != 0) {
55 if(ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
56 perror("[!] get_broadcast: ioctl error");
57 return 0;
58 }
59
60 /* just to clarify where we're getting the values from */
61 sock_holder = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
62 break;
63 }
64 }
65 close(sock);
66
67 if(sock_holder == NULL)
68 return ERR_INTERFACES;
69
70 return sock_holder->sin_addr.s_addr;
71}
72#endif
73
74/* Return the broadcast ip */
75IP broadcast_ip() 29IP broadcast_ip()
76{ 30{
77 IP ip; 31 IP ip;
78 #ifdef __linux
79 ip.i = get_broadcast();
80 if(ip.i == ERR_INTERFACES)
81 ip.i = ~0;
82 else if(ip.i == ERR_IOCTL)
83 ip.i = 0;
84 #else
85 ip.i = ~0; 32 ip.i = ~0;
86 #endif
87 return ip; 33 return ip;
88} 34}
89 35
diff --git a/core/LAN_discovery.h b/core/LAN_discovery.h
index 23391b90..4ca65c03 100644
--- a/core/LAN_discovery.h
+++ b/core/LAN_discovery.h
@@ -28,14 +28,6 @@
28 28
29#include "DHT.h" 29#include "DHT.h"
30 30
31/* used for get_broadcast() */
32#ifdef __linux
33#include <sys/ioctl.h>
34#include <arpa/inet.h>
35#include <linux/netdevice.h>
36#endif
37
38
39#ifdef __cplusplus 31#ifdef __cplusplus
40extern "C" { 32extern "C" {
41#endif 33#endif