3

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.

Cannoliopsida
  • 3,044
  • 5
  • 36
  • 61

1 Answers1

6

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!

Jeff Winn
  • 804
  • 8
  • 14
  • 1
    +1 for DotRas. I went through the same thing as OP and when DotRas was first released I jumped on. Don't worry about it not being updated, it's complete and there aren't any changes to make unless Microsoft makes changes to the RAS framework. – scottm Jun 06 '12 at 19:19
  • 2
    Yeah I really only need to update the project whenever Microsoft releases a service pack to an existing operating system or when a new one is launched. So, the 1.3 release includes plans for Windows 8 once it goes to RTM later this year. I'm glad to see people are using it! – Jeff Winn Jun 06 '12 at 19:25