summaryrefslogtreecommitdiff
path: root/net/kphone/patches/patch-ac
blob: 5816e2f996c7b21091fd29711455d8caede51504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
$NetBSD: patch-ac,v 1.3 2005/12/05 20:50:46 rillig Exp $

--- dissipate2/siputil.cpp.orig	2005-06-21 12:14:49.000000000 +0100
+++ dissipate2/siputil.cpp	2005-11-24 16:47:03.000000000 +0000
@@ -5,6 +5,9 @@
 #include <sys/time.h>
 #include <sys/errno.h>
 #include <sys/ioctl.h>
+#if defined (__FreeBSD__) || defined(__NetBSD__)
+#include <ifaddrs.h>
+#endif
 #include <net/if_arp.h>
 #include <net/route.h>
 #include <net/if.h>
@@ -13,6 +16,7 @@
 #include <qobject.h>
 #include <qmessagebox.h>
 #include <netdb.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -26,6 +30,8 @@
 /* max number of network interfaces*/
 #define MAX_IF 5
 
+#ifdef __linux__
+
 /* Path to the route entry in proc filesystem */
 #define PROCROUTE "/proc/net/route"
 
@@ -41,6 +47,8 @@
 #define SIOCGIFCOUNT 0x8935
 #endif
 
+#endif /* not Linux */
+
 char iface[16];
 
 
@@ -62,6 +70,7 @@
  */
 char *getdefaultdev()
 {
+#ifdef __linux__
 	FILE *fp = fopen( PROCROUTE, "r");
 	char buff[4096], gate_addr[128], net_addr[128];
 	char mask_addr[128];
@@ -85,19 +94,49 @@
 			return iface;
 	}
 	fclose(fp);
+
 /* didn't find a default gateway */
 	return NULL;
+#else
+	return "";
+#endif /* Linux */
 }
 
 
 void findFqdn( void )
 {
-	int sock, err, if_count, i, j = 0;
+	int if_count, i, j = 0;
+#if !(defined(__FreeBSD__) || defined(__NetBSD__))
+        int sock, err;
 	struct ifconf netconf;
 	char buffer[32*MAX_IF];
-	char if_name[10][21];
-	char if_addr[10][21];
+#endif
+	char if_name[MAX_IF][21];
+	char if_addr[MAX_IF][21];
 	char *default_ifName;
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+        struct ifaddrs *ifp, *oifp;
+        
+        if(getifaddrs(&ifp) < 0 )
+                printf( "Error with getifaddrs(): %i.\n", errno );
+        oifp=ifp; /* save ifp */
+        for (if_count = 0; ifp != NULL; ifp = ifp->ifa_next) {
+                if(ifp->ifa_addr->sa_family != AF_INET) continue;
+
+        if ( strncmp( ifp->ifa_name, "lo", 2 ) != 0 ) {
+                if(j == MAX_IF) printf( "Error: cannot handle more than %d interfaces.\n",MAX_IF);
+                else
+                {
+                        strncpy( if_name[j], ifp->ifa_name, 20);
+                        strncpy( if_addr[j], inet_ntoa(((struct sockaddr_in *)ifp->ifa_addr)->sin_addr ), 20);
+                        j++;
+                }
+                }
+        if_count++;
+        }
+        if (oifp != NULL) freeifaddrs(oifp);
+
+#else /* not FreeBSD or NetBSD */
 	netconf.ifc_len = 32 * MAX_IF;
 	netconf.ifc_buf = buffer;
 	sock=socket( PF_INET, SOCK_DGRAM, 0 );
@@ -105,9 +144,11 @@
 	if ( err < 0 ) printf( "Error in ioctl: %i.\n", errno );
 	close( sock );
 	if_count = netconf.ifc_len / 32;
+#endif
 	printf( "Found %i interfaces.\n", if_count );
 
 //#test
+#if !(defined(__FreeBSD__) || defined(__NetBSD__))
 	if ( if_count == 1 ) {
 		strncpy( if_name[j], netconf.ifc_req[0].ifr_name, 20 );
 		strncpy( if_addr[j], inet_ntoa(((struct sockaddr_in*)(&netconf.ifc_req[0].ifr_addr))->sin_addr), 20 );
@@ -122,6 +163,8 @@
 			}
 		}
 	}
+#endif /* not FreeBSD or NetBSD */
+
 	if( j == 1 ) {
 		dissipate_our_fqdn = strdup( if_addr[0] );
 	} else {