Solved

ip address after connect

Posted on 1998-10-03
4
158 Views
Last Modified: 2010-04-01
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?
0
Comment
Question by:ivanh
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
arbitrary earned 150 total points
ID: 1174318
if your connection to the internet is based on RAS then what you can do is call RasGetEntryProperties for the current entry and then you can get the IP from the LPRASENTRY parameter ,
which will contain the RASIPADDR  ipaddr; which is your ras given IP address .


0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1174319
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 ...
0
 
LVL 1

Author Comment

by:ivanh
ID: 1174320
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?
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1174321
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question