public static SnmpEngineId createEngineId(int iana,InetAddress addr){
  if (addr == null)   throw new IllegalArgumentException("InetAddress is null.");
  byte[] address=addr.getAddress();
  byte[] engineid=new byte[5 + address.length];
  engineid[0]=(byte)((iana & 0xFF000000) >> 24);
  engineid[0]|=0x80;
  engineid[1]=(byte)((iana & 0x00FF0000) >> 16);
  engineid[2]=(byte)((iana & 0x0000FF00) >> 8);
  engineid[3]=(byte)(iana & 0x000000FF);
  if (address.length == 4)   engineid[4]=0x01;
  if (address.length == 16)   engineid[4]=0x02;
  for (int i=0; i < address.length; i++) {
    engineid[i + 5]=address[i];
  }
  return new SnmpEngineId(engineid);
}

public static SnmpEngineId createEngineId ( int iana , InetAddress addr ) { if ( addr == null ) throw new IllegalArgumentException ( "InetAddress is null." ) ; byte [ ] address = addr . getAddress ( ) ; byte [ ] engineid = new byte [ 5 + address . length ] ; engineid [ 0 ] = ( byte ) ( ( iana & 0xFF000000 ) > > 24 ) ; engineid [ 0 ] |= 0x80 ; engineid [ 1 ] = ( byte ) ( ( iana & 0x00FF0000 ) > > 16 ) ; engineid [ 2 ] = ( byte ) ( ( iana & 0x0000FF00 ) > > 8 ) ; engineid [ 3 ] = ( byte ) ( iana & 0x000000FF ) ; if ( address . length == 4 ) engineid [ 4 ] = 0x01 ; if ( address . length == 16 ) engineid [ 4 ] = 0x02 ; for ( int i = 0 ; i < address . length ; i ++ ) { engineid [ i + 5 ] = address [ i ] ; } return new SnmpEngineId ( engineid ) ; }
generates an engine id based on an inetaddress . handles ipv4 and ipv6 addresses . the creation algorithm uses the passed iana number .
