Submitter: Stephen J. Friedl steve at unixwiz.net For: net-snmp-5.0.7 Purpose: Enable UDP broadcasts in NET-SNMP Date: Sun Feb 16 10:58:49 PST 2003 This patch enables the setting of UDP broadcast on an SNMP session. The equipment I'm talking to initially has no IP address, and this is the only way of performing configuration that suits our purposes (these are JetDirect-like print servers). The code itself is pretty self-contained, but it's likely that somebody else will pick another value for the "next" flag in the SNMP_FLAGS_xxx series unless this gets picked up by the main team. It's also likely that my hack is sub-optimal. APPLYING THIS PATCH # cd net-snmp-5.0.7 # patch -p0 < THIS.PATCH.FILE ENABLING UDP BROADCAST To use this, simply set the flag in the session template: struct snmp_session sess_template; snmp_sess_init(&sess_template); ... sess_template.peername = strdup("255.255.255.255"); sess_template.flags |= SNMP_FLAGS_UDP_BROADCAST; ... sess_template.callback = asynch_response; ... This attempts to set the SO_BROADCAST flag on the created socket, and it fails if this can't be done. We really need to use the async methods, because each request to 255.255.255.255 generates more than one response. When the async_response() callback returns 1, the library knows that this request has been satisfied, so to correctly process the multiple responses, it has to always return 0. -- Stephen J Friedl | Software Consultant | Tustin, CA | +1 714 544-6561 www.unixwiz.net | I speak for me only | KA8CMY | steve@unixwiz.net --- include/net-snmp/library/snmp_api.h.orig 2003-02-14 03:05:44.000000000 +0000 +++ include/net-snmp/library/snmp_api.h 2003-02-16 19:15:01.000000000 +0000 @@ -289,6 +289,7 @@ #define SNMP_DETAIL_SIZE 512 +#define SNMP_FLAGS_UDP_BROADCAST 0x200 /* SJF 2003/02/16 */ #define SNMP_FLAGS_DONT_PROBE 0x100 /* don't probe for an engineID */ #define SNMP_FLAGS_STREAM_SOCKET 0x80 #define SNMP_FLAGS_LISTENING 0x40 /* Server stream sockets only */ --- snmplib/snmp_api.c.orig 2003-02-14 03:06:33.000000000 +0000 +++ snmplib/snmp_api.c 2003-02-16 19:15:38.000000000 +0000 @@ -1300,6 +1300,28 @@ slp->transport = netsnmp_tdomain_transport(session->peername, session->local_port, "udp"); + + /* + * enable broadcast if we can, but it can only be for UDP. + * SJF 2003/02/16 + */ + + if ( slp->transport != 0 && (session->flags & SNMP_FLAGS_UDP_BROADCAST) ) { + int b = 1; + int rc; + + rc = setsockopt( slp->transport->sock, SOL_SOCKET, SO_BROADCAST, + (char *)&b, + sizeof b); + + if ( rc != 0 ) { + in_session->s_snmp_errno = SNMPERR_BAD_ADDRESS; /* good as any? */ + in_session->s_errno = errno; + + DEBUGMSGTL(("_sess_open", "couldn't enable UDP_BROADCAST\n")); + return NULL; + } + } } if (slp->transport == NULL) {