[SNMP4J] IPv6 Address with Scope

Frank Fock fock at agentpp.com
Sat Mar 21 00:41:53 CET 2009


Senthil,

Thanks for your fix. However, IPv4 zoned addresses
are not handled correctly by it. I am working on
solution that covers those too.

Best regards,
Frank

Senthil Muniswamy wrote:
> Frank,
> I am using SNMP4J-Agent and
> TransportIpAddress.setTransportAddress(OctetString transportAddress)
> causes exception if snmpTargetAddrTAddress is set with TAddress (IPv6
> Address with Scope).
> 
> I have made below changes to TransportIpAddress to handle the scope,
> could you please confirm if this is correct?
> 
>   public void setTransportAddress(OctetString transportAddress) throws
>       UnknownHostException {
>     OctetString inetAddr =
>         transportAddress.substring(0, transportAddress.length()-2);
>     byte[] addr = inetAddr.getValue();
>     if(addr.length <= 16) {
>     	setInetAddress(InetAddress.getByAddress(addr));
>     }
>     else {
>         byte[] ip6addr = new byte[16];
>         System.arraycopy(addr, 0, ip6addr, 0, ip6addr.length);
>         int scope = ((addr[16] << 24) + ((addr[17] & 0xff) << 16) +
> ((addr[18] & 0xFF) << 8) +
>                 (addr[19] & 0xFF));
>         setInetAddress(Inet6Address.getByAddress(null, ip6addr, scope));
>     }
>     port = ((transportAddress.get(transportAddress.length()-2) & 0xFF) << 8);
>     port += (transportAddress.get(transportAddress.length()-1) & 0xFF);
>   }
> 
>   public byte[] getValue() {
>         byte[] addr = getInetAddress().getAddress();
>         int size = 2;
>         if(getInetAddress() instanceof Inet6Address &&
>                 ((Inet6Address)getInetAddress()).getScopeId() > 0) {
>             size = size+4;
>         }
>         byte[] retval = new byte[addr.length+size];
>         System.arraycopy(addr, 0, retval, 0, addr.length);
>         if(size > 2) {
>             int scope = ((Inet6Address)getInetAddress()).getScopeId();
>             retval[addr.length] = (byte)((scope & 0xFF000000) >> 24);
>             retval[addr.length+1] = (byte)((scope & 0x00FF0000) >> 16);
>             retval[addr.length+2] = (byte)((scope & 0x0000FF00) >> 8);
>             retval[addr.length+3] = (byte)(scope & 0x000000FF);
>         }
>         retval[retval.length-2] = (byte)((port >> 8) & 0xFF);
>         retval[retval.length-1] = (byte)(port & 0xFF);
>     return retval;
>   }
> 
>   public int getBERLength() {
>     return getValue().length;
>   }
> 
> 
> Thanks,
> Senthil
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list