Link to home
Start Free TrialLog in
Avatar of ivanh
ivanh

asked on

ip address after connect

I wrote a little connection program (like everyone else) and it works except for getting the ip address off of an NT box.  Windows 95/98 works fine.  
Below is what I'm using to the the ip.

gethostname(szLocalHostName, 254);
heHostInfo = gethostbyname(szLocalHostName);
NBOtoIP(heHostInfo->h_addr_list[0], szLocalIPAddress);

This works fine on 95, but NT returns me the value I used in my MSLoopback connector (100.100.100.1).  What do I use in order to get the correct ip from my Ras connection?
ASKER CERTIFIED SOLUTION
Avatar of arbitrary
arbitrary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gysbert1
gysbert1

Have a look at the value of :
  NBOtoIP(heHostInfo->h_addr_list[1], szLocalIPAddress);

h_addr_list is supposed to list all the addresses set up for the host entity. It might be that the first one is llopback and one of the others is the IP you need. The list is NULL terminated so if (h_addr_list[n]==NULL) it is the last entry ...
Avatar of ivanh

ASKER

Sorry for not responding sooner.  Shortly after I posted my question, my system crashed and I had to rebuild.  Anyway, I tried the RasGetEntryProperties and it looks like it should work, but I think my problem has to do with setting the bit flags.  I guess I don't understand how to set bit flags.  It says you can either set a specific one or clear it.  How do you clear a specific bit flag?

About the comment.  It worked and the information is there, but I guess I was hoping for more of a consistent way of determining and ip for a connection.  Is the last one in the array always the dialup ip?
I am not sure how the list is populated, I guess it traverses the hosts file and the queries the DNS (if it exists). Have a look at your hosts file. I bet loopback is the first entry (it usually is !).

About the bitflags.
If the constant BIT_3 = 4  {or 00000100 in binary }  you can clear it with:
  Flags &= ( ~BIT_3 );

 ~BIT_3 will be 11111011 and if you AND this with the FLAGS variable it will clear the third bit for you.