[Linux-HA] IPaddr and ifconfig
Matt Bell
mtbell at oss.buffalo.edu
Wed Mar 2 08:42:10 MST 2005
Hi,
I have a FC3 box running heartbeat. The box has a
number of vlan interfaces on different vlans which have interface names like
eth1.892, eth1.892:0. The problem i am having is that IPaddr uses ifconfig
to match up an ipaddress to an interface. However ifconfig only displays 9
characters so if the interface name is longer than 9 characters IPaddr
fails to get the entire interface name. The solution i've been using is to
use the following program (getint).
<getint.c>
#include <sys/types.h>
#include <netinet/in.h>
#include <ifaddrs.h>
#include <stdio.h>
int main (int argc, char **argv) {
struct ifaddrs *ifap, *ifa;
struct sockaddr_in *s;
ifap = (struct ifaddrs *)malloc(sizeof(struct ifaddrs));
if (argc != 2) {
printf("Usage: %s <ip address>\n", argv[0]);
exit (1);
}
if (getifaddrs(&ifap) != 0) {
perror("Unable to retrieve interfaces\n");
}
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family == AF_INET) {
s = (struct sockaddr_in *)ifa->ifa_addr;
if (strcmp((char *)(inet_ntoa(s->sin_addr)),
argv[1]) == 0) {
printf("%s\n", ifa->ifa_name);
break;
}
}
}
free(ifap);
exit (0);
}
in conjunction with the following modifications to IPaddr to get the
entire interface name
--- /tmp/IPaddr 2005-03-02 10:25:16.000000000 -0500
+++ IPaddr 2005-03-02 10:06:42.000000000 -0500
@@ -35,6 +35,7 @@
ROUTE=/sbin/route
SENDARP=$HA_BIN/send_arp
FINDIF=$HA_BIN/findif
+GETINT=$HA_BIN/getint
USAGE="usage: $0 ip-address {start|stop|status|monitor}";
SYSTYPE="`uname -s`"
case "$SYSTYPE" in
@@ -133,7 +134,8 @@
IF=`find_interface_solaris $BASEIP`
;;
*)
- IF=`find_interface_generic $BASEIP`
+# IF=`find_interface_generic $BASEIP`
+ IF=`$GETINT $BASEIP`
;;
esac
I was wondering if anyone has come across this problem before and have
dealt with it in a different way?
-Matt
More information about the Linux-HA
mailing list