Previous: , Up: Embedding Serveez   [Contents][Index]

5.1.2 A simple example

The following small example shows how to use the Serveez core library to print the list of known network interface. As you will notice there are three major steps to do: Include the library header with #include <libserveez.h>, initialize the library via svz_boot and finalize it via svz_halt. In between these calls you can use all of the API functions, variables and macros described in Embedding API.

#include <stdio.h>
#include <stdlib.h>
#include <libserveez.h>

static int
display_ifc (const svz_interface_t *ifc,
             void *closure)
  char *addr = svz_inet_ntoa (ifc->ipaddr);

  if (ifc->description)
    /* interface with description */
    printf ("%40s: %s\n",
            ifc->description, addr);
    /* interface with interface # only */
    printf ("%31s%09lu: %s\n",
            "interface # ", ifc->index, addr);
  return 0;

main (int argc, char **argv)
  /* Library initialization.  */
  svz_boot ("example");

  /* Display a list of interfaces.  */
  printf ("local interfaces:\n");
  svz_foreach_interface (display_ifc, NULL);

  /* Library finalization.  */
  svz_halt ();

  return EXIT_SUCCESS;