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


3 Making the library work

LibNetBlock has no magic in it, it won’t intercept calls to the mentioned functions just because it is compiled. Even installing the library in a system directory isn’t enough. The library needs to be loaded into memory. More strictly, it needs to be PRELOADED (loaded before other libraries). This is achieved easily, if you are using ld.so (or derivatives) to load libraries (like on GNU/Linux). Just add the following line:

export LD_PRELOAD=/usr/local/lib/libnetblock.so

to your startup scripts (like $HOME/.bashrc, $HOME/.bash_profile). You should change the path to the correct one. If you aren’t using bash, consult your shell manual for details on how to export an environment variable.

This will make the dynamic linker, ld.so, load LibNetBlock before loading any other libraries, when starting programs. That is, after the line above gets executed, all programs from that moment start using LibNetBlock.

You can alternatively put the full path to the library in the /etc/ld.so.preload (NOT recommended, because some good programs may need network access). No syntax is required, just the path and filename, like this:

/usr/local/lib/libnetblock.so

To load LibNetBlock for just one program, type like this (for bash):

LD_PRELOAD=/usr/local/lib/libnetblock.so some-program-name