?
Solved

ip address after connect

Posted on 1998-10-03
4
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
arbitrary earned 300 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

762 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