2014-07-05 2 views
0

https://github.com/lextm/sharpsnmplib/blob/master/SharpSnmpLib/IP.csSharpSnmpLib | 바이트에는 4 또는 16 개의 요소가 포함되어야합니다. -이 오류의 원인은 무엇입니까?

System.ArgumentException: bytes must contain 4 or 16 elements 
at Lextm.SharpSnmpLib.IP..ctor(Tuple`2 length, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) 
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) 
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) 
at Lextm.SharpSnmpLib.ResponsePdu..ctor(Tuple`2 length, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) 
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream) 
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) 
at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessage(Int32 first, Stream stream,   UserRegistry registry) 
at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessages(Byte[] buffer, Int32 index, Int32 length, UserRegistry registry) 
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket) 
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, Socket udpSocket) 
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver) 
at Lextm.SharpSnmpLib.Messaging.Messenger.BulkHasNext(VersionCode version, IPEndPoint endpoint, OctetString community, Variable seed, Int32 timeout, Int32 maxRepetitions, IList`1& next, IPrivacyProvider privacy, ISnmpMessage& report) 
at Lextm.SharpSnmpLib.Messaging.Messenger.BulkWalk(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList`1 list, Int32 timeout, Int32 maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report) 
at Maprinter.snmpWalk..ctor(String IP, String ID, Int32 timeOut) 

내가 네트워크 프린터에서 일부 데이터를 끌어 오기 위해이 라이브러리를 사용하고 있습니다. 지금까지 모든 것이 잘 작동하고 대부분의 프린터가 내가 원하는 데이터를 반환합니다. 하지만이 오류가 발생하면 프린터에서 아무 것도받지 못하므로이 오류의 원인은 무엇입니까?

Messenger.BulkWalk(VersionCode.V2, 
            new IPEndPoint(IPAddress.Parse("10.0.0.101"), 161), 
            new OctetString("public"), 
            new ObjectIdentifier("1.3.6.1"), 
            result, 
            timeOut, 
            10, 
            WalkMode.Default, 
            null, 
            null); 
+0

예외의 원인이되는 코드를 알려주십시오. 더 구체적으로 IP 클래스 생성자에 전달하는 매개 변수를 보여줍니다. –

+0

프린터에서 직접 IP를 얻었습니다. 코드를 표시하도록 질문을 업데이트했습니다. @YuvalItzchakov –

+0

예외를 일으키는 라인은 무엇입니까? –

답변

1

예외가 빈 것으로 IpAddress 본체를 전송하는 장치의 SNMP 에이전트에 의해 발생 된 (0 × 40, 0 × 00). 결과는 Null 본문 (0x05, 0x00)이어야하므로 표준을 위반합니다.

IpAddress은 정확히 4 바이트 인 RFC2578에 정의됩니다. 이것이 #SNMP가 4를 검사하는 이유입니다. 16에 대한 검사는 IPv6 주소에 대한 것이지만 실제로는 사용자 지정 규칙에 의해 지원되어야합니다. 올바른 몸이 전송되도록

귀하의 경우, 옵션이 될 수

,

  • 펌웨어를 수정합니다.
  • #SNMP 코드베이스 (MIT/X11 라이센스)를 수정하고 필요에 맞게 수정하십시오.
+0

나는 SNMP를 지원하는 모든 프린터에서 작업 할 수 있기를 원합니다. 펌웨어가 다른 프린터의 문제를 해결하지 않을 것이라고 수정합니다. 나는 당신이해야 할 일을 이해하고 당신이이 도서관의 개발자임을 압니다. 할 일이 무엇인지 제안 해 주실 수 있습니까? 라이브러리에서 무엇을 수정해야하며 어떤 파일을 가져야합니까? @Lex Li –

+0

귀하의 대답을 이해하기 때문에 소프트웨어에서 (0x40, 0x00) 및 (0x05, 0x00) 모두를 프린터에서 수신하도록 허용해야합니다. 그래서이 파일을 발견했습니다 : https : // github.co.kr/lextm/sharpsnmplib/blob/master/SharpSnmpLib/SnmpType.cs # L59 Null을 0x05로 정의합니다. null을 0x05와 0x40 둘 다 어떻게 정의 할 수 있습니까? @Lex Li –

+0

나는 입력 한 모든 단어를주의 깊게 읽을 시간이 있었으면 좋겠다. 분명히 나는 ​​0x40이'IpAddress'에 대한 것을 보여줬다. 0x40, 0x00을 예외없이 수신하려면 예외를 throw하는 행을 주석으로 처리하면됩니다. 이해가되지 않는다면 더 많은 C#을 배워야 할 것입니다. 모든 핵심 사항이 다루어 지므로 더 이상 제안 할 수는 없습니다. 상업 컨설팅 서비스가 필요한 경우 알려주십시오. –