Dear Perl Monks, I am using Perl for a trap reciever/monitor in SNMP but the code only runs once and then gives an error: Creating Socket Unknown Error. The code is as follows;
#!/usr/local/bin/perl use SNMP_Session; use BER; use Socket; $session = SNMPv1_Session->open_trap_session (); while (($trap, $sender, $sender_port) = $session->receive_trap ()) { $DATE = localtime(time); # chomp ($DATE= `/bin/date \'+%a %b %e %T\'` ); print STDERR "n$DATE - " . inet_ntoa($sender) . " - port: $sender_ +port\n"; print_trap ($session, $trap); } sub print_trap ($$) { ($this, $trap) = @_; my($community, $ent, $agent, $gen, $spec, $dt, @bindings) = $this->decode_trap_request ($trap); print " Community:\t".$community."\n"; print " Enterprise:\t".BER::pretty_oid ($ent)."\n"; print " Agent addr:\t".inet_ntoa ($agent)."\n"; print " Generic ID:\t$gen\n"; print " Specific ID:\t$spec\n"; print " Uptime:\t".BER::pretty_uptime_value ($dt)."\n"; $prefix = " bindings:\t"; my ($binding, $oid, $value); while ($bindings ne ''){ print "binds = ".$bindings.\n; ($binding,$bindings) = &decode_sequence ($bindings); ($oid, $value) = decode_by_template ($binding,"%0%@"); print $prefix.BER::pretty_oid ($oid)." => ".pretty_print ($val +ue)."\n"; $prefix = "\t\t"; } }
Do I have a problem with the socket set up or is the code wrong. I would be grateful for any help or suggestions b-unit briancgs@aol.com

In reply to Unknown Socket error by b-unit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.