Next: , Previous: , Up: Top   [Contents]


4 Programming with the library

LibNetBlock comes with a development package. You can use the following public functions and constants:

If you’re using C or C++ (or any language that can parse C header files), you can use the header file directly. Simply type:

	#include <libnetblock.h>

and compile the program with the library, e.g.:

gcc -o your_prog your_prog.c -lnetblock -ldl

If needed, LibNetBlock should be first in link order.

If you want to use LibNetBlock with some other programming language, you can generate bindings to LibNetBlock for that language. You can use SWIG for this purpose. The header file is compatible with SWIG, so you can simply run:

swig -<your_lang> [<other options>] /path/to/libnetblock.h

e.g.

swig -php -o lnb_wrap_php.c /usr/include/libnetblock.h

You can then compile the generated wrapper files:

gcc -fpic -c lnb_wrap_*.c

and link them into one or separate shared libraries:

gcc -shared lnb_wrap_*.o -lnetblock -o lnb_wrapper.so

After this, you can link your program with the wrapper library and LibNetBlock:

gcc -o your_prog your_prog.c lnb_wrapper.so -lnetblock -ldl

or use the library in other languages, as shown in the SWIG examples.

LibNetBlock will not contain the interfaces compiled-in, because there may be incompatibilities between languages or even between different versions of the same language, causing compile-time or other conflicts and unnecessary dependencies.

By using SWIG yourself, you can be sure that such problems will not occur.


Next: , Previous: , Up: Top   [Contents]