[Olsr-cvs] olsrd-current/src/win32 ifnet.c,1.30,1.31
Thomas Lopatic
(spam-protected)
Wed Oct 11 22:18:38 CEST 2006
Update of /cvsroot/olsrd/olsrd-current/src/win32
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13397/src/win32
Modified Files:
ifnet.c
Log Message:
Applied friendly name patch by Sektor.
Index: ifnet.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/win32/ifnet.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** ifnet.c 7 Jan 2006 08:16:26 -0000 1.30
--- ifnet.c 11 Oct 2006 20:18:36 -0000 1.31
***************
*** 133,136 ****
--- 133,197 ----
}
+ static int FriendlyNameToMiniIndex(int *MiniIndex, char *String)
+ {
+ typedef DWORD (*GETADAPTERSADDRESSES)(ULONG Family,
+ DWORD Flags,
+ PVOID Reserved,
+ PIP_ADAPTER_ADDRESSES pAdapterAddresses,
+ PULONG pOutBufLen);
+ unsigned long BuffLen;
+ unsigned long Res;
+ IP_ADAPTER_ADDRESSES AdAddr[MAX_INTERFACES], *WalkerAddr;
+ char FriendlyName[MAX_INTERFACE_NAME_LEN];
+ HMODULE h;
+ GETADAPTERSADDRESSES pfGetAdaptersAddresses;
+
+ h = LoadLibrary("iphlpapi.dll");
+
+ if (h == NULL)
+ {
+ fprintf(stderr, "LoadLibrary() = %08lx", GetLastError());
+ return -1;
+ }
+
+ pfGetAdaptersAddresses = (GETADAPTERSADDRESSES) GetProcAddress(h, "GetAdaptersAddresses");
+
+ if (pfGetAdaptersAddresses == NULL)
+ {
+ fprintf(stderr, "Unable to use adapter friendly name (GetProcAddress() = %08lx)\n", GetLastError());
+ return -1;
+ }
+
+ BuffLen = sizeof (AdAddr);
+
+ Res = pfGetAdaptersAddresses(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, String, MAX_INTERFACE_NAME_LEN) == 0)
+ break;
+ }
+
+ if (WalkerAddr == NULL)
+ {
+ fprintf(stderr, "No such interface: %s!\n", String);
+ return -1;
+ }
+
+ *MiniIndex = WalkerAddr->IfIndex & 255;
+ }
+
int GetIntInfo(struct InterfaceInfo *Info, char *Name)
{
***************
*** 149,156 ****
}
! if (IntNameToMiniIndex(&MiniIndex, Name) < 0)
{
! fprintf(stderr, "No such interface: %s!\n", Name);
! return -1;
}
--- 210,230 ----
}
! if ((Name[0] != 'i' && Name[0] != 'I') ||
! (Name[1] != 'f' && Name[1] != 'F'))
{
! if (FriendlyNameToMiniIndex(&MiniIndex, Name) < 0)
! {
! fprintf(stderr, "No such interface: %s!\n", Name);
! return -1;
! }
! }
!
! else
! {
! if (IntNameToMiniIndex(&MiniIndex, Name) < 0)
! {
! fprintf(stderr, "No such interface: %s!\n", Name);
! return -1;
! }
}
More information about the Olsr-cvs
mailing list