--------------------- PatchSet 4719 Date: 2007/06/11 13:27:37 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Roll conversion into SNMP/comm interface Members: src/snmp_core.cc:1.10.8.9->1.10.8.10 Index: squid3/src/snmp_core.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/snmp_core.cc,v retrieving revision 1.10.8.9 retrieving revision 1.10.8.10 diff -u -r1.10.8.9 -r1.10.8.10 --- squid3/src/snmp_core.cc 1 May 2007 08:32:31 -0000 1.10.8.9 +++ squid3/src/snmp_core.cc 11 Jun 2007 13:27:37 -0000 1.10.8.10 @@ -1,6 +1,6 @@ /* - * $Id: snmp_core.cc,v 1.10.8.9 2007/05/01 08:32:31 amosjeffries Exp $ + * $Id: snmp_core.cc,v 1.10.8.10 2007/06/11 13:27:37 amosjeffries Exp $ * * DEBUG: section 49 SNMP support * AUTHOR: Glenn Chisholm @@ -359,19 +359,17 @@ snmpConnectionOpen(void) { u_short port; - - struct sockaddr_in xaddr; - socklen_t len; + struct addrinfo *xaddr = NULL; int x; debugs(49, 5, "snmpConnectionOpen: Called"); - if ((port = Config.Port.snmp) > (u_short) 0) { + if (Config.Port.snmp > (u_short) 0) { + Config.Addrs.snmp_incoming.SetPort(Config.Port.snmp); enter_suid(); theInSnmpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, Config.Addrs.snmp_incoming, - port, COMM_NONBLOCKING, "SNMP Port"); leave_suid(); @@ -383,12 +381,12 @@ debugs(1, 1, "Accepting SNMP messages on port " << port << ", FD " << theInSnmpConnection << "."); - if (Config.Addrs.snmp_outgoing.s_addr != no_addr.s_addr) { + if (!Config.Addrs.snmp_outgoing.IsNoAddr()) { + Config.Addrs.snmp_outgoing.SetPort(Config.Port.snmp); enter_suid(); theOutSnmpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, Config.Addrs.snmp_outgoing, - port, COMM_NONBLOCKING, "SNMP Port"); leave_suid(); @@ -410,18 +408,18 @@ theOutSnmpConnection = theInSnmpConnection; } - memset(&theOutSNMPAddr, '\0', sizeof(struct IN_ADDR)); + theOutSNMPAddr.SetEmpty(); - len = sizeof(struct sockaddr_in); - memset(&xaddr, '\0', len); - x = getsockname(theOutSnmpConnection, + theOutSNMPAddr.GetAddrInfo(xaddr); - (struct sockaddr *) &xaddr, &len); + x = getsockname(theOutSnmpConnection,xaddr->ai_addr, &xaddr->ad_addrlen); if (x < 0) debugs(51, 1, "theOutSnmpConnection FD " << theOutSnmpConnection << ": getsockname: " << xstrerror()); else - theOutSNMPAddr = xaddr.sin_addr; + theOutSNMPAddr = *xaddr; + + theOutSNMPAddr.FreeAddrInfo(xaddr); } } @@ -476,9 +474,7 @@ snmpHandleUdp(int sock, void *not_used) { LOCAL_ARRAY(char, buf, SNMP_REQUEST_SIZE); - - struct sockaddr_in from; - socklen_t from_len; + IPAddress from; snmp_request_t *snmp_rq; int len; @@ -486,21 +482,22 @@ commSetSelect(sock, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); - from_len = sizeof(struct sockaddr_in); - memset(&from, '\0', from_len); + from.GetAddrInfo(AI); memset(buf, '\0', SNMP_REQUEST_SIZE); len = comm_udp_recvfrom(sock, buf, SNMP_REQUEST_SIZE, 0, + from); - (struct sockaddr *) &from, - &from_len); - - if (len > 0) { + /* INET6 : SNMP still has no IPv6 Support */ + if(!from.IsIPv4()) { + debugs(49,1, "snmpHandleUdp: FD " << sock << " cannot handle data from non-IPv4 source " << from); + } + else if (len > 0) { buf[len] = '\0'; - debugs(49, 3, "snmpHandleUdp: FD " << sock << ": received " << len << " bytes from " << inet_ntoa(from.sin_addr) << "."); + debugs(49, 3, "snmpHandleUdp: FD " << sock << ": received " << len << " bytes from " << from << "."); snmp_rq = (snmp_request_t *)xcalloc(1, sizeof(snmp_request_t)); snmp_rq->buf = (u_char *) buf; @@ -508,7 +505,7 @@ snmp_rq->sock = sock; snmp_rq->outbuf = (unsigned char *)xmalloc(snmp_rq->outlen = SNMP_REQUEST_SIZE); - xmemcpy(&snmp_rq->from, &from, sizeof(struct sockaddr_in)); + from.GetSockAddr(snmp_rq->from); snmpDecodePacket(snmp_rq); xfree(snmp_rq->outbuf); xfree(snmp_rq); @@ -523,9 +520,7 @@ static void snmpDecodePacket(snmp_request_t * rq) { - struct snmp_pdu *PDU; - u_char *Community; u_char *buf = rq->buf; int len = rq->len;