Solved

ip address after connect

Posted on 1998-10-03
4
153 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now