Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: IPv6 issue
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted July 21, 2011 8:09 AM

I'm trying to put IPv6 support in to my application, and am running in to trouble with the code that I have written. Everything works fine for IPv4, but I am getting a SocketException when attempting to do a Get() on a device with IPv6.

In general, my code looks like the following:

string deviceIPAddress = "fe80::d2c2:82ff:fe5b:d640";
// ...
IPAddress ipAddress = System.Net.IPAddress.Parse( deviceIPAddress );
// ...
LocalVariable req = new LocalVariable(); // I use this to put the RequestMessage, IPEndPoint and timeout information in a single object to be passed in to Manager.Start()
req.ipAddress = new System.Net.IPEndPoint( ipAddress, 161 );
// ...
ResponseMessage response = slave.GetResponse( req.msg, req.ipAddress );

I've cut some of the parts of the code out, just because it gets a little convoluted with the thread management that I have to do. It makes it to the call for slave.GetResponse just fine, but throws a SocketException when it gets there. SocketException.Message is "An address incompatible with the requested protocol was used".

Also a little odd - right above the GetResponse call, I have a trace statement. When I trace req.ipAddress, I get "[fe80::d2c2:82ff:fe5b:d640]:161". Where are the brackets coming from - I didn't put them there and until I created the IPEndPoint, they were there when it was an IPAddress object. Is this just because of the :161, so that it doesn't get confused with the rest of the IPAddress?

I know that the machine support IPv6 properly - I can ping the device that I'm trying to talk to. So, I don't think it's that.

What am I doing wrong?

Thanks,
Matt
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted July 21, 2011 9:19 AM

Hi Matt,
The slave's local endpoint is probably not IPv6.
What does your Start call look like? You can use Dart.Snmp.IPEndPoint to create the ManagerSlave on an IPv6 socket:

manager1.Start(mySlaveWorker, new Dart.Snmp.IPEndPoint(System.Net.Sockets.AddressFamily.InterNetworkV6), req);

Also, when the IPEndPoint is examined as a string, it is formatted with the brackets.

Hope it helps,
-ken
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted July 21, 2011 12:58 PM

Ken -

That seems to have worked. I was using the version of the Start() command that didn't specify the end point. Once I added that, everything seems happy.

Or, at least, mostly happy. I'm not getting the SocketException any more, but the packet doesn't seem to be getting to the other side. I see it in WireShark leaving the PC, but the Cisco switch that I'm talking to isn't getting the packet or returning it. Once I figure that out, I'll know more about what is or isn't working on my side.

Thanks again,
Matt
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted July 22, 2011 3:50 PM

Ken -

Things seem to be working on the query end. Is there a similar change that I need to make in order to receive IPv6 traps/notifications/informs/etc? When I start the Manager object, I'm using this call:
snmpMgr.Start( new ManagerMessageReceived( OnManagerMessageReceived ), null );

If I make a change, will I be able to receive both IPv4 and IPv6 messages? What will I need to do that?

Thanks,
Matt
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted July 25, 2011 9:10 AM

Hi,
There is similarly a ManagerMessageReceived delegate that takes an IPEndPoint (where you can specify the AddressFamily).

In order to receive messages on both addresses, you will need to start two Managers.

Hope it helps,
-ken
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted July 25, 2011 4:14 PM

Ken -

Do I need to call Start twice on the same object, like this:
snmpMgr.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetwork ), false, null );
snmpMgr.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetworkV6 ), false, null );

or Start once on each of two objects:
snmpMgrV4.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetwork ), false, null );
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetworkV6 ), false, null );

In the second case, will I need to then make changes so that my outgoing requests use the proper Manager, or will it still find its way using a single object for outgoing?

Thanks - Matt
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted July 26, 2011 3:51 PM

Hi,
You should use two Manager components.

For outgoing requests, you will want to use a ManagerSlave that is opened on a socket of the appropriate AddressFamily (these slaves are provided as a parameter in the function passed to the Start call).

Hope it helps,
-ken
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted July 27, 2011 10:43 AM

Ken -

Looks like I'm still missing something. I've created a second Manager object, and gotten it working with reading data from Agents (both V4 and V6). However, the traps still aren't working. Currently, my initialization code looks like this:

snmpMgrV4.Message += OnMessageReceived;
snmpMgrV4.Error += OnSNMPException;
snmpMgrV4.Log += OnManagerLog;
snmpMgrV4.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetwork ), false, null );

snmpMgrV6.Message += OnMessageReceived;
snmpMgrV6.Error += OnSNMPException;
snmpMgrV6.Log += OnManagerLog;
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.Sockets.AddressFamily.InterNetworkV6 ), false, null );

I thought for a while that it was Windows Firewall getting in the way, but I shut it off, and still don't get the trap. Neither V4 nor V6 are working. I've tried it with "true" for the acceptBroadcast variable, and that didn't work. I've tried rolling the code back to before I put the IPEndPoint parameter in place - still nothing. I don't know if it makes a difference, but I'm running Windows7 x64. Originally, I wrote this on XP and I know that it worked then. I don't know that I've tried it since I got the Windows7 box. But, I don't know what would be different. The packet is showing up in WireShark, so I know that the Agents are configured properly.

Any other ideas?

Thanks again!
Matt
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted July 27, 2011 12:33 PM

Hi Matt,
Sorry, I believe you have to specify the port to listen on (162) when you create the IPEndPoint.

For example, something similar to this should work:

private void button1_Click(object sender, EventArgs e)
{
  manager1.AuthoritativeEngine.Id = System.Text.Encoding.Default.GetBytes("DartManager");
  manager1.Start(new Dart.Snmp.ManagerMessageReceived(trapCatcher),
    new IPEndPoint("192.168.0.166", System.Net.Sockets.AddressFamily.InterNetwork, 162), true, null);
}

private void trapCatcher(Manager manager, MessageBase message, object state)
{
  MessageBox.Show(message.Origin.ToString());
}

Hope it helps,
-ken
mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted August 2, 2011 4:13 PM

Ken -

Sorry that I'm so long getting back to you - I've been out of the office for a few days.

I tried to add 162 to the IPEndPoint constructor, and ended up with these statements:
snmpMgrV4.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( "", System.Net.Sockets.AddressFamily.InterNetwork, 162 ), true, null );
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( "", System.Net.Sockets.AddressFamily.InterNetworkV6, 162 ), true, null );

These changes seem to have gotten IPv4 traps working, but I am still not receiving the IPv6 traps. I am still seeing the traps in WireShark, so they are still configured properly, but my Manager does not get the message.

I tried to set the first parameter of the IPEndPoint constructor to my machine's IPv6 address, and it received the trap properly. Am I not able to use the localhost version of this constructor with IPv6? Is it working, but listening on some other IPv6 IP address that I have defined for my network connection (such as the Link Local)? Is there any way to tell what IP the Manager is listening on? If I want to listen to all SNMP traffic for the machine, do I need to create Manager objects for each IP address?

Thanks again for all of your help with this!
Matt
Jason Farrar (Admin)

From: Oneida, NY USA
Posts: 223
Member Since: 07/24/07

Extra Support Options
Custom Application Development

posted August 3, 2011 4:24 PM

The constructor you are using for IPEndpoint grabs the first address of the specified family and returns it, it doesn't listen on all interfaces.

It's possible that it is listening but not on the IP that you want it to listen on, to check that you can check the Address property of the IPEndpoint object, so you should create the object first to check it before passing it into the Start method. Ex:
Dart.Snmp.IPEndPoint MyIPEndPoint = new Dart.Snmp.IPEndPoint( "", System.Net.Sockets.AddressFamily.InterNetworkV6, 162 )
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), MyIPEndPoint, true, null );

If you want to listen on all interfaces the following code should do it:
snmpMgrV4.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.IPAddress.Any, 162 ), true, null );
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.IPv6Any, 162 ), true, null );

mljames

From: Indianapolis, IN USA
Posts: 9
Member Since: 02/21/03
posted August 4, 2011 7:49 AM

Jason / Ken -

Thanks for all of your help. That looks like everything that I need for now.

Did want to correct one typo in the last post for anyone trying to do this after me. The second line should read:
snmpMgrV6.Start( new ManagerMessageReceived( OnManagerMessageReceived ), new Dart.Snmp.IPEndPoint( System.Net.IPAddress.IPv6Any, 162 ), true, null );

Thanks again!
Matt
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX