Ping support
diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c
index d8f51df..836e160 100644
--- a/sgsnemu/cmdline.c
+++ b/sgsnemu/cmdline.c
@@ -1,7 +1,7 @@
 /*
-  File autogenerated by gengetopt version 2.8
+  File autogenerated by gengetopt version 2.8rc
   generated with the following command:
-  gengetopt --conf-parser 
+  ../../gengetopt-2.8rc/src/gengetopt --conf-parser 
 
   The developers of gengetopt consider the fixed text that goes in all
   gengetopt output files to be in the public domain:
@@ -52,10 +52,7 @@
   printf("              --dns=STRING       DNS Server to use\n");
   printf("   -lSTRING   --listen=STRING    Local interface\n");
   printf("   -rSTRING   --remote=STRING    Remote host\n");
-  printf("   -nSTRING   --net=STRING       Network (default='192.168.0.0')\n");
-  printf("              --mask=STRING      Network mask (default='255.255.255.0')\n");
   printf("              --contexts=INT     Number of contexts (default='1')\n");
-  printf("              --static           Allocate static tun ifterface (default=off)\n");
   printf("              --timelimit=INT    Exit after timelimit seconds (default='0')\n");
   printf("   -aSTRING   --apn=STRING       Access point name (default='internet')\n");
   printf("   -iSTRING   --imsi=STRING      IMSI (default='240010123456789')\n");
@@ -63,6 +60,17 @@
   printf("   -qINT      --qos=INT          Requested quality of service (default='0x0b921f')\n");
   printf("   -uSTRING   --uid=STRING       Login user ID (default='mig')\n");
   printf("   -pSTRING   --pwd=STRING       Login password (default='hemmelig')\n");
+  printf("              --createif         Create local network interface (default=off)\n");
+  printf("              --ipup=STRING      Script to run after link-up\n");
+  printf("              --ipdown=STRING    Script to run after link-down\n");
+  printf("              --defaultroute     Add default route after link-up (default=off)\n");
+  printf("              --net=STRING       Network (default='0.0.0.0')\n");
+  printf("              --mask=STRING      Network mask (default='0.0.0.0')\n");
+  printf("              --pinghost=STRING  Ping remote host\n");
+  printf("              --pingrate=INT     Number of ping req per second (default='1')\n");
+  printf("              --pingsize=INT     Number of ping data bytes (default='56')\n");
+  printf("              --pingcount=INT    Number of ping req to send (default='0')\n");
+  printf("              --pingquiet        Do not print ping packet info (default=off)\n");
 }
 
 
@@ -96,10 +104,7 @@
   args_info->dns_given = 0 ;
   args_info->listen_given = 0 ;
   args_info->remote_given = 0 ;
-  args_info->net_given = 0 ;
-  args_info->mask_given = 0 ;
   args_info->contexts_given = 0 ;
-  args_info->static_given = 0 ;
   args_info->timelimit_given = 0 ;
   args_info->apn_given = 0 ;
   args_info->imsi_given = 0 ;
@@ -107,6 +112,17 @@
   args_info->qos_given = 0 ;
   args_info->uid_given = 0 ;
   args_info->pwd_given = 0 ;
+  args_info->createif_given = 0 ;
+  args_info->ipup_given = 0 ;
+  args_info->ipdown_given = 0 ;
+  args_info->defaultroute_given = 0 ;
+  args_info->net_given = 0 ;
+  args_info->mask_given = 0 ;
+  args_info->pinghost_given = 0 ;
+  args_info->pingrate_given = 0 ;
+  args_info->pingsize_given = 0 ;
+  args_info->pingcount_given = 0 ;
+  args_info->pingquiet_given = 0 ;
 #define clear_args() { \
   args_info->fg_flag = 0;\
   args_info->debug_flag = 0;\
@@ -116,10 +132,7 @@
   args_info->dns_arg = NULL; \
   args_info->listen_arg = NULL; \
   args_info->remote_arg = NULL; \
-  args_info->net_arg = strdup("192.168.0.0") ;\
-  args_info->mask_arg = strdup("255.255.255.0") ;\
   args_info->contexts_arg = 1 ;\
-  args_info->static_flag = 0;\
   args_info->timelimit_arg = 0 ;\
   args_info->apn_arg = strdup("internet") ;\
   args_info->imsi_arg = strdup("240010123456789") ;\
@@ -127,6 +140,17 @@
   args_info->qos_arg = 0x0b921f ;\
   args_info->uid_arg = strdup("mig") ;\
   args_info->pwd_arg = strdup("hemmelig") ;\
+  args_info->createif_flag = 0;\
+  args_info->ipup_arg = NULL; \
+  args_info->ipdown_arg = NULL; \
+  args_info->defaultroute_flag = 0;\
+  args_info->net_arg = strdup("0.0.0.0") ;\
+  args_info->mask_arg = strdup("0.0.0.0") ;\
+  args_info->pinghost_arg = NULL; \
+  args_info->pingrate_arg = 1 ;\
+  args_info->pingsize_arg = 56 ;\
+  args_info->pingcount_arg = 0 ;\
+  args_info->pingquiet_flag = 0;\
 }
 
   clear_args();
@@ -151,10 +175,7 @@
         { "dns",	1, NULL, 0 },
         { "listen",	1, NULL, 'l' },
         { "remote",	1, NULL, 'r' },
-        { "net",	1, NULL, 'n' },
-        { "mask",	1, NULL, 0 },
         { "contexts",	1, NULL, 0 },
-        { "static",	0, NULL, 0 },
         { "timelimit",	1, NULL, 0 },
         { "apn",	1, NULL, 'a' },
         { "imsi",	1, NULL, 'i' },
@@ -162,10 +183,21 @@
         { "qos",	1, NULL, 'q' },
         { "uid",	1, NULL, 'u' },
         { "pwd",	1, NULL, 'p' },
+        { "createif",	0, NULL, 0 },
+        { "ipup",	1, NULL, 0 },
+        { "ipdown",	1, NULL, 0 },
+        { "defaultroute",	0, NULL, 0 },
+        { "net",	1, NULL, 0 },
+        { "mask",	1, NULL, 0 },
+        { "pinghost",	1, NULL, 0 },
+        { "pingrate",	1, NULL, 0 },
+        { "pingsize",	1, NULL, 0 },
+        { "pingcount",	1, NULL, 0 },
+        { "pingquiet",	0, NULL, 0 },
         { NULL,	0, NULL, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVfdc:l:r:n:a:i:m:q:u:p:", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVfdc:l:r:a:i:m:q:u:p:", long_options, &option_index);
 
       if (c == -1) break;	/* Exit from `while (1)' loop.  */
 
