From: Judson Lester Date: 2002-10-25T02:44:04+09:00 Subject: Trouble with UDPSocket --------------Boundary-00=_1KYHO7CUJXVQKHXATRBF Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit I've been fooling with a script to multiplex two snmp servers on one box. The idea is to have xinetd connect to the script, and the script pass the packets on to servers in order until one of them can respond. The script is attached. This is running on a Linux box with Ruby 1.6.7. This isn't working, even with the single existing server. Normally, if you do an snmpget for OID 0, the response is that there is no such OID. Ditto with 0.0. However, with the script in place, OID 0 gets no answer from the server, OID 0.0 hangs until OID 0 is sent, then I get an answer, but the script hangs in the decode (gleefully borrowed from the SNMP package from RAA). Honestly, I'm not sure if this is a problem with xinetd, my script (and so the province of this list), or something with the server itself. But, xinetd seems to be behaving properly (from the log review of done if it), and the server responds as expected without the script in place. Can anyone see any obvious errors I'm making? -- Judson --------------Boundary-00=_1KYHO7CUJXVQKHXATRBF Content-Type: text/x-c++src; charset="us-ascii"; name="snmp-unified.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="snmp-unified.rb" #!/usr/bin/ruby require 'socket' require 's2nmp' def main() snmp = SNMPForward::new #Add servers to forward to here snmp.addServer("localhost", 161) snmp.passAlong end class SNMPForward include Ber def initialize @snmpServers=Array::new end public def addServer (host, port) newServer=UDPSocket::new newServer.connect(host, port) @snmpServers << newServer end class SNMPSuccessException < Exception end def passAlong () log=File::new("/tmp/snmp-utest.log", "a") snmpServers=Array::new log<<"\nStarting SNMP-Unified\n" log<<"Opened SNMP on localhost\n" log.flush begin $stdin.each_line {|data| #data.chomp! log<<"Question: #{data} \n" log.flush response=nil begin @snmpServers.each {|server| server.send(data, 0) if not select([server], nil, nil, 3) log << "Server didn't answer.\n" log.flush return end response=server.recv(2000,0) log<< "Answer: #{response}. Checking error\n" log.flush tag,val,msg = tlv(reponse) log << "." log.flush tag,dummy,msg=tlv(val) log << "." log.flush tag,dummy,msg=tlv(msg) log << "." log.flush pdutype,pdu,msg=tlv(msg) log << "." log.flush tag,dummy,msg=tlv(pdu) log << "." log.flush tag,err,msg=tlv(msg) log << "." log.flush log << "Error code: #{dec_int(err)}" log.flush if not [2, 5].include? dec_int(err) raise SNMPSuccessException end } rescue SNMPSuccessException print response end } rescue => e log<<"\nEXCEPTION: #{e.message} \n" raise end log << "Exiting. Who knows why?\n"; log.flush end end main --------------Boundary-00=_1KYHO7CUJXVQKHXATRBF--