certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi RTIG/CMakeLists.txt RTIG/RTIG.ggo RTIG/RT...


From: CERTI CVS commits
Subject: [certi-cvs] certi RTIG/CMakeLists.txt RTIG/RTIG.ggo RTIG/RT...
Date: Wed, 04 Sep 2013 07:56:58 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      13/09/04 07:56:57

Modified files:
        RTIG           : CMakeLists.txt RTIG.ggo RTIG.cc RTIG_cmdline.c 
                         RTIG_cmdline.h RTIG.hh main.cc 
        libCERTI       : Socket.hh 

Log message:
        Add -l command line option to RTIG in order to listen on a specific 
address@hidden address and not all of them.
        Fixes bug #35955

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/CMakeLists.txt?cvsroot=certi&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.ggo?cvsroot=certi&r1=3.1&r2=3.2
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.cc?cvsroot=certi&r1=3.69&r2=3.70
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG_cmdline.c?cvsroot=certi&r1=3.1&r2=3.2
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG_cmdline.h?cvsroot=certi&r1=3.1&r2=3.2
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.hh?cvsroot=certi&r1=3.37&r2=3.38
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/main.cc?cvsroot=certi&r1=3.22&r2=3.23
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Socket.hh?cvsroot=certi&r1=3.20&r2=3.21

Patches:
Index: RTIG/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/RTIG/CMakeLists.txt,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- RTIG/CMakeLists.txt 18 Dec 2011 16:02:22 -0000      1.9
+++ RTIG/CMakeLists.txt 4 Sep 2013 07:56:30 -0000       1.10
@@ -1,22 +1,35 @@
 include_directories(${CERTI_SOURCE_DIR}/libHLA)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libCERTI)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libRTI)
+include_directories(${CMAKE_SOURCE_DIR}/libCERTI)
+include_directories(${CMAKE_SOURCE_DIR}/libRTI)
 
-SET(rtig_SRCS
-  Federate.cc
-  Federation.cc
-  FederationsList.cc
+find_program(GENGETOPT_PROGRAM NAMES gengetopt)
+if (GENGETOPT_PROGRAM)
+   set(GGOFILE ${CMAKE_CURRENT_SOURCE_DIR}/RTIG.ggo)
+   add_custom_target(GenRTIGCmdline
+                    COMMAND ${GENGETOPT_PROGRAM} --no-handle-error 
--show-required -i ${GGOFILE}
+                    DEPENDS ${GGOFILE}
+                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                    COMMENT "Regenerate RTIG command line C files -- (from 
${GGOFILE})"
+                    )
+endif(GENGETOPT_PROGRAM)
+set(rtig_SRCS_generated
+    RTIG_cmdline.c RTIG_cmdline.h)
+
+set(rtig_SRCS
+  Federate.cc Federate.hh
+  Federation.cc Federation.hh
+  FederationsList.cc FederationsList.hh
   main.cc
-  RTIG.cc
+  RTIG.cc RTIG.hh
   RTIG_processing.cc
-  Trace.cc
-  RTIG_cmdline.c  
+  Trace.cc Trace.hh
+  ${rtig_SRCS_generated}
   )
 
-ADD_EXECUTABLE(rtig ${rtig_SRCS})
-TARGET_LINK_LIBRARIES(rtig CERTI)
+add_executable(rtig ${rtig_SRCS})
+target_link_libraries(rtig CERTI)
 
-INSTALL(TARGETS rtig
+install(TARGETS rtig
     EXPORT CERTIDepends
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION lib

Index: RTIG/RTIG.ggo
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.ggo,v
retrieving revision 3.1
retrieving revision 3.2
diff -u -b -r3.1 -r3.2
--- RTIG/RTIG.ggo       30 Oct 2008 10:49:27 -0000      3.1
+++ RTIG/RTIG.ggo       4 Sep 2013 07:56:31 -0000       3.2
@@ -3,12 +3,12 @@
 
 package "RTIG"
 purpose "CERTI RunTime Infrastructure Gateway (RTIG)"
-usage  "rtig [-v 2]"
+usage  "rtig [-v 2] [-l @IP]"
 
 # gengetopt options
 args "-F RTIG_cmdline -G"
 
 # Options
 option "verbose"       v       "verbosity level\n 0 -> no output\n 1 -> small 
amount\n 2 -> show fed parse"    int     optional
-
-# $Id: RTIG.ggo,v 3.1 2008/10/30 10:49:27 erk Exp $
+option "listen"  l "listen only on specified IP address (hostname may be used 
as well)" string optional
+#
\ No newline at end of file

Index: RTIG/RTIG.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.cc,v
retrieving revision 3.69
retrieving revision 3.70
diff -u -b -r3.69 -r3.70
--- RTIG/RTIG.cc        2 Sep 2011 21:42:24 -0000       3.69
+++ RTIG/RTIG.cc        4 Sep 2013 07:56:32 -0000       3.70
@@ -18,7 +18,7 @@
 // along with this program ; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// $Id: RTIG.cc,v 3.69 2011/09/02 21:42:24 erk Exp $
+// $Id: RTIG.cc,v 3.70 2013/09/04 07:56:32 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include <config.h>
@@ -59,15 +59,19 @@
       auditServer(RTIG_AUDIT_FILENAME),
       federations(socketServer, auditServer)
 {
+    this->verboseLevel = 0;
+    // the default is to listen on all network interface
+    // unless -l argument to rtig command line is specified
+    this->listeningIPAddress = 0;
     // Start RTIG services
     const char *tcp_port_s = getenv("CERTI_TCP_PORT");
     const char *udp_port_s = getenv("CERTI_UDP_PORT");
     if (tcp_port_s==NULL) tcp_port_s = PORT_TCP_RTIG ;
     if (udp_port_s==NULL) udp_port_s = PORT_UDP_RTIG ;
-    tcpPort = atoi(tcp_port_s);
-    udpPort = atoi(udp_port_s);
+    this->tcpPort = atoi(tcp_port_s);
+    this->udpPort = atoi(udp_port_s);
 
-    federations.setVerboseLevel(verboseLevel);
+    this->federations.setVerboseLevel(verboseLevel);
 }
 
 // ----------------------------------------------------------------------------
@@ -452,27 +456,41 @@
     G.Out(pdGendoc,"exit  RTIG::closeConnection");
 }
 
+void
+RTIG::setListeningIPAddress(const std::string& hostName) throw (NetworkError) {
+    this->listeningIPAddress = Socket::host2addr(hostName);
+}
+
+
 // ----------------------------------------------------------------------------
 // execute
 // Called only by RTIG main
 void
-RTIG::execute()
-{
-int result ;
-fd_set fd ;
-Socket *link ;
-
-// create TCP and UDP connections for the RTIG server
-udpSocketServer.createUDPServer(udpPort);
-tcpSocketServer.createTCPServer(tcpPort);
-// udpSocketServer.createUDPServer(PORT_UDP_RTIG);
+RTIG::execute() throw (NetworkError) {
+    int result ;
+    fd_set fd ;
+    Socket *link ;
+
+    // create TCP and UDP connections for the RTIG server
+
+    // listen only on specified interface (if any)
+    //  1) listen on interface specified on the command line
+    if (this->listeningIPAddress != 0) {
+        udpSocketServer.createUDPServer(udpPort);
+        tcpSocketServer.createTCPServer(tcpPort, listeningIPAddress);
+    }
+    // default case listen on all network interfaces
+    else {
+        udpSocketServer.createUDPServer(udpPort);
+        tcpSocketServer.createTCPServer(tcpPort);
+    }
 
-if (verboseLevel>0) {
+    if (verboseLevel>0) {
        cout << "CERTI RTIG up and running ..." << endl ;
        }
-terminate = false ;
+    terminate = false ;
 
-while (!terminate) {
+    while (!terminate) {
        // Initialize fd_set structure with all opened sockets.
        #if _WIN32
 
@@ -501,7 +519,7 @@
        if (terminate) break;
 
        if((result == -1)&&(WSAGetLastError() == WSAEINTR)) break;
-       #else
+#else
                FD_ZERO(&fd);
                FD_SET(tcpSocketServer.returnSocket(), &fd);
 
@@ -512,7 +530,7 @@
                result = select(fd_max + 1, &fd, NULL, NULL, NULL);
 
                if((result == -1)&&(errno == EINTR)) break;
-       #endif
+#endif
 
        // Is it a message from an already opened connection?
        link = socketServer.getActiveSocket(&fd);
@@ -1055,4 +1073,4 @@
 
 }} // namespace certi/rtig
 
-// $Id: RTIG.cc,v 3.69 2011/09/02 21:42:24 erk Exp $
+// $Id: RTIG.cc,v 3.70 2013/09/04 07:56:32 erk Exp $

Index: RTIG/RTIG_cmdline.c
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG_cmdline.c,v
retrieving revision 3.1
retrieving revision 3.2
diff -u -b -r3.1 -r3.2
--- RTIG/RTIG_cmdline.c 30 Oct 2008 10:49:28 -0000      3.1
+++ RTIG/RTIG_cmdline.c 4 Sep 2013 07:56:40 -0000       3.2
@@ -1,7 +1,7 @@
 /*
-  File autogenerated by gengetopt version 2.21
+  File autogenerated by gengetopt version 2.22.6
   generated with the following command:
-  gengetopt -i RTIG.ggo -F RTIG_cmdline -G
+  /usr/bin/gengetopt --no-handle-error --show-required -i 
/home/erk/workspace/certi/RTIG/RTIG.ggo -F RTIG_cmdline -G
 
   The developers of gengetopt consider the fixed text that goes in all
   gengetopt output files to be in the public domain:
@@ -17,12 +17,18 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifndef FIX_UNUSED
+#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
+#endif
+
 
 #include "RTIG_cmdline.h"
 
 const char *gengetopt_args_info_purpose = "CERTI RunTime Infrastructure 
Gateway (RTIG)";
 
-const char *gengetopt_args_info_usage = "Usage: rtig [-v 2]";
+const char *gengetopt_args_info_usage = "Usage: rtig [-v 2] [-l @IP]";
+
+const char *gengetopt_args_info_versiontext = "";
 
 const char *gengetopt_args_info_description = "";
 
@@ -30,16 +36,22 @@
   "  -h, --help         Print help and exit",
   "  -V, --version      Print version and exit",
   "  -v, --verbose=INT  verbosity level\n                        0 -> no 
output\n                        1 -> small amount\n                        2 -> 
show fed parse",
+  "  -l, --listen=STRING  listen only on specified IP address",
     0
 };
 
+typedef enum {ARG_NO
+  , ARG_STRING
+  , ARG_INT
+} cmdline_parser_arg_type;
+
 static
 void clear_given (struct gengetopt_args_info *args_info);
 static
 void clear_args (struct gengetopt_args_info *args_info);
 
 static int
-cmdline_parser_internal (int argc, char * const *argv, struct 
gengetopt_args_info *args_info,
+cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info 
*args_info,
                         struct cmdline_parser_params *params, const char 
*additional_error);
 
 
@@ -52,44 +64,62 @@
   args_info->help_given = 0 ;
   args_info->version_given = 0 ;
   args_info->verbose_given = 0 ;
+  args_info->listen_given = 0 ;
 }
 
 static
 void clear_args (struct gengetopt_args_info *args_info)
 {
+  FIX_UNUSED (args_info);
   args_info->verbose_orig = NULL;
+  args_info->listen_arg = NULL;
+  args_info->listen_orig = NULL;
   
 }
 
 static
 void init_args_info(struct gengetopt_args_info *args_info)
 {
+
+
   args_info->help_help = gengetopt_args_info_help[0] ;
   args_info->version_help = gengetopt_args_info_help[1] ;
   args_info->verbose_help = gengetopt_args_info_help[2] ;
+  args_info->listen_help = gengetopt_args_info_help[3] ;
   
 }
 
 void
 cmdline_parser_print_version (void)
 {
-  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
+  printf ("%s %s\n",
+     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : 
CMDLINE_PARSER_PACKAGE),
+     CMDLINE_PARSER_VERSION);
+
+  if (strlen(gengetopt_args_info_versiontext) > 0)
+    printf("\n%s\n", gengetopt_args_info_versiontext);
 }
 
-void
-cmdline_parser_print_help (void)
-{
-  int i = 0;
+static void print_help_common(void) {
   cmdline_parser_print_version ();
 
   if (strlen(gengetopt_args_info_purpose) > 0)
     printf("\n%s\n", gengetopt_args_info_purpose);
 
-  printf("\n%s\n\n", gengetopt_args_info_usage);
+  if (strlen(gengetopt_args_info_usage) > 0)
+    printf("\n%s\n", gengetopt_args_info_usage);
+
+  printf("\n");
 
   if (strlen(gengetopt_args_info_description) > 0)
-    printf("%s\n", gengetopt_args_info_description);
+    printf("%s\n\n", gengetopt_args_info_description);
+}
 
+void
+cmdline_parser_print_help (void)
+{
+  int i = 0;
+  print_help_common();
   while (gengetopt_args_info_help[i])
     printf("%s\n", gengetopt_args_info_help[i++]);
 }
@@ -102,34 +132,88 @@
   init_args_info (args_info);
 }
 
-struct cmdline_parser_params *
-cmdline_parser_params_init()
+void
+cmdline_parser_params_init(struct cmdline_parser_params *params)
 {
-  struct cmdline_parser_params *params = 
-    (struct cmdline_parser_params *)malloc(sizeof(struct 
cmdline_parser_params));
-
   if (params)
     { 
       params->override = 0;
-      params->initialize = 0;
-      params->check_required = 0;
+      params->initialize = 1;
+      params->check_required = 1;
       params->check_ambiguity = 0;
+      params->print_errors = 1;
     }
+}
     
+struct cmdline_parser_params *
+cmdline_parser_params_create(void)
+{
+  struct cmdline_parser_params *params = 
+    (struct cmdline_parser_params *)malloc(sizeof(struct 
cmdline_parser_params));
+  cmdline_parser_params_init(params);  
   return params;
 }
 
 static void
+free_string_field (char **s)
+{
+  if (*s)
+    {
+      free (*s);
+      *s = 0;
+    }
+}
+
+
+static void
 cmdline_parser_release (struct gengetopt_args_info *args_info)
 {
   
-  if (args_info->verbose_orig)
+  free_string_field (&(args_info->verbose_orig));
+  free_string_field (&(args_info->listen_arg));
+  free_string_field (&(args_info->listen_orig));
+  
+  
+
+  clear_given (args_info);
+}
+
+
+static void
+write_into_file(FILE *outfile, const char *opt, const char *arg, const char 
*values[])
+{
+  FIX_UNUSED (values);
+  if (arg) {
+    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
+  } else {
+    fprintf(outfile, "%s\n", opt);
+  }
+}
+
+
+int
+cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
+{
+  int i = 0;
+
+  if (!outfile)
     {
-      free (args_info->verbose_orig); /* free previous argument */
-      args_info->verbose_orig = 0;
+      fprintf (stderr, "%s: cannot dump options to stream\n", 
CMDLINE_PARSER_PACKAGE);
+      return EXIT_FAILURE;
     }
   
-  clear_given (args_info);
+  if (args_info->help_given)
+    write_into_file(outfile, "help", 0, 0 );
+  if (args_info->version_given)
+    write_into_file(outfile, "version", 0, 0 );
+  if (args_info->verbose_given)
+    write_into_file(outfile, "verbose", args_info->verbose_orig, 0);
+  if (args_info->listen_given)
+    write_into_file(outfile, "listen", args_info->listen_orig, 0);
+  
+
+  i = EXIT_SUCCESS;
+  return i;
 }
 
 int
@@ -146,23 +230,9 @@
       return EXIT_FAILURE;
     }
 
-  if (args_info->help_given) {
-    fprintf(outfile, "%s\n", "help");
-  }
-  if (args_info->version_given) {
-    fprintf(outfile, "%s\n", "version");
-  }
-  if (args_info->verbose_given) {
-    if (args_info->verbose_orig) {
-      fprintf(outfile, "%s=\"%s\"\n", "verbose", args_info->verbose_orig);
-    } else {
-      fprintf(outfile, "%s\n", "verbose");
-    }
-  }
-  
+  i = cmdline_parser_dump(outfile, args_info);
   fclose (outfile);
 
-  i = EXIT_SUCCESS;
   return i;
 }
 
@@ -172,13 +242,11 @@
   cmdline_parser_release (args_info);
 }
 
-
-/* gengetopt_strdup() */
-/* strdup.c replacement of strdup, which is not standard */
+/** @brief replacement of strdup, which is not standard */
 char *
 gengetopt_strdup (const char *s)
 {
-  char *result = NULL;
+  char *result = 0;
   if (!s)
     return result;
 
@@ -190,29 +258,23 @@
 }
 
 int
-cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info 
*args_info)
+cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
 {
   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
 }
 
 int
-cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info 
*args_info,
+cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info 
*args_info,
                    struct cmdline_parser_params *params)
 {
   int result;
-  result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
-
-  if (result == EXIT_FAILURE)
-    {
-      cmdline_parser_free (args_info);
-      exit (EXIT_FAILURE);
-    }
+  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
   
   return result;
 }
 
 int
-cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info 
*args_info, int override, int initialize, int check_required)
+cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, 
int override, int initialize, int check_required)
 {
   int result;
   struct cmdline_parser_params params;
@@ -221,14 +283,9 @@
   params.initialize = initialize;
   params.check_required = check_required;
   params.check_ambiguity = 0;
+  params.print_errors = 1;
 
-  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
-
-  if (result == EXIT_FAILURE)
-    {
-      cmdline_parser_free (args_info);
-      exit (EXIT_FAILURE);
-    }
+  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
   
   return result;
 }
@@ -236,6 +293,8 @@
 int
 cmdline_parser_required (struct gengetopt_args_info *args_info, const char 
*prog_name)
 {
+  FIX_UNUSED (args_info);
+  FIX_UNUSED (prog_name);
   return EXIT_SUCCESS;
 }
 
@@ -269,37 +328,6 @@
   int val;
 };
 
-/* For communication from `getopt' to the caller.
-   When `getopt' finds an option that takes an argument,
-   the argument value is returned here.
-   Also, when `ordering' is RETURN_IN_ORDER,
-   each non-option ARGV-element is returned here.  */
-
-static char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
-   This is used for communication to and from the caller
-   and for communication between successive calls to `getopt'.
-
-   On entry to `getopt', zero means this is the first call; initialize.
-
-   When `getopt' returns -1, this is the index of the first of the
-   non-option elements that the caller should itself scan.
-
-   Otherwise, `optind' communicates from one call to the next
-   how much of ARGV has been scanned so far.  */
-
-static int optind;
-
-/* Callers store zero here to inhibit the error message `getopt' prints
-   for unrecognized options.  */
-
-static int opterr;
-
-/* Set to an option character which was unrecognized.  */
-
-static int optopt;
-
 /* This version of `getopt' appears to the caller like standard Unix `getopt'
    but it behaves differently for the user, since it allows the user
    to intersperse the options with the other arguments.
@@ -681,7 +709,7 @@
                int print_errors, struct custom_getopt_data *d)
 {
        char c = *d->nextchar++;
-       char *temp = strchr(optstring, c);
+       const char *temp = strchr(optstring, c);
 
        /* Increment `custom_optind' when we start to process its last 
character.  */
        if (*d->nextchar == '\0')
@@ -862,13 +890,127 @@
                opt_index);
 }
 
+
+static char *package_name = 0;
+
+/**
+ * @brief updates an option
+ * @param field the generic pointer to the field to update
+ * @param orig_field the pointer to the orig field
+ * @param field_given the pointer to the number of occurrence of this option
+ * @param prev_given the pointer to the number of occurrence already seen
+ * @param value the argument for this option (if null no arg was specified)
+ * @param possible_values the possible values for this option (if specified)
+ * @param default_value the default value (in case the option only accepts 
fixed values)
+ * @param arg_type the type of this option
+ * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
+ * @param override @see cmdline_parser_params.override
+ * @param no_free whether to free a possible previous value
+ * @param multiple_option whether this is a multiple option
+ * @param long_opt the corresponding long option
+ * @param short_opt the corresponding short option (or '-' if none)
+ * @param additional_error possible further error specification
+ */
+static
+int update_arg(void *field, char **orig_field,
+               unsigned int *field_given, unsigned int *prev_given, 
+               char *value, const char *possible_values[],
+               const char *default_value,
+               cmdline_parser_arg_type arg_type,
+               int check_ambiguity, int override,
+               int no_free, int multiple_option,
+               const char *long_opt, char short_opt,
+               const char *additional_error)
+{
+  char *stop_char = 0;
+  const char *val = value;
+  int found;
+  char **string_field;
+  FIX_UNUSED (field);
+
+  stop_char = 0;
+  found = 0;
+
+  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && 
*field_given)))
+    {
+      if (short_opt != '-')
+        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
+               package_name, long_opt, short_opt,
+               (additional_error ? additional_error : ""));
+      else
+        fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
+               package_name, long_opt,
+               (additional_error ? additional_error : ""));
+      return 1; /* failure */
+    }
+
+  FIX_UNUSED (default_value);
+    
+  if (field_given && *field_given && ! override)
+    return 0;
+  if (prev_given)
+    (*prev_given)++;
+  if (field_given)
+    (*field_given)++;
+  if (possible_values)
+    val = possible_values[found];
+
+  switch(arg_type) {
+  case ARG_INT:
+    if (val) *((int *)field) = strtol (val, &stop_char, 0);
+    break;
+  case ARG_STRING:
+    if (val) {
+      string_field = (char **)field;
+      if (!no_free && *string_field)
+        free (*string_field); /* free previous string */
+      *string_field = gengetopt_strdup (val);
+    }
+    break;
+  default:
+    break;
+  };
+
+  /* check numeric conversion */
+  switch(arg_type) {
+  case ARG_INT:
+    if (val && !(stop_char && *stop_char == '\0')) {
+      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
+      return 1; /* failure */
+    }
+    break;
+  default:
+    ;
+  };
+
+  /* store the original value */
+  switch(arg_type) {
+  case ARG_NO:
+    break;
+  default:
+    if (value && orig_field) {
+      if (no_free) {
+        *orig_field = value;
+      } else {
+        if (*orig_field)
+          free (*orig_field); /* free previous string */
+        *orig_field = gengetopt_strdup (value);
+      }
+    }
+  };
+
+  return 0; /* OK */
+}
+
+
 int
-cmdline_parser_internal (int argc, char * const *argv, struct 
gengetopt_args_info *args_info,
+cmdline_parser_internal (
+  int argc, char **argv, struct gengetopt_args_info *args_info,
                         struct cmdline_parser_params *params, const char 
*additional_error)
 {
   int c;       /* Character of the parsed option.  */
 
-  int error = 0;
+  int error_occurred = 0;
   struct gengetopt_args_info local_args_info;
   
   int override;
@@ -876,6 +1018,13 @@
   int check_required;
   int check_ambiguity;
   
+  char *optarg;
+  int optind;
+  int opterr;
+  int optopt;
+  
+  package_name = argv[0];
+  
   override = params->override;
   initialize = params->initialize;
   check_required = params->check_required;
@@ -888,28 +1037,27 @@
 
   optarg = 0;
   optind = 0;
-  opterr = 1;
+  opterr = params->print_errors;
   optopt = '?';
 
   while (1)
     {
       int option_index = 0;
-      char *stop_char;
 
       static struct option long_options[] = {
         { "help",      0, NULL, 'h' },
         { "version",   0, NULL, 'V' },
         { "verbose",   1, NULL, 'v' },
-        { NULL,        0, NULL, 0 }
+        { "listen",    1, NULL, 'l' },
+        { 0,  0, 0, 0 }
       };
 
-      stop_char = 0;
       custom_optarg = optarg;
       custom_optind = optind;
       custom_opterr = opterr;
       custom_optopt = optopt;
 
-      c = custom_getopt_long (argc, argv, "hVv:", long_options, &option_index);
+      c = custom_getopt_long (argc, argv, "hVv:l:", long_options, 
&option_index);
 
       optarg = custom_optarg;
       optind = custom_optind;
@@ -930,27 +1078,34 @@
           cmdline_parser_free (&local_args_info);
           exit (EXIT_SUCCESS);
 
-        case 'v':      /* verbosity level\n 0 -> no output\n 1 -> small 
amount\n 2 -> show fed parse.  */
-          if (local_args_info.verbose_given || (check_ambiguity && 
args_info->verbose_given))
-            {
-              fprintf (stderr, "%s: `--verbose' (`-v') option given more than 
once%s\n", argv[0], (additional_error ? additional_error : ""));
-              goto failure;
-            }
-          if (args_info->verbose_given && ! override)
-            continue;
-          local_args_info.verbose_given = 1;
-          args_info->verbose_given = 1;
-          args_info->verbose_arg = strtol (optarg, &stop_char, 0);
-          if (!(stop_char && *stop_char == '\0')) {
-            fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], 
optarg);
+        case 'v':      /* verbosity level
+         0 -> no output
+         1 -> small amount
+         2 -> show fed parse.  */
+        
+        
+          if (update_arg( (void *)&(args_info->verbose_arg), 
+               &(args_info->verbose_orig), &(args_info->verbose_given),
+              &(local_args_info.verbose_given), optarg, 0, 0, ARG_INT,
+              check_ambiguity, override, 0, 0,
+              "verbose", 'v',
+              additional_error))
             goto failure;
-          }
-          if (args_info->verbose_orig)
-            free (args_info->verbose_orig); /* free previous string */
-          args_info->verbose_orig = gengetopt_strdup (optarg);
+        
           break;
+        case 'l':      /* listen only on specified IP address.  */
 
 
+          if (update_arg( (void *)&(args_info->listen_arg), 
+               &(args_info->listen_orig), &(args_info->listen_given),
+              &(local_args_info.listen_given), optarg, 0, 0, ARG_STRING,
+              check_ambiguity, override, 0, 0,
+              "listen", 'l',
+              additional_error))
+            goto failure;
+        
+          break;
+
         case 0:        /* Long option with no short option */
         case '?':      /* Invalid option.  */
           /* `getopt_long' already printed an error message.  */
@@ -967,7 +1122,7 @@
 
   cmdline_parser_release (&local_args_info);
 
-  if ( error )
+  if ( error_occurred )
     return (EXIT_FAILURE);
 
   return 0;

Index: RTIG/RTIG_cmdline.h
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG_cmdline.h,v
retrieving revision 3.1
retrieving revision 3.2
diff -u -b -r3.1 -r3.2
--- RTIG/RTIG_cmdline.h 30 Oct 2008 10:49:29 -0000      3.1
+++ RTIG/RTIG_cmdline.h 4 Sep 2013 07:56:41 -0000       3.2
@@ -1,6 +1,6 @@
 /** @file RTIG_cmdline.h
  *  @brief The header file for the command line option parser
- *  generated by GNU Gengetopt version 2.21
+ *  generated by GNU Gengetopt version 2.22.6
  *  http://www.gnu.org/software/gengetopt.
  *  DO NOT modify this file, since it can be overwritten
  *  @author GNU Gengetopt by Lorenzo Bettini */
@@ -13,15 +13,22 @@
 #include "config.h"
 #endif
 
+#include <stdio.h> /* for FILE */
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
 #ifndef CMDLINE_PARSER_PACKAGE
-/** @brief the program name */
+/** @brief the program name (used for printing errors) */
 #define CMDLINE_PARSER_PACKAGE "RTIG"
 #endif
 
+#ifndef CMDLINE_PARSER_PACKAGE_NAME
+/** @brief the complete program name (used for help and version) */
+#define CMDLINE_PARSER_PACKAGE_NAME "RTIG"
+#endif
+
 #ifndef CMDLINE_PARSER_VERSION
 /** @brief the program version */
 #define CMDLINE_PARSER_VERSION VERSION
@@ -32,13 +39,26 @@
 {
   const char *help_help; /**< @brief Print help and exit help description.  */
   const char *version_help; /**< @brief Print version and exit help 
description.  */
-  int verbose_arg;     /**< @brief verbosity level\n 0 -> no output\n 1 -> 
small amount\n 2 -> show fed parse.  */
-  char * verbose_orig; /**< @brief verbosity level\n 0 -> no output\n 1 -> 
small amount\n 2 -> show fed parse original value given at command line.  */
-  const char *verbose_help; /**< @brief verbosity level\n 0 -> no output\n 1 
-> small amount\n 2 -> show fed parse help description.  */
-  
-  int help_given ;     /**< @brief Whether help was given.  */
-  int version_given ;  /**< @brief Whether version was given.  */
-  int verbose_given ;  /**< @brief Whether verbose was given.  */
+  int verbose_arg;     /**< @brief verbosity level
+   0 -> no output
+   1 -> small amount
+   2 -> show fed parse.  */
+  char * verbose_orig; /**< @brief verbosity level
+   0 -> no output
+   1 -> small amount
+   2 -> show fed parse original value given at command line.  */
+  const char *verbose_help; /**< @brief verbosity level
+   0 -> no output
+   1 -> small amount
+   2 -> show fed parse help description.  */
+  char * listen_arg;   /**< @brief listen only on specified IP address.  */
+  char * listen_orig;  /**< @brief listen only on specified IP address 
original value given at command line.  */
+  const char *listen_help; /**< @brief listen only on specified IP address 
help description.  */
+  
+  unsigned int help_given ;    /**< @brief Whether help was given.  */
+  unsigned int version_given ; /**< @brief Whether version was given.  */
+  unsigned int verbose_given ; /**< @brief Whether verbose was given.  */
+  unsigned int listen_given ;  /**< @brief Whether listen was given.  */
 
 } ;
 
@@ -46,15 +66,18 @@
 struct cmdline_parser_params
 {
   int override; /**< @brief whether to override possibly already present 
options (default 0) */
-  int initialize; /**< @brief whether to initialize the option structure 
gengetopt_args_info (default 0) */
-  int check_required; /**< @brief whether to check that all required options 
were provided (default 0) */
+  int initialize; /**< @brief whether to initialize the option structure 
gengetopt_args_info (default 1) */
+  int check_required; /**< @brief whether to check that all required options 
were provided (default 1) */
   int check_ambiguity; /**< @brief whether to check for options already 
specified in the option structure gengetopt_args_info (default 0) */
+  int print_errors; /**< @brief whether getopt_long should print an error 
message for a bad option (default 1) */
 } ;
 
 /** @brief the purpose string of the program */
 extern const char *gengetopt_args_info_purpose;
 /** @brief the usage string of the program */
 extern const char *gengetopt_args_info_usage;
+/** @brief the description string of the program */
+extern const char *gengetopt_args_info_description;
 /** @brief all the lines making the help output */
 extern const char *gengetopt_args_info_help[];
 
@@ -65,7 +88,7 @@
  * @param args_info the structure where option information will be stored
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser (int argc, char * const *argv,
+int cmdline_parser (int argc, char **argv,
   struct gengetopt_args_info *args_info);
 
 /**
@@ -79,7 +102,7 @@
  * @return 0 if everything went fine, NON 0 if an error took place
  * @deprecated use cmdline_parser_ext() instead
  */
-int cmdline_parser2 (int argc, char * const *argv,
+int cmdline_parser2 (int argc, char **argv,
   struct gengetopt_args_info *args_info,
   int override, int initialize, int check_required);
 
@@ -91,11 +114,20 @@
  * @param params additional parameters for the parser
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser_ext (int argc, char * const *argv,
+int cmdline_parser_ext (int argc, char **argv,
   struct gengetopt_args_info *args_info,
   struct cmdline_parser_params *params);
 
 /**
+ * Save the contents of the option struct into an already open FILE stream.
+ * @param outfile the stream where to dump options
+ * @param args_info the option struct to dump
+ * @return 0 if everything went fine, NON 0 if an error took place
+ */
+int cmdline_parser_dump(FILE *outfile,
+  struct gengetopt_args_info *args_info);
+
+/**
  * Save the contents of the option struct into a (text) file.
  * This file can be read by the config file parser (if generated by gengetopt)
  * @param filename the file where to save
@@ -115,11 +147,18 @@
 void cmdline_parser_print_version(void);
 
 /**
+ * Initializes all the fields a cmdline_parser_params structure 
+ * to their default values
+ * @param params the structure to initialize
+ */
+void cmdline_parser_params_init(struct cmdline_parser_params *params);
+
+/**
  * Allocates dynamically a cmdline_parser_params structure and initializes
- * all its fields to 0
- * @return the initialized cmdline_parser_params structure
+ * all its fields to their default values
+ * @return the created and initialized cmdline_parser_params structure
  */
-struct cmdline_parser_params *cmdline_parser_params_init();
+struct cmdline_parser_params *cmdline_parser_params_create(void);
 
 /**
  * Initializes the passed gengetopt_args_info structure's fields

Index: RTIG/RTIG.hh
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.hh,v
retrieving revision 3.37
retrieving revision 3.38
diff -u -b -r3.37 -r3.38
--- RTIG/RTIG.hh        2 Oct 2010 13:20:37 -0000       3.37
+++ RTIG/RTIG.hh        4 Sep 2013 07:56:43 -0000       3.38
@@ -18,7 +18,7 @@
 // along with this program ; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// $Id: RTIG.hh,v 3.37 2010/10/02 13:20:37 erk Exp $
+// $Id: RTIG.hh,v 3.38 2013/09/04 07:56:43 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef CERTI_RTIG_HH
@@ -33,6 +33,8 @@
 #include "AuditFile.hh"
 #include "HandleManager.hh"
 
+#include <string>
+
 namespace certi {
 namespace rtig {
 
@@ -56,8 +58,8 @@
     static void signalHandler(int sig);
     static bool terminate ;
     void setVerboseLevel(int level) { verboseLevel = level ; 
federations.setVerboseLevel(level);}
-    void execute();
-
+    void setListeningIPAddress(const std::string& hostName) throw 
(NetworkError);
+    void execute() throw (NetworkError);
 
 private:
     // Both methods return the socket, because it may have been closed
@@ -129,6 +131,7 @@
     int tcpPort ;
     int udpPort ;
     int verboseLevel ;
+    in_addr_t listeningIPAddress;
     HandleManager<Handle> federationHandles ;
     SocketTCP tcpSocketServer ;
     SocketUDP udpSocketServer ;
@@ -145,4 +148,4 @@
 
 #endif // CERTI_RTIG_HH
 
-// $Id: RTIG.hh,v 3.37 2010/10/02 13:20:37 erk Exp $
+// $Id: RTIG.hh,v 3.38 2013/09/04 07:56:43 erk Exp $

Index: RTIG/main.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/main.cc,v
retrieving revision 3.22
retrieving revision 3.23
diff -u -b -r3.22 -r3.23
--- RTIG/main.cc        21 Oct 2009 20:04:46 -0000      3.22
+++ RTIG/main.cc        4 Sep 2013 07:56:47 -0000       3.23
@@ -66,7 +66,7 @@
  * one rtig process for each federation. However a single RTIG may
  * be used for several federations.
  * The command line usage of the RTIG is following:
- * \par rtig [-v 2]
+ * \par rtig [-v 2] [-l @IP|hostname]
  * \par
  * <ul>
  *   <li> \b -v  (optional) verbosity level </li>
@@ -75,6 +75,7 @@
  *          <li> 1 -> small amount </li>
  *          <li> 2 -> show fed parse </li>
  *   </ul>
+ *   <li> \b -l  (optional) listening @IP address</li>
  * </ul>
  *
  * Once the RTIG is launched an HLA Federate may interact with the RTI.
@@ -129,7 +130,15 @@
        std::set_new_handler(NewHandler);
 
        myRTIG.setVerboseLevel(verboseLevel);
+    // if a listening IP has been specified then use it
+    if (args.listen_given) {
+        myRTIG.setListeningIPAddress(args.listen_arg);
+    }
+    try {
        myRTIG.execute();
+    } catch (NetworkError& e) {
+        std::cerr << "CERTI RTIG aborted with a Network Error: [" << e._reason 
<< "]." <<std::endl;
+    }
 
        if (verboseLevel>0) {
                cout << "CERTI RTIG exiting." << endl ;

Index: libCERTI/Socket.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Socket.hh,v
retrieving revision 3.20
retrieving revision 3.21
diff -u -b -r3.20 -r3.21
--- libCERTI/Socket.hh  18 Dec 2011 15:25:43 -0000      3.20
+++ libCERTI/Socket.hh  4 Sep 2013 07:56:52 -0000       3.21
@@ -39,6 +39,8 @@
 typedef int SOCKET;
 #endif
 
+#include <cstring>
+#include <cerrno>
 #include <string>
 #include <sstream>
 
@@ -66,7 +68,7 @@
                virtual SOCKET returnSocket() = 0;
 
        /**
-        * This function build a string which represents
+     * This function builds a string which represents
         * the provided IPv4 address as a "w.x.y.z".
         * @param[in] addr, the IPv4 address
         * @return the string "w.x.y.z"
@@ -86,6 +88,25 @@
                    << "." << static_cast<int>(uaddr.parts[0]);
                return msg.str();
        }
+
+    /**
+     * This function builds an IP address out of an hostname.
+     */
+    static in_addr_t host2addr(const std::string& hostName) throw 
(NetworkError) {
+        in_addr_t retaddr=0;
+        // get host information from server name
+        // this may perform DNS query
+        struct hostent *hptr = gethostbyname(hostName.c_str());
+        // FIXME we should probably use getaddrinfo instead
+        if (NULL == hptr) {
+            throw NetworkError(stringize()
+                    << "gethostbyname gave NULL answer for hostname <"
+                    << hostName
+                    << "> with error <" << strerror(errno) << ">");
+        }
+        memcpy((void *) &retaddr, (void *) hptr->h_addr, hptr->h_length);
+        return retaddr;
+    }
 };
 
 } // namespace certi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]