Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ip address after connect

Posted on 1998-10-03
4
Medium Priority
?
162 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

650 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