Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: Messages should be able to build from Stream.
Pedro D. Lima Jesus

From: Bolivia, Bolivia
Posts: 5
Member Since: 06/24/10
posted June 24, 2010 4:33 PM

I think that the messages should be able to build from Stream, the goal is create a sniff of the request messages, I'm waiting the request in the xxx.xxx.xxx:161, in this i have caught a Stream but now i need to rebuild the reques message, and with this information build the responce message.

someone can help me?

Kind regards,
Pedro D. Lima Jesus
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted June 24, 2010 5:26 PM

Hi Pedro,
I am not sure I understand your question exactly, but the following should help:

1. To create the response, it is best to pass the RequestMessage object to the Agent.CreateDefaultMessage method, as demonstrated in the Agent sample application.

2. To get the actual encoded request PDU, examine the RequestMessage.EncodedMessage property.

Hope it helps,
-ken
Pedro D. Lima Jesus

From: Bolivia, Bolivia
Posts: 5
Member Since: 06/24/10
posted June 24, 2010 10:22 PM

well, I have the message in the Stream variable,

m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
m_Socket.Bind(m_LocalEndPoint);
m_Socket.BeginReceiveFrom(m_Buffer, 0, m_Buffer.Length, SocketFlags.None, ref m_EndPoint, new AsyncCallback(OnReceiveFrom), null);
......
......
MemoryStream message = new MemoryStream(m_Buffer, 0, count);

this message should be able to rebuild the RequestMessage.

maybe the RequestMessage should have a overload where it recive the Stream variable.

e.g. RequestMessage request = new RequestMessage(stream);

some thing like that.
Pedro D. Lima Jesus

From: Bolivia, Bolivia
Posts: 5
Member Since: 06/24/10
posted June 25, 2010 11:12 AM

Hi,

well, I'm implementing a Network Sniffer to heard the message in the xxx.xxx.xxx:161 adress, now after that, I need to know which was the RequestMessage, this Network Sniffer is part of my devices simulator.

in this case I have as input data the MemoryStream mesage, this mesage must parse and rebuild the RequestMessage.

RequestMessage request = new RequestMessage(stream);

some thing like that.

Kind regards,
Pedro D. Lima Jesus
Mike Baldwin (Admin)



From: Rome, NY USA
Posts: 114
Member Since: 04/11/00

Extra Support Options
Custom Application Development

posted June 27, 2010 4:08 PM

Pedro,

Actually, the following syntax should work for you:

MessageBase request = MessageBase.Create(m_Buffer, 0, cnt);

Then check the request to see if it's a GetMessage, SetMessage, etc.

Hope this helps.
Pedro D. Lima Jesus

From: Bolivia, Bolivia
Posts: 5
Member Since: 06/24/10
posted June 28, 2010 10:44 AM

Hi Mike,

yeah, I need that.

MessageBase request = MessageBase.Create(m_Buffer, 0, cnt);

but we have bought the version 4.2.12. in this version does not have the overload of the method MessageBase.Create(m_Buffer, 0, cnt);

I can know, which is the correct version with this funtionality?

Kind regards,
Pedro D. Lima Jesus


K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted June 28, 2010 11:08 AM

Hi,
There is no such overload, but you can create a Segment object from the buffer, count and offset, and pass this as the first parameter.

Sorry for the confusion,
-ken
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted June 28, 2010 11:28 AM

Hi,
One more thing - the last parameter cannot be null (despite what the docs say), but you can simply pass in a new instance of MibNodes to the function.
Null will be allowed in the next release.

-ken
Pedro D. Lima Jesus

From: Bolivia, Bolivia
Posts: 5
Member Since: 06/24/10
posted June 28, 2010 11:42 AM

Hi Ken,

yeah, i undestand that, but the methos "Create" of the object MessageBase does not recive the buffer, offset and count.

m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
m_Socket.Bind(m_LocalEndPoint);
m_Socket.BeginReceiveFrom(m_Buffer, 0, m_Buffer.Length, SocketFlags.None, ref m_EndPoint, new AsyncCallback(OnReceiveFrom), null);
.
.
.
EndPoint remote = new IPEndPoint(0, 0);
int count = m_Socket.EndReceiveFrom(ar, ref remote);
if (count > 0)
{
  //////////////////////////////////////
  //the create method does not have the overload to recive the parameters( buffer, offset, count)
MessageBase message = MessageBase.Create(m_Buffer, 0, count);


HandleMessage(message, (IPEndPoint)remote);
remote = new IPEndPoint(0, 0);
m_Socket.BeginReceiveFrom(m_Buffer, 0, m_Buffer.Length, SocketFlags.None, ref remote, new AsyncCallback(OnReceiveFrom), null);
}

this have sense?

Kind regards,
Pedro D. Lima Jesus
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted June 28, 2010 3:19 PM

Hi Pedro,
I thought I answered this...

MessageBase.Create(new Dart.Common.Segment(buffer, offset, count), etc...

Or maybe I still do not understand your concern?

Are you expecting other data on this port? I still do not understand why you cannot let the component take care of the socket binding and receiving (and therefore the message construction) for you.

-ken
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX