Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone have an example of how to use SnmpSendMsg? All i need to do is create a simple Pdu and send it, but I have no idea how to add my message into the Pdu and so, SnmpSendMsg does nothing.
I have searched google and msdn to no avail, i can get all the documentation from MSDN, but there are no bloody examples.
Any help is appreciated.
PS. I AM USING C#
ah and here is my code so far:
SnmpCB = new SnmpAPI.SnmpCallback(OnSnmpMessage);string LocalAddr = System.Net.Dns.GetHostName();
string RemoteAddr = System.Net.Dns.GetHostByName("Alarm").AddressList[0].ToString();
int major, minor, level, translate, retran;
SNMPAPI_STATUS rc = SnmpAPI.SnmpStartup(out major, out minor, out level, out translate, out retran);
if (rc != SNMPAPI_STATUS.SNMPAPI_SUCCESS)
throw new Exception("SNMP Initialization Error");
IntPtr hSnmp = SnmpAPI.SnmpCreateSession(IntPtr.Zero, 0, SnmpCB, IntPtr.Zero);IntPtr Src = SnmpAPI.SnmpStrToEntity(hSnmp,LocalAddr);
IntPtr Dest = SnmpAPI.SnmpStrToEntity(hSnmp,RemoteAddr);WinSnmp.SMIOCTETS Octets = new SMIOCTETS();
WinSnmp.SMIVALUE Value = new SMIVALUE();
IntPtr Context = SnmpAPI.SnmpStrToContext(hSnmp,ref Octets);WinSnmp.SMIOID Name = new SMIOID();
IntPtr VbList = SnmpAPI.SnmpCreateVbl(hSnmp,ref Name,ref Value);IntPtr Pdu = SnmpAPI.SnmpCreatePdu(hSnmp,WinSnmp.SNMPAPI_PDU.SNMP_PDU_SET,null,null,null,VbList);
SnmpAPI.SnmpSendMsg(hSnmp,Src,Dest,Context,Pdu);
SnmpAPI.SnmpFreePdu(Pdu);
TIA,
ChiThey mostly come at night...mostly

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |