I'm happy to report that thanks to APR, I can now successfully cross-compile
my server under Win32 and Unix, and run it on both!  I can't thank you all
enough for your wonderful library!

So now that I'm running, however, I'm encountering some issues.  The first
is as follows: how do I enumerate the IP addresses of the server?  My basic
algorithm is as follows:

# // Get the machine's DNS name and look up its IP address(es)
# char hostName[APRMAXHOSTLEN + 1];
# apr_gethostname( hostName, sizeof(hostName), pool );
# apr_sockaddr_info_get( &sockAddr, hostName, APR_INET, 0, 0, pool );
# do
# {
#       // Walk across the linked-list of addresses and output
#       char* ip = 0;
#       apr_sockaddr_ip_get( &ip, sockAddr );
#       cout << "Found IP: " << ip << "\n";
# }
# while( sockAddr = sockAddr->next );

On Win32 this finds all network adapters, but under Unix (Fedora Core 2)
this only finds the loopback address (127.0.0.1).

Any suggestions on how else to algorithmically identify the local machine's
IP addresses?  This technique kinda works on Win32, but feels kinda flaky
(and is flaky on Unix).  Is there any better approach to finding local IP
addresses?

And for reference, here's my /sbin/ifconfig output:

eth0      Link encap:Ethernet  HWaddr 00:0C:29:9D:33:59  
          inet addr:192.168.163.129  Bcast:192.168.163.255
Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe9d:3359/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3071 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2333 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3075757 (2.9 Mb)  TX bytes:154256 (150.6 Kb)
          Interrupt:10 Base address:0x1080 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2904 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2904 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2889754 (2.7 Mb)  TX bytes:2889754 (2.7 Mb)

-david

PS: I gave up on the UTF-8/16 conversion using APR and just wrote my own
converter.  If anyone is interested in the code, I'm happy to share.

Reply via email to