GCJ Support

 

The GNU compiler for Java or GCJ is used for compiling Java source code as native machine code. It is a portable, optimal, ahead-of-time compiler for the Java programming language. It can compile:

Support for GCJ is included in the low-level API. Developers can use this support for developing native run-time SNMP agents and manager applications.

 

The packages required for using GCJ are:

This can be downloaded from http://sourceware.cygnus.com/java

 

Note that there is no change in the core SNMP APIs because of GCJ support. The only requirement is the additional package (the gcjsnmp2.jar file). The existing snmp2 package can be used for both GCJ and Java applications.

 

Extracting gcjsnmp2 Package

 

The gcjsnmp2.jar file has to be manually extracted because the GCJ compiler does not look into jar files for the classes. This can be done using the JDK's jar tool in one of the following ways.

While compiling the AdventNet classes for GCJ, make sure that the following classes are compiled from the gcjsnmp2 package and not from com.adventnet.snmp.snmp2 or JDK package.

This could be done by moving the original SASClient class from the snmp2 directory to a different directory and compiling it.

 

Environment Setting for GCJ Compilation

 

There is a file called snmp.properties in the classes/com/adventnet/snmp/snmp2/ directory . This file has to be edited to have the following line.

 

GCJ_COMPILE = 1

 

The default value of this option is 0.

 

Compiling with the AdventNet SNMP Low-Level API

 

The following diagram illustrates how the user can develop a native SNMP application using the AdventNet API with the GCJ compiler.

 

 

Step I - Create a native library of the AdventNet snmp2 package

 

The com.adventnet.snmp.snmp2 package along with the gcjsnmp2.jar classes is given to GCJ to get the SNMP2 libraries. Then a shared or a static library archive can be created. The shared library is created by GCJ itself. To create a static library, the classes should be first converted to object files using GCJ. Then a library archive of the object files can be created.

 

For example, to create a shared library (in Unix-based systems), type the following command.

 

gcj -shared snmp2 classes gcjsnmp2 classes o libsnmp2.so

 

The above command creates a shared library file where the snmp2 classes are in the com.adventnet.snmp.snmp2 package and gcjsnmp2 classes are in the extracted gcjsnmp2.jar file.

 

To create a static library (in Unix-based systems):

  1. Create the object (.o) files.

gcj -c snmp2 classes gcjsnmp2 classes

  1. Create the archive of the object files.

ar rv libsnmp2.a *.o

  1. Create the library.

ranlib libsnmp2.a

 

Step II - Create the executable of the SNMP application that uses the AdventNet's snmp2 package

 

The user application could be compiled and linked with the snmp2 library (created in Step I) to produce the native application. For example, the following command creates the native executable called UserExecutable linked with the libsnmp2 library created in Step I.

 

gcj -lsnmp2 user classes or java source files o UserExecutable

 

The user classes or Java source files belong to the user's application.

 

Known Issues in GCJ

  1. GCJ does not work with 2.95.1 release.

This is because of the usage of receive methods in Datagram sockets inside threads. The application hangs indefinitely inside the receive call. Also, the library does not have a full implementation of the java.security package, which is required for SNMPv3.

 

Note: The workaround is to use the latest CVS or the latest RPM version of the compiler.

  1. Latest RPM and CVS versions of the compiler works only for the NoAuthNoPriv security level in SNMPv3.

The AuthPriv and AuthNoPriv security levels in SNMPv3 version cannot be supported because the libgcj library (from the latest RPM and CVS) does not implement of the MD5 algorithm by default as in JDK. The MD5 algorithm is used for calculating digests of the SNMP messages for these levels. At run time, this throws NoSuchAlgorithmException because of the MD5 algorithm not being found. Also for privacy, the DES encryption is required, which is not available in the library.

 

Note: The workaround is downloading the third-party implementation of these algorithms (source), integrating with the libgcj library source, and compiling. There is an implementation of Message Digest and DES encryption from Cryptix, which can be downloaded from http://www.cryptix.org.



Copyright © 1996-2005, AdventNet Inc. All Rights Reserved.