• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

test_api.c

00001 /*
00002  * Run this after adding a new attribute to the nf_conntrack object
00003  */
00004 
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <unistd.h>
00008 #include <sys/wait.h>
00009 #include <errno.h>
00010 
00011 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
00012 
00013 /*
00014  * this file contains a test to check the set/get/copy/cmp APIs.
00015  */
00016 
00017 static void eval_sigterm(int status)
00018 {
00019         switch(WTERMSIG(status)) {
00020         case SIGSEGV:
00021                 printf("received SIGSEV\n");
00022                 break;
00023         case 0:
00024                 printf("OK\n");
00025                 break;
00026         default:
00027                 printf("exited with signal: %d\n", WTERMSIG(status));
00028                 break;
00029         }
00030 }
00031 
00032 int main(void)
00033 {
00034         int ret, i;
00035         struct nf_conntrack *ct, *tmp;
00036         char data[32];
00037         int status;
00038 
00039         /* initialize fake data for testing purposes */
00040         for (i=0; i<sizeof(data); i++)
00041                 data[i] = 0x01;
00042 
00043         ct = nfct_new();
00044         if (!ct) {
00045                 perror("nfct_new");
00046                 return 0;
00047         }
00048         tmp = nfct_new();
00049         if (!tmp) {
00050                 perror("nfct_new");
00051                 return 0;
00052         }
00053 
00054         printf("== test set API ==\n");
00055         ret = fork();
00056         if (ret == 0) {
00057                 for (i=0; i<ATTR_MAX; i++)
00058                         nfct_set_attr(ct, i, data);
00059                 exit(0);
00060         } else {
00061                 wait(&status);
00062                 eval_sigterm(status);
00063         }
00064 
00065         for (i=0; i<ATTR_MAX; i++)
00066                 nfct_set_attr(ct, i, data);
00067 
00068         printf("== test get API ==\n");
00069         ret = fork();
00070         if (ret == 0) {
00071                 for (i=0; i<ATTR_MAX; i++)
00072                         nfct_get_attr(ct, i);
00073                 exit(0);
00074         } else {
00075                 wait(&status);
00076                 eval_sigterm(status);
00077         }
00078 
00079         printf("== test copy API ==\n");
00080         ret = fork();
00081         if (ret == 0) {
00082                 for (i=0; i<ATTR_MAX; i++)
00083                         nfct_copy_attr(tmp, ct, i);
00084                 exit(0);
00085         } else {
00086                 wait(&status);
00087                 eval_sigterm(status);
00088         }
00089 
00090         printf("== test cmp API ==\n");
00091         ret = fork();
00092         if (ret == 0) {
00093                 nfct_cmp(tmp, ct, NFCT_CMP_ALL);
00094                 exit(0);
00095         } else {
00096                 wait(&status);
00097                 eval_sigterm(status);
00098         }
00099 
00100         nfct_destroy(ct);
00101         nfct_destroy(tmp);
00102         return EXIT_SUCCESS;
00103 }

Generated on Wed Jan 26 2011 23:11:37 for libnetfilter_conntrack by  doxygen 1.7.1