Răsfoiți Sursa

First run at adding support for corosync totemip determination.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2213 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 16 ani în urmă
părinte
comite
1e0e9a5633
1 a modificat fișierele cu 78 adăugiri și 4 ștergeri
  1. 78 4
      exec/totemip.c

+ 78 - 4
exec/totemip.c

@@ -43,6 +43,10 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#if defined(COROSYNC_SOLARIS)
+#include <net/if.h>
+#include <sys/sockio.h>
+#endif
 #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
 #include <sys/sockio.h>
 #include <net/if.h>
@@ -310,12 +314,82 @@ int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
 	return ret;
 }
 
+#if defined(COROSYNC_SOLARIS)
+int totemip_iface_check(struct totem_ip_address *bindnet,
+	struct totem_ip_address *boundto,
+	int *interface_up,
+	int *interface_num,
+	int mask_high_bit)
+{
+	struct sockaddr_storage bindnet_ss;
+	struct sockaddr_storage boundto_ss;
+	struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss;
+	struct sockaddr_in *boundto_sin = (struct sockaddr_in *)&boundto_ss;
+        struct sockaddr_in *sockaddr_in;
+        int id_fd;
+        struct ifconf ifc;
+        int numreqs = 0;
+        int i;
+        in_addr_t mask_addr;
+	int res = -1;
+	int addrlen;
+
+	totemip_totemip_to_sockaddr_convert(bindnet,
+		0, &bindnet_ss, &addrlen);
+
+	*interface_up = 0;
+	/*
+	* Generate list of local interfaces in ifc.ifc_req structure
+	*/
+	id_fd = socket (AF_INET, SOCK_STREAM, 0);
+	ifc.ifc_buf = 0;
+	do {
+		numreqs += 32;
+		ifc.ifc_len = sizeof (struct ifreq) * numreqs;
+		ifc.ifc_buf = (void *)realloc(ifc.ifc_buf, ifc.ifc_len);
+		res = ioctl (id_fd, SIOCGIFCONF, &ifc);
+		if (res < 0) {
+			close (id_fd);
+			return -1;
+		}
+	} while (ifc.ifc_len == sizeof (struct ifreq) * numreqs);
+	res = -1;
+
+	/*
+	* Find interface address to bind to
+	*/
+	for (i = 0; i < ifc.ifc_len / sizeof (struct ifreq); i++) {
+		sockaddr_in = (struct sockaddr_in *)&ifc.ifc_ifcu.ifcu_req[i].ifr_ifru.ifru_addr;
+		mask_addr = inet_addr ("255.255.255.0");
+
+		if ((sockaddr_in->sin_family == AF_INET) &&
+			(sockaddr_in->sin_addr.s_addr & mask_addr) ==
+			(bindnet_sin->sin_addr.s_addr & mask_addr)) {
+
+			boundto_sin->sin_addr.s_addr = sockaddr_in->sin_addr.s_addr;
+			res = i;
+
+			if (ioctl(id_fd, SIOCGIFFLAGS, &ifc.ifc_ifcu.ifcu_req[i]) < 0) {
+				printf ("couldn't do ioctl\n");
+			}
+
+			*interface_up = ifc.ifc_ifcu.ifcu_req[i].ifr_ifru.ifru_flags & IFF_UP;
+			break; /* for */
+		}
+	}
+	free (ifc.ifc_buf);
+	close (id_fd);
+
+	return (res);
+}
+#endif
+
 #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
 int totemip_iface_check(struct totem_ip_address *bindnet,
-			struct totem_ip_address *boundto,
-			int *interface_up,
-			int *interface_num,
-			int mask_high_bit)
+	struct totem_ip_address *boundto,
+	int *interface_up,
+	int *interface_num,
+	int mask_high_bit)
 {
 #define NEXT_IFR(a)	((struct ifreq *)((u_char *)&(a)->ifr_addr +\
 	((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr))))