Getting IP address/interface number after a RasDial

2k views Asked by At

In C++ with .NET, I'm trying to get the IP address or interface name of a RASCONN that I just connected with RasDial (I have the HRASCONN pointer). I'm finding the MSDN API confusing and after hours searching I can't find the right calls (but it seems like they must exist).

In case there's a better way to do this, the goal here is to have some unique identifer so that when I later call NetworkInterface.GetAllNetworkInterfaces() in my managing C#, I can pick out the right connection.

1

There are 1 answers

2
Jeff Winn On BEST ANSWER

You'll need to look at the RasGetProjectionInfo function and use the HRASCONN pointer that you retrieved earlier. RASP_PppIp should be rasprojection value passed in to get the RASPPPIP struct which contains your IP address. I'd post some C++ code for you to use, but that's not my best language and don't want to embarass myself.

Here's some helpful links to assist you:

RasGetProjectionInfo: http://msdn.microsoft.com/en-us/library/aa377548(v=vs.85).aspx

RASPPPIP: http://msdn.microsoft.com/en-us/library/aa377634(v=vs.85).aspx

Since it appears part of your application is using C# you may want to consider using the DotRas project on CodePlex. It's a C# based wrapper around the entire RAS API. To get the PPP information from DotRas you would need to:

using DotRas;

var conn = RasConnection.GetActiveConnections().Where(c => c.EntryName == "Your Entry").FirstOrDefault();
RasPppIp ipInfo = conn.GetProjectionInfo(RasProjectionType.IP);

From here you can access the ipInfo.IPAddress property to get at the information you want.

Here's the link to DotRas: https://github.com/winnster/DotRas

Hope that helps!