@@ -236,17 +268,6 @@
           args_info->remote_arg = strdup (optarg);
           break;
 
-        case 'n':	/* Network.  */
-          if (args_info->net_given)
-            {
-              fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE);
-              clear_args ();
-              exit (EXIT_FAILURE);
-            }
-          args_info->net_given = 1;
-          args_info->net_arg = strdup (optarg);
-          break;
-
         case 'a':	/* Access point name.  */
           if (args_info->apn_given)
             {
@@ -354,19 +375,6 @@
             args_info->dns_arg = strdup (optarg);
             break;
           }
-          /* Network mask.  */
-          else if (strcmp (long_options[option_index].name, "mask") == 0)
-          {
-            if (args_info->mask_given)
-              {
-                fprintf (stderr, "%s: `--mask' option given more than once\n", PACKAGE);
-                clear_args ();
-                exit (EXIT_FAILURE);
-              }
-            args_info->mask_given = 1;
-            args_info->mask_arg = strdup (optarg);
-            break;
-          }
           /* Number of contexts.  */
           else if (strcmp (long_options[option_index].name, "contexts") == 0)
           {
@@ -380,19 +388,6 @@
             args_info->contexts_arg = strtol (optarg,&stop_char,0);
             break;
           }
-          /* Allocate static tun ifterface.  */
-          else if (strcmp (long_options[option_index].name, "static") == 0)
-          {
-            if (args_info->static_given)
-              {
-                fprintf (stderr, "%s: `--static' option given more than once\n", PACKAGE);
-                clear_args ();
-                exit (EXIT_FAILURE);
-              }
-            args_info->static_given = 1;
-            args_info->static_flag = !(args_info->static_flag);
-            break;
-          }
           /* Exit after timelimit seconds.  */
           else if (strcmp (long_options[option_index].name, "timelimit") == 0)
           {
@@ -406,6 +401,149 @@
             args_info->timelimit_arg = strtol (optarg,&stop_char,0);
             break;
           }
+          /* Create local network interface.  */
+          else if (strcmp (long_options[option_index].name, "createif") == 0)
+          {
+            if (args_info->createif_given)
+              {
+                fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->createif_given = 1;
+            args_info->createif_flag = !(args_info->createif_flag);
+            break;
+          }
+          /* Script to run after link-up.  */
+          else if (strcmp (long_options[option_index].name, "ipup") == 0)
+          {
+            if (args_info->ipup_given)
+              {
+                fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->ipup_given = 1;
+            args_info->ipup_arg = strdup (optarg);
+            break;
+          }
+          /* Script to run after link-down.  */
+          else if (strcmp (long_options[option_index].name, "ipdown") == 0)
+          {
+            if (args_info->ipdown_given)
+              {
+                fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->ipdown_given = 1;
+            args_info->ipdown_arg = strdup (optarg);
+            break;
+          }
+          /* Add default route after link-up.  */
+          else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
+          {
+            if (args_info->defaultroute_given)
+              {
+                fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->defaultroute_given = 1;
+            args_info->defaultroute_flag = !(args_info->defaultroute_flag);
+            break;
+          }
+          /* Network.  */
+          else if (strcmp (long_options[option_index].name, "net") == 0)
+          {
+            if (args_info->net_given)
+              {
+                fprintf (stderr, "%s: `--net' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->net_given = 1;
+            args_info->net_arg = strdup (optarg);
+            break;
+          }
+          /* Network mask.  */
+          else if (strcmp (long_options[option_index].name, "mask") == 0)
+          {
+            if (args_info->mask_given)
+              {
+                fprintf (stderr, "%s: `--mask' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->mask_given = 1;
+            args_info->mask_arg = strdup (optarg);
+            break;
+          }
+          /* Ping remote host.  */
+          else if (strcmp (long_options[option_index].name, "pinghost") == 0)
+          {
+            if (args_info->pinghost_given)
+              {
+                fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->pinghost_given = 1;
+            args_info->pinghost_arg = strdup (optarg);
+            break;
+          }
+          /* Number of ping req per second.  */
+          else if (strcmp (long_options[option_index].name, "pingrate") == 0)
+          {
+            if (args_info->pingrate_given)
+              {
+                fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->pingrate_given = 1;
+            args_info->pingrate_arg = strtol (optarg,&stop_char,0);
+            break;
+          }
+          /* Number of ping data bytes.  */
+          else if (strcmp (long_options[option_index].name, "pingsize") == 0)
+          {
+            if (args_info->pingsize_given)
+              {
+                fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->pingsize_given = 1;
+            args_info->pingsize_arg = strtol (optarg,&stop_char,0);
+            break;
+          }
+          /* Number of ping req to send.  */
+          else if (strcmp (long_options[option_index].name, "pingcount") == 0)
+          {
+            if (args_info->pingcount_given)
+              {
+                fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->pingcount_given = 1;
+            args_info->pingcount_arg = strtol (optarg,&stop_char,0);
+            break;
+          }
+          /* Do not print ping packet info.  */
+          else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
+          {
+            if (args_info->pingquiet_given)
+              {
+                fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
+                clear_args ();
+                exit (EXIT_FAILURE);
+              }
+            args_info->pingquiet_given = 1;
+            args_info->pingquiet_flag = !(args_info->pingquiet_flag);
+            break;
+          }
 
         case '?':	/* Invalid option.  */
           /* `getopt_long' already printed an error message.  */
@@ -593,38 +731,6 @@
                 }
               continue;
             }
-          if (!strcmp(fopt, "net"))
-            {
-              if (override || !args_info->net_given)
-                {
-                  args_info->net_given = 1;
-                  if (fnum == 2)
-                    args_info->net_arg = strdup (farg);
-                  else
-                    {
-                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
-                               filename, line_num);
-                      exit (EXIT_FAILURE);
-                    }
-                }
-              continue;
-            }
-          if (!strcmp(fopt, "mask"))
-            {
-              if (override || !args_info->mask_given)
-                {
-                  args_info->mask_given = 1;
-                  if (fnum == 2)
-                    args_info->mask_arg = strdup (farg);
-                  else
-                    {
-                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
-                               filename, line_num);
-                      exit (EXIT_FAILURE);
-                    }
-                }
-              continue;
-            }
           if (!strcmp(fopt, "contexts"))
             {
               if (override || !args_info->contexts_given)
@@ -641,15 +747,6 @@
                 }
               continue;
             }
-          if (!strcmp(fopt, "static"))
-            {
-              if (override || !args_info->static_given)
-                {
-                  args_info->static_given = 1;
-                  args_info->static_flag = !(args_info->static_flag);
-                }
-              continue;
-            }
           if (!strcmp(fopt, "timelimit"))
             {
               if (override || !args_info->timelimit_given)
@@ -762,6 +859,161 @@
                 }
               continue;
             }
+          if (!strcmp(fopt, "createif"))
+            {
+              if (override || !args_info->createif_given)
+                {
+                  args_info->createif_given = 1;
+                  args_info->createif_flag = !(args_info->createif_flag);
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "ipup"))
+            {
+              if (override || !args_info->ipup_given)
+                {
+                  args_info->ipup_given = 1;
+                  if (fnum == 2)
+                    args_info->ipup_arg = strdup (farg);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "ipdown"))
+            {
+              if (override || !args_info->ipdown_given)
+                {
+                  args_info->ipdown_given = 1;
+                  if (fnum == 2)
+                    args_info->ipdown_arg = strdup (farg);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "defaultroute"))
+            {
+              if (override || !args_info->defaultroute_given)
+                {
+                  args_info->defaultroute_given = 1;
+                  args_info->defaultroute_flag = !(args_info->defaultroute_flag);
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "net"))
+            {
+              if (override || !args_info->net_given)
+                {
+                  args_info->net_given = 1;
+                  if (fnum == 2)
+                    args_info->net_arg = strdup (farg);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "mask"))
+            {
+              if (override || !args_info->mask_given)
+                {
+                  args_info->mask_given = 1;
+                  if (fnum == 2)
+                    args_info->mask_arg = strdup (farg);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "pinghost"))
+            {
+              if (override || !args_info->pinghost_given)
+                {
+                  args_info->pinghost_given = 1;
+                  if (fnum == 2)
+                    args_info->pinghost_arg = strdup (farg);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "pingrate"))
+            {
+              if (override || !args_info->pingrate_given)
+                {
+                  args_info->pingrate_given = 1;
+                  if (fnum == 2)
+                    args_info->pingrate_arg = strtol (farg,&stop_char,0);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "pingsize"))
+            {
+              if (override || !args_info->pingsize_given)
+                {
+                  args_info->pingsize_given = 1;
+                  if (fnum == 2)
+                    args_info->pingsize_arg = strtol (farg,&stop_char,0);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "pingcount"))
+            {
+              if (override || !args_info->pingcount_given)
+                {
+                  args_info->pingcount_given = 1;
+                  if (fnum == 2)
+                    args_info->pingcount_arg = strtol (farg,&stop_char,0);
+                  else
+                    {
+                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
+                               filename, line_num);
+                      exit (EXIT_FAILURE);
+                    }
+                }
+              continue;
+            }
+          if (!strcmp(fopt, "pingquiet"))
+            {
+              if (override || !args_info->pingquiet_given)
+                {
+                  args_info->pingquiet_given = 1;
+                  args_info->pingquiet_flag = !(args_info->pingquiet_flag);
+                }
+              continue;
+            }
           
 
           /* Tried all known options. This one is unknown! */