summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-02 13:42:36 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-02 13:42:36 +0000
commit573a9a5c5b9021e84267b34638770c13a99b4669 (patch)
tree9e1d3e6d04f69b2bdc2e5685751d6a17fb33ef12 /legacy
parent4797954c4d0f2de0ebeb4ab63aa527b534829316 (diff)
eeze 1.2 is now operational
SVN revision: 65809
Diffstat (limited to 'legacy')
-rw-r--r--legacy/eeze/configure.ac34
-rw-r--r--legacy/eeze/src/lib/Eeze_Net.h62
-rw-r--r--legacy/eeze/src/lib/Makefile.am2
-rw-r--r--legacy/eeze/src/lib/eeze_main.c34
-rw-r--r--legacy/eeze/src/lib/eeze_net.c319
-rw-r--r--legacy/eeze/src/lib/eeze_net_private.h53
6 files changed, 496 insertions, 8 deletions
diff --git a/legacy/eeze/configure.ac b/legacy/eeze/configure.ac
index 228cdc65d4..a300a02d32 100644
--- a/legacy/eeze/configure.ac
+++ b/legacy/eeze/configure.ac
@@ -153,6 +153,38 @@ fi
153if test -z "$OLD_LIBMOUNT_TRUE" ; then 153if test -z "$OLD_LIBMOUNT_TRUE" ; then
154 AC_DEFINE_UNQUOTED([OLD_LIBMOUNT], [1], [using first version of libmount]) 154 AC_DEFINE_UNQUOTED([OLD_LIBMOUNT], [1], [using first version of libmount])
155fi 155fi
156
157AC_CHECK_HEADERS([netinet/in.h])
158want_ipv6="yes"
159have_ipv6="no"
160
161AC_ARG_ENABLE([ipv6],
162 [AC_HELP_STRING([--disable-ipv6],
163 [disable ipv6 functionality @<:@default=detect@:>@])],
164 [
165 if test "x${enableval}" = "xyes" ; then
166 want_ipv6="yes"
167 else
168 want_ipv6="no"
169 fi],
170 [want_ipv6="auto"])
171
172# Verify IPV6 availability in headers
173if test "x${want_ipv6}" != "xno" ; then
174 AC_CHECK_TYPES([struct ipv6_mreq],
175 [have_ipv6="yes"],
176 [have_ipv6="no"],
177 [[
178#ifdef HAVE_NETINET_IN_H
179# include <netinet/in.h>
180#endif
181 ]])
182fi
183
184if test "x${have_ipv6}" = "xyes" ; then
185 AC_DEFINE(HAVE_IPV6, 1, [Define if IPV6 is supported])
186fi
187
156### Checks for header files 188### Checks for header files
157 189
158 190
@@ -226,6 +258,8 @@ echo
226echo "Utilities..............:" 258echo "Utilities..............:"
227echo " eeze_scanner.........: ${have_eeze_scanner}" 259echo " eeze_scanner.........: ${have_eeze_scanner}"
228echo 260echo
261echo "IPv6...................: ${have_ipv6}"
262echo
229echo "Documentation..........: ${build_doc}" 263echo "Documentation..........: ${build_doc}"
230echo 264echo
231echo "Compilation............: make (or gmake)" 265echo "Compilation............: make (or gmake)"
diff --git a/legacy/eeze/src/lib/Eeze_Net.h b/legacy/eeze/src/lib/Eeze_Net.h
new file mode 100644
index 0000000000..97a17ca00a
--- /dev/null
+++ b/legacy/eeze/src/lib/Eeze_Net.h
@@ -0,0 +1,62 @@
1#ifndef EEZE_NET_H
2#define EEZE_NET_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18#include <Eina.h>
19#include <Ecore.h>
20
21/**
22 * @file Eeze_Net.h
23 * @brief Network manipulation
24 *
25 * Eeze net functions allow you to gather information about network objects
26 *
27 * @addtogroup net Net
28 * @{
29 */
30
31typedef struct Eeze_Net Eeze_Net;
32
33typedef enum
34{
35 EEZE_NET_ADDR_TYPE_IP,
36 EEZE_NET_ADDR_TYPE_IP6,
37 EEZE_NET_ADDR_TYPE_BROADCAST,
38 EEZE_NET_ADDR_TYPE_BROADCAST6,
39 EEZE_NET_ADDR_TYPE_NETMASK,
40 EEZE_NET_ADDR_TYPE_NETMASK6,
41} Eeze_Net_Addr_Type;
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47EAPI Eeze_Net *eeze_net_new(const char *name);
48EAPI void eeze_net_free(Eeze_Net *net);
49EAPI const char *eeze_net_mac_get(Eeze_Net *net);
50EAPI int eeze_net_idx_get(Eeze_Net *net);
51EAPI Eina_Bool eeze_net_scan(Eeze_Net *net);
52EAPI const char *eeze_net_addr_get(Eeze_Net *net, Eeze_Net_Addr_Type type);
53EAPI const char *eeze_net_attribute_get(Eeze_Net *net, const char *attr);
54EAPI const char *eeze_net_syspath_get(Eeze_Net *net);
55EAPI Eina_List *eeze_net_list(void);
56
57#ifdef __cplusplus
58}
59#endif
60/** @} */
61
62#endif
diff --git a/legacy/eeze/src/lib/Makefile.am b/legacy/eeze/src/lib/Makefile.am
index e92fe459a2..3eedae976e 100644
--- a/legacy/eeze/src/lib/Makefile.am
+++ b/legacy/eeze/src/lib/Makefile.am
@@ -23,6 +23,8 @@ includesdir = $(includedir)/eeze-@VMAJ@
23 23
24libeeze_la_SOURCES = \ 24libeeze_la_SOURCES = \
25eeze_main.c \ 25eeze_main.c \
26eeze_net.c \
27eeze_net_private.h \
26eeze_udev_find.c \ 28eeze_udev_find.c \
27eeze_udev_private.h \ 29eeze_udev_private.h \
28eeze_udev_private.c \ 30eeze_udev_private.c \
diff --git a/legacy/eeze/src/lib/eeze_main.c b/legacy/eeze/src/lib/eeze_main.c
index 0ca5986799..e1fe7f0842 100644
--- a/legacy/eeze/src/lib/eeze_main.c
+++ b/legacy/eeze/src/lib/eeze_main.c
@@ -6,11 +6,13 @@
6#include <Eeze.h> 6#include <Eeze.h>
7#include <Eeze_Disk.h> 7#include <Eeze_Disk.h>
8#include "eeze_udev_private.h" 8#include "eeze_udev_private.h"
9#include "eeze_net_private.h"
9#include "eeze_disk_private.h" 10#include "eeze_disk_private.h"
10 11
11_udev *udev; 12_udev *udev;
12 13
13int _eeze_udev_log_dom = -1; 14int _eeze_udev_log_dom = -1;
15int _eeze_net_log_dom = -1;
14int _eeze_init_count = 0; 16int _eeze_init_count = 0;
15 17
16static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV }; 18static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV };
@@ -25,36 +27,51 @@ eeze_init(void)
25 if (!eina_init()) 27 if (!eina_init())
26 return 0; 28 return 0;
27 29
28 _eeze_udev_log_dom = eina_log_domain_register 30 _eeze_udev_log_dom = eina_log_domain_register("eeze_udev", EINA_COLOR_CYAN);
29 ("eeze_udev", EINA_COLOR_CYAN);
30
31 if (_eeze_udev_log_dom < 0) 31 if (_eeze_udev_log_dom < 0)
32 { 32 {
33 EINA_LOG_ERR("Could not register 'eeze_udev' log domain."); 33 EINA_LOG_ERR("Could not register 'eeze_udev' log domain.");
34 goto eina_fail; 34 goto eina_fail;
35 } 35 }
36 _eeze_net_log_dom = eina_log_domain_register("eeze_net", EINA_COLOR_GREEN);
37 if (_eeze_net_log_dom < 0)
38 {
39 EINA_LOG_ERR("Could not register 'eeze_net' log domain.");
40 goto eina_net_fail;
41 }
42
36 43
37 if (!ecore_init()) 44 if (!ecore_init())
38 goto fail; 45 goto ecore_fail;
39#ifdef HAVE_EEZE_MOUNT 46#ifdef HAVE_EEZE_MOUNT
40 if (!eeze_disk_init()) 47 if (!eeze_disk_init())
41 goto eeze_fail; 48 goto eeze_fail;
42#endif 49#endif
43 if (!((udev) = udev_new())) 50 if (!(udev = udev_new()))
44 { 51 {
45 EINA_LOG_ERR("Could not initialize udev library!"); 52 EINA_LOG_ERR("Could not initialize udev library!");
46 goto ecore_fail; 53 goto fail;
54 }
55 if (!eeze_net_init())
56 {
57 EINA_LOG_ERR("Error initializing eeze_net subsystems!");
58 goto net_fail;
47 } 59 }
48 60
49 return _eeze_init_count; 61 return _eeze_init_count;
50 62
51ecore_fail: 63net_fail:
64 udev_unref(udev);
65fail:
52#ifdef HAVE_EEZE_MOUNT 66#ifdef HAVE_EEZE_MOUNT
53 eeze_disk_shutdown(); 67 eeze_disk_shutdown();
54eeze_fail: 68eeze_fail:
55#endif 69#endif
56 ecore_shutdown(); 70 ecore_shutdown();
57fail: 71ecore_fail:
72 eina_log_domain_unregister(_eeze_net_log_dom);
73 _eeze_net_log_dom = -1;
74eina_net_fail:
58 eina_log_domain_unregister(_eeze_udev_log_dom); 75 eina_log_domain_unregister(_eeze_udev_log_dom);
59 _eeze_udev_log_dom = -1; 76 _eeze_udev_log_dom = -1;
60eina_fail: 77eina_fail:
@@ -72,6 +89,7 @@ eeze_shutdown(void)
72#ifdef HAVE_EEZE_MOUNT 89#ifdef HAVE_EEZE_MOUNT
73 eeze_disk_shutdown(); 90 eeze_disk_shutdown();
74#endif 91#endif
92 eeze_net_shutdown();
75 ecore_shutdown(); 93 ecore_shutdown();
76 eina_log_domain_unregister(_eeze_udev_log_dom); 94 eina_log_domain_unregister(_eeze_udev_log_dom);
77 _eeze_udev_log_dom = -1; 95 _eeze_udev_log_dom = -1;
diff --git a/legacy/eeze/src/lib/eeze_net.c b/legacy/eeze/src/lib/eeze_net.c
new file mode 100644
index 0000000000..a57f7ac4a4
--- /dev/null
+++ b/legacy/eeze/src/lib/eeze_net.c
@@ -0,0 +1,319 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <arpa/inet.h>
6#include <sys/ioctl.h>
7#include <net/if.h>
8#include <unistd.h>
9#include <Eeze_Net.h>
10
11#include "eeze_udev_private.h"
12#include "eeze_net_private.h"
13
14static Eina_Hash *eeze_nets = NULL;
15
16Eina_Bool
17eeze_net_init(void)
18{
19 eeze_nets = eina_hash_string_superfast_new(NULL);
20 return !!eeze_nets;
21}
22
23void
24eeze_net_shutdown(void)
25{
26 eina_hash_free(eeze_nets);
27 eeze_nets = NULL;
28}
29
30/** @addtogroup net Net
31 * @{
32 */
33
34/**
35 * @brief Create a new net object
36 * @param name The name of the underlying device (eth0, br1, etc)
37 * @return A newly allocated net object, or NULL on failure
38 *
39 * This function creates a new net object based on @p name.
40 * Only the most minimal lookups are performed at creation in order
41 * to save memory.
42 */
43Eeze_Net *
44eeze_net_new(const char *name)
45{
46 const char *syspath;
47 const char *idx;
48 _udev_enumerate *en;
49 _udev_list_entry *devs, *cur;
50 _udev_device *device;
51 Eeze_Net *net;
52
53 net = eina_hash_find(eeze_nets, name);
54 if (net)
55 {
56 EINA_REFCOUNT_REF(net);
57 return net;
58 }
59
60 en = udev_enumerate_new(udev);
61 udev_enumerate_add_match_sysname(en, name);
62 udev_enumerate_add_match_subsystem(en, "net");
63 udev_enumerate_scan_devices(en);
64 devs = udev_enumerate_get_list_entry(en);
65 udev_list_entry_foreach(cur, devs)
66 {
67 const char *devname, *test;
68
69 devname = udev_list_entry_get_name(cur);
70 test = strrchr(devname, '/');
71 if (strcmp(++test, name)) continue;
72 device = _new_device(devname);
73 syspath = eina_stringshare_add(name);
74 break;
75 }
76 if (!device) return NULL;
77 net = calloc(1, sizeof(Eeze_Net));
78 if (!net) return NULL;
79 EINA_REFCOUNT_INIT(net);
80 net->device = device;
81 net->syspath = syspath;
82 net->name = eina_stringshare_add(name);
83 idx = udev_device_get_sysattr_value(net->device, "ifindex");
84 net->index = atoi(idx);
85 eina_hash_add(eeze_nets, name, net);
86 udev_enumerate_unref(en);
87 return net;
88}
89
90/**
91 * @brief Free a net object
92 * @param net The object to free
93 *
94 * Use this function to free a net object.
95 * @see eeze_net_new()
96 * @see eeze_net_list()
97 */
98void
99eeze_net_free(Eeze_Net *net)
100{
101 EINA_SAFETY_ON_NULL_RETURN(net);
102
103 EINA_REFCOUNT_UNREF(net)
104 {
105 udev_device_unref(net->device);
106 eina_stringshare_del(net->syspath);
107 eina_stringshare_del(net->name);
108 eina_stringshare_del(net->ip);
109 eina_stringshare_del(net->broadip);
110 eina_stringshare_del(net->netmask);
111#ifdef HAVE_IPV6
112 eina_stringshare_del(net->ip6);
113 eina_stringshare_del(net->broadip6);
114 eina_stringshare_del(net->netmask6);
115#endif
116 free(net);
117 }
118}
119
120/**
121 * @brief Get the MAC address of a net object
122 * @param net The net object
123 * @return The MAC address, NULL on failure
124 * Use this function to retrieve the non-stringshared MAC address of @p net.
125 */
126const char *
127eeze_net_mac_get(Eeze_Net *net)
128{
129 EINA_SAFETY_ON_NULL_RETURN_VAL(net, NULL);
130
131 return udev_device_get_sysattr_value(net->device, "address");
132}
133
134/**
135 * @brief Get the index of a net object
136 * @param net The net object
137 * @return The ifindex of the object, -1 on failure
138 * Use this function to get the hardware index of @p net
139 */
140int
141eeze_net_idx_get(Eeze_Net *net)
142{
143 EINA_SAFETY_ON_NULL_RETURN_VAL(net, -1);
144 return net->index;
145}
146
147/**
148 * @brief Scan an interface to cache its network addresses
149 * @param net The net object to scan
150 * @return EINA_TRUE on success, EINA_FALSE on failure
151 * Use this function to scan and cache the ip address, netmask, and broadcast
152 * address for an interface. This function will perform a full scan every time
153 * it is called, and IPv6 addresses will be cached if Eeze was compiled with IPv6
154 * support was enabled at compile time.
155 * @see eeze_net_addr_get()
156 */
157Eina_Bool
158eeze_net_scan(Eeze_Net *net)
159{
160 char ip[INET_ADDRSTRLEN];
161#ifdef HAVE_IPV6
162 char ip6[INET6_ADDRSTRLEN];
163 struct sockaddr_in6 *sa6;
164#endif
165 int sock;
166 int ioctls[5] = {SIOCGIFADDR, SIOCGIFBRDADDR, SIOCGIFNETMASK}, *i = ioctls;
167 struct ifreq ifr;
168 struct sockaddr_in *sa;
169
170 EINA_SAFETY_ON_NULL_RETURN_VAL(net, EINA_FALSE);
171
172 /* ensure that we have the right name, mostly for hahas */
173 if_indextoname((unsigned int)net->index, ifr.ifr_name);
174 ifr.ifr_addr.sa_family = AF_INET;
175 sock = socket(AF_INET, SOCK_DGRAM, 0);
176 if (sock < 0) return EINA_FALSE;
177
178 if (ioctl(sock, *i++, &ifr) < 0) goto error;
179 sa = (struct sockaddr_in*) & (ifr.ifr_addr);
180 inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN);
181 eina_stringshare_replace_length(&net->ip, ip, INET_ADDRSTRLEN);
182
183 if (ioctl(sock, *i++, &ifr) < 0) goto error;
184 sa = (struct sockaddr_in*) & (ifr.ifr_broadaddr);
185 inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN);
186 eina_stringshare_replace_length(&net->broadip, ip, INET_ADDRSTRLEN);
187
188 if (ioctl(sock, *i++, &ifr) < 0) goto error;
189 sa = (struct sockaddr_in*) & (ifr.ifr_netmask);
190 inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN);
191 eina_stringshare_replace_length(&net->netmask, ip, INET_ADDRSTRLEN);
192
193 close(sock);
194#ifdef HAVE_IPV6
195 ifr.ifr_addr.sa_family = AF_INET6;
196 sock = socket(AF_INET6, SOCK_DGRAM, 0);
197 if (sock < 0) return EINA_FALSE;
198
199 if (ioctl(sock, *i++, &ifr) < 0) goto error;
200 sa6 = (struct sockaddr_in6*) & (ifr.ifr_addr);
201 inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN);
202 eina_stringshare_replace_length(&net->ip6, ip6, INET6_ADDRSTRLEN);
203
204 if (ioctl(sock, *i++, &ifr) < 0) goto error;
205 sa6 = (struct sockaddr_in6*) & (ifr.ifr_broadaddr);
206 inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN);
207 eina_stringshare_replace_length(&net->broadip6, ip6, INET6_ADDRSTRLEN);
208
209 if (ioctl(sock, *i++, &ifr) < 0) goto error;
210 sa6 = (struct sockaddr_in6*) & (ifr.ifr_netmask);
211 inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN);
212 eina_stringshare_replace_length(&net->netmask6, ip6, INET6_ADDRSTRLEN);
213
214 close(sock);
215#endif
216
217 return EINA_TRUE;
218error:
219 close(sock);
220 return EINA_FALSE;
221}
222
223/**
224 * @brief Get the address of a net object
225 * @param net The net object
226 * @param type The type of address to retrieve
227 * @return The stringshared address for @p net corresponding to @p type, NULL on failure
228 * This function returns a value previously cached.
229 * @see eeze_net_scan()
230 */
231const char *
232eeze_net_addr_get(Eeze_Net *net, Eeze_Net_Addr_Type type)
233{
234 EINA_SAFETY_ON_NULL_RETURN_VAL(net, NULL);
235
236 switch (type)
237 {
238 case EEZE_NET_ADDR_TYPE_IP6:
239#ifdef HAVE_IPV6
240 return net->ip6;
241#else
242 return NULL;
243#endif
244 case EEZE_NET_ADDR_TYPE_BROADCAST:
245 return net->broadip;
246 case EEZE_NET_ADDR_TYPE_BROADCAST6:
247#ifdef HAVE_IPV6
248 return net->broadip6;
249#else
250 return NULL;
251#endif
252 case EEZE_NET_ADDR_TYPE_NETMASK:
253 return net->netmask;
254 case EEZE_NET_ADDR_TYPE_NETMASK6:
255#ifdef HAVE_IPV6
256 return net->netmask6;
257#else
258 return NULL;
259#endif
260 default:
261 break;
262 }
263 return net->ip;
264}
265
266/**
267 * @brief Get a system attribute of a net object
268 * @param net The net object
269 * @param attr The attribute to retrieve
270 * @return The non-stringshared value of the attribute, NULL on failure
271 * Use this function to perform a udev sysattr lookup on the underlying device of @p net
272 */
273const char *
274eeze_net_attribute_get(Eeze_Net *net, const char *attr)
275{
276 EINA_SAFETY_ON_NULL_RETURN_VAL(net, NULL);
277 EINA_SAFETY_ON_NULL_RETURN_VAL(attr, NULL);
278 EINA_SAFETY_ON_TRUE_RETURN_VAL(!attr[0], NULL);
279
280 return udev_device_get_sysattr_value(net->device, attr);
281}
282
283/**
284 * @brief Get the /sys/ path of a net object
285 * @param net The net object
286 * @return The stringshared /sys/ path of the interface, NULL on failure
287 */
288const char *
289eeze_net_syspath_get(Eeze_Net *net)
290{
291 EINA_SAFETY_ON_NULL_RETURN_VAL(net, NULL);
292
293 return net->syspath;
294}
295
296/**
297 * @brief Get a list of all the network interfaces available
298 * @return A list of Eeze_Net objects
299 * Use this function to get all network interfaces available to the application.
300 * This list must be freed by the user.
301 */
302Eina_List *
303eeze_net_list(void)
304{
305 struct if_nameindex *ifs, *i;
306 Eina_List *ret = NULL;
307 Eeze_Net *net;
308
309 ifs = if_nameindex();
310 for (i = ifs; i && i->if_name && i->if_name[0]; i++)
311 {
312 net = eeze_net_new(i->if_name);
313 if (net) ret = eina_list_append(ret, net);
314 }
315
316 if_freenameindex(ifs);
317 return ret;
318}
319/** @} */
diff --git a/legacy/eeze/src/lib/eeze_net_private.h b/legacy/eeze/src/lib/eeze_net_private.h
new file mode 100644
index 0000000000..d9b8faf115
--- /dev/null
+++ b/legacy/eeze/src/lib/eeze_net_private.h
@@ -0,0 +1,53 @@
1#ifndef EEZE_NET_PRIVATE_H
2#define EEZE_NET_PRIVATE_H
3#include <Eeze.h>
4#include "eeze_udev_private.h"
5
6#ifndef EEZE_NET_COLOR_DEFAULT
7#define EEZE_NET_COLOR_DEFAULT EINA_COLOR_GREEN
8#endif
9extern int _eeze_net_log_dom;
10#ifdef CRI
11#undef CRI
12#endif
13
14#ifdef ERR
15#undef ERR
16#endif
17#ifdef INF
18#undef INF
19#endif
20#ifdef WARN
21#undef WARN
22#endif
23#ifdef DBG
24#undef DBG
25#endif
26
27#define CRI(...) EINA_LOG_DOM_CRIT(_eeze_net_log_dom, __VA_ARGS__)
28#define DBG(...) EINA_LOG_DOM_DBG(_eeze_net_log_dom, __VA_ARGS__)
29#define INF(...) EINA_LOG_DOM_INFO(_eeze_net_log_dom, __VA_ARGS__)
30#define WARN(...) EINA_LOG_DOM_WARN(_eeze_net_log_dom, __VA_ARGS__)
31#define ERR(...) EINA_LOG_DOM_ERR(_eeze_net_log_dom, __VA_ARGS__)
32
33struct Eeze_Net
34{
35 EINA_REFCOUNT;
36 int index;
37 _udev_device *device;
38 const char *syspath;
39 const char *name;
40
41 const char *ip;
42 const char *broadip;
43 const char *netmask;
44#ifdef HAVE_IPV6
45 const char *ip6;
46 const char *broadip6;
47 const char *netmask6;
48#endif
49};
50
51Eina_Bool eeze_net_init(void);
52void eeze_net_shutdown(void);
53#endif