Changeset 21563 for trunk/src/iphlpapi/iphlpapi.cpp
- Timestamp:
- Jan 18, 2011, 1:00:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/iphlpapi/iphlpapi.cpp
r21480 r21563 27 27 28 28 #include <types.h> 29 #include <sys \socket.h>30 #include <sys \ioctl.h>31 #include <net \route.h>32 #include <net \if.h>33 #include <net \if_arp.h>29 #include <sys/socket.h> 30 #include <sys/ioctl.h> 31 #include <net/route.h> 32 #include <net/if.h> 33 #include <net/if_arp.h> 34 34 #ifdef TCPV40HDRS 35 #include <netinet \in.h>36 #include <arpa \NAMESER.H>35 #include <netinet/in.h> 36 #include <arpa/NAMESER.H> 37 37 #endif 38 38 #include <resolv.h> … … 50 50 typedef struct 51 51 { 52 53 54 55 52 unsigned long IPAddress; 53 unsigned short interfaceIndex; 54 unsigned long netmask; 55 unsigned long broadcastAddress; 56 56 } 57 57 AddrInfo; … … 79 79 { 80 80 sprintf(dst, "%u.%u.%u.%u", 81 82 83 84 81 (char)data, 82 (char)(*(((char*)&data) + 1)), 83 (char)(*(((char*)&data) + 2)), 84 (char)(*(((char*)&data) + 3))); 85 85 } 86 86 … … 207 207 208 208 // Allocate the adapter info entry 209 pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof 209 pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof(IP_ADAPTER_INFO)); 210 210 memset(pipAdapter, 0, sizeof(IP_ADAPTER_INFO)); 211 211 if (oldAdapter) … … 276 276 for (int j = 0; j < cAddresses; ++j) 277 277 { 278 #ifdef DEBUG 279 if (i == 0) // print only once 280 { 281 dprintf(("IPHLPAPI: ADDR %d:", j)); 282 dprintf(("IPHLPAPI: IPAddress 0x%08X", addrInfo[j].IPAddress)); 283 dprintf(("IPHLPAPI: interfaceIndex %d", addrInfo[j].interfaceIndex)); 284 dprintf(("IPHLPAPI: netmask 0x%08X", addrInfo[j].netmask)); 285 dprintf(("IPHLPAPI: broadcastAddress 0x%08X", addrInfo[j].broadcastAddress)); 286 } 287 #endif 278 288 if (addrInfo[j].interfaceIndex == ifIndex) 279 289 { … … 305 315 for (j = 0; j < rtentries->hostcount + rtentries->netcount; ++j) 306 316 { 317 #ifdef DEBUG 318 if (i == 0) // print only once 319 { 320 dprintf(("IPHLPAPI: RTENTRY %d:", j)); 321 dprintf(("IPHLPAPI: rt_hash 0x%08X", rtentry->rt_hash)); 322 dprintf(("IPHLPAPI: rt_dst 0x%08X", ((struct sockaddr_in *)(&rtentry->rt_dst))->sin_addr.s_addr)); 323 dprintf(("IPHLPAPI: rt_gateway 0x%08X", ((struct sockaddr_in *)(&rtentry->rt_gateway))->sin_addr.s_addr)); 324 dprintf(("IPHLPAPI: rt_flags 0x%08X", rtentry->rt_flags)); 325 dprintf(("IPHLPAPI: rt_refcnt %d", rtentry->rt_refcnt)); 326 dprintf(("IPHLPAPI: rt_use %d", rtentry->rt_use)); 327 dprintf(("IPHLPAPI: rt_ifp 0x%p", rtentry->rt_ifp)); 328 //dprintf(("IPHLPAPI: if_name %s", rtentry->rt_ifp->if_name)); 329 dprintf(("IPHLPAPI: metric1 %d", rtentry->metric1)); 330 dprintf(("IPHLPAPI: metric2 %d", rtentry->metric2)); 331 dprintf(("IPHLPAPI: metric3 %d", rtentry->metric3)); 332 dprintf(("IPHLPAPI: metric4 %d", rtentry->metric4)); 333 } 334 #endif 307 335 // only take default gateways for this interface 336 #if 1 337 // rtentry->rt_ifp is (always?) a high address (0xFxxxxxxx) and for 338 // some reason reading it causes an access violation on some systems 339 // while works great on other systems. I don't know why. Luckily 340 // (luckily???), the definition of struct rtentries in headers is 341 // wrong -- each entry in the rtentries::rttable array is 342 // additionally followed by an ASCIIZ string containing the 343 // interface name. And the interface name is what we need. Owse. 344 char *if_name = (char *)(rtentry + 1); 345 dprintf(("IPHLPAPI: if_name %s", if_name)); 346 347 if (strcmp(if_name, iShortName) == 0 && 348 #else 308 349 if (strcmp(rtentry->rt_ifp->if_name, iShortName) == 0 && 350 #endif 309 351 ((struct sockaddr_in *)(&rtentry->rt_dst))->sin_addr.s_addr == 0) 310 352 { … … 331 373 } 332 374 333 // For some strange reason, the definition of struct rtentries 334 // is wrong. Each entry in the rtentries::rttable array is followed 335 // by the interface name. Compensate for that. 375 // Compensate for the interface name following the rtentry 336 376 ++rtentry; 337 377 rtentry = (struct rtentry *)
Note:
See TracChangeset
for help on using the changeset viewer.