[olsr-dev] Windows interface naming

(spam-protected) (spam-protected)
Fri Sep 22 16:46:21 CEST 2006


Hi guys,
I'm new in this mailing list.
I downloaded olsrd software in order to use it under Windows Xp.
I think it's a good software in all its parts (core, gui, plugin).

I read the note "INTERFACE NAMING" in the readme file and I have just a question: why don't you use the friendly name displayed in the Network Connections Window?
The index adapter, used to build the interface name, is not persistent (it changes when you disable/enable an adapter).
Moreover if you use a config file to run olsrd you must change the interface name specified in that file.

I have developed the following patches for ifnet.c (win32) and Makefile.win32 to enable the use of the friedly name.
Please, give me some feedbacks if you think these modifications are good.
Bye
Sektor

--- Makefile.win32      2005-12-29 21:26:32.000000000 +0100
+++ Makefile.win32.new  2006-09-22 16:31:10.531080400 +0200
@@ -8,7 +8,7 @@
 SRCS +=                $(wildcard src/win32/*.c)
 HDRS +=                $(wildcard src/win32/*.h)

-DEFINES +=     -DWIN32
+DEFINES +=     -DWIN32 -D_WIN32_WINNT=0x0501
 LIBS +=                -mno-cygwin -lws2_32 -liphlpapi
 INCLUDES +=    -I$(TOPDIR)/src/win32
 CFLAGS +=      -mno-cygwin

--- ifnet.c	2005-10-23 21:01:04.000000000 +0200
+++ ifnet.c.new	2006-09-22 16:36:22.784856000 +0200
@@ -141,6 +141,8 @@
   unsigned long Res;
   int TabIdx;
   IP_ADAPTER_INFO AdInfo[MAX_INTERFACES], *Walker;
+  IP_ADAPTER_ADDRESSES AdAddr[MAX_INTERFACES], *WalkerAddr;
+  char FriendlyName[MAX_INTERFACE_NAME_LEN];
 
   if (olsr_cnf->ip_version == AF_INET6)
   {
@@ -148,10 +150,39 @@
     return -1;
   }
 
-  if (IntNameToMiniIndex(&MiniIndex, Name) < 0)
+  if ((Name[0] != 'i' && Name[0] != 'I') ||
+      (Name[1] != 'f' && Name[1] != 'F'))
   {
-    fprintf(stderr, "No such interface: %s!\n", Name);
-    return -1;
+	BuffLen = sizeof (AdAddr);
+	
+	Res = GetAdaptersAddresses(AF_INET, 0, NULL, AdAddr, &BuffLen);
+	
+	if (Res != NO_ERROR)
+	{
+	    fprintf(stderr, "GetAdaptersAddresses() = %08lx", GetLastError());
+	    return -1;
+	}
+	for (WalkerAddr = AdAddr; WalkerAddr != NULL; WalkerAddr = WalkerAddr->Next)
+	{
+	    OLSR_PRINTF(5, "Index = %08x - ", (int)WalkerAddr->IfIndex);
+	    wcstombs(FriendlyName, WalkerAddr->FriendlyName, MAX_INTERFACE_NAME_LEN); 
+	    OLSR_PRINTF(5, "Friendly name = %s\n", FriendlyName);
+	    if (strncmp(FriendlyName, Name, MAX_INTERFACE_NAME_LEN) == 0)
+	    	break;
+	}
+	if (WalkerAddr == NULL)
+	{
+		fprintf(stderr, "No such interface: %s!\n", Name);
+		return -1;
+	}
+	MiniIndex = WalkerAddr->IfIndex;
+  } else
+  {
+	  if (IntNameToMiniIndex(&MiniIndex, Name) < 0)
+	  {
+	    fprintf(stderr, "No such interface: %s!\n", Name);
+	    return -1;
+	  }
   }
 
   IfTable = (MIB_IFTABLE *)Buff;






More information about the Olsr-dev mailing list