These changes use glib2 command line option parsing in pinger. The notion of multiple -d options I could not duplicate so -d now takes a arg of 0 through 5 as the debug value to use.
With these changes pinger builds on both linux & windows.
# HG changeset patch # User Roger Massey <[email protected]> # Date 1363993362 21600 # Node ID 830d138cb854690216d4c8fe0e64ea585338cfe9 # Parent 2196db3eb8c03e917d1f0eeed919d4ba5caa9ffb Changes to pinger to use glib command line processing. Allows windows and linux to use the same code. diff -r 2196db3eb8c0 -r 830d138cb854 clientlib/compressframe.c --- a/clientlib/compressframe.c Thu Mar 21 13:14:49 2013 -0600 +++ b/clientlib/compressframe.c Fri Mar 22 17:02:42 2013 -0600 @@ -78,7 +78,7 @@ /// return the corresponding Frame /// In other words, un-marshall the data... /// @todo: Not yet implemented. -Frame* +WINEXPORT Frame* compressframe_tlvconstructor(gconstpointer tlvstart, ///<[in] Start of marshalled CStringFrame data gconstpointer pktend) ///<[in] Pointer to first invalid byte past 'tlvstart' { diff -r 2196db3eb8c0 -r 830d138cb854 clientlib/cryptframe.c --- a/clientlib/cryptframe.c Thu Mar 21 13:14:49 2013 -0600 +++ b/clientlib/cryptframe.c Fri Mar 22 17:02:42 2013 -0600 @@ -84,7 +84,7 @@ /// Given marshalled packet data corresponding to an CryptFrame (C-style string), /// return the corresponding Frame /// In other words, un-marshall the data... -Frame* +WINEXPORT Frame* cryptframe_tlvconstructor(gconstpointer tlvstart, ///<[in] Start of marshalled CStringFrame data gconstpointer pktend) ///<[in] Pointer to first invalid byte past 'tlvstart' { diff -r 2196db3eb8c0 -r 830d138cb854 clientlib/nvpairframe.c --- a/clientlib/nvpairframe.c Thu Mar 21 13:14:49 2013 -0600 +++ b/clientlib/nvpairframe.c Fri Mar 22 17:02:42 2013 -0600 @@ -127,7 +127,7 @@ /// Given marshalled packet data corresponding to an NVpairFrame (name/value pair) /// return the corresponding Frame /// In other words, un-marshall the data... -Frame* +WINEXPORT Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart, ///<[in] Start of marshalled CStringFrame data gconstpointer pktend) ///<[in] Pointer to first invalid byte past 'tlvstart' { diff -r 2196db3eb8c0 -r 830d138cb854 include/compressframe.h --- a/include/compressframe.h Thu Mar 21 13:14:49 2013 -0600 +++ b/include/compressframe.h Fri Mar 22 17:02:42 2013 -0600 @@ -37,7 +37,7 @@ }; CompressFrame* compressframe_new(guint16 frame_type, guint16 compression_method); -Frame* compressframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); +WINEXPORT Frame* compressframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); ///@} diff -r 2196db3eb8c0 -r 830d138cb854 include/cryptframe.h --- a/include/cryptframe.h Thu Mar 21 13:14:49 2013 -0600 +++ b/include/cryptframe.h Fri Mar 22 17:02:42 2013 -0600 @@ -38,7 +38,7 @@ }; CryptFrame* cryptframe_new(guint16 frame_type, guint16 encryption_method, void* encryption_info); -Frame* cryptframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); +WINEXPORT Frame* cryptframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); ///@} diff -r 2196db3eb8c0 -r 830d138cb854 include/nvpairframe.h --- a/include/nvpairframe.h Thu Mar 21 13:14:49 2013 -0600 +++ b/include/nvpairframe.h Fri Mar 22 17:02:42 2013 -0600 @@ -38,7 +38,7 @@ }; NVpairFrame* nvpairframe_new(guint16 frame_type, gchar* name, gchar* value, gsize framesize); -Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); +WINEXPORT Frame* nvpairframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend); ///@} diff -r 2196db3eb8c0 -r 830d138cb854 testcode/CMakeLists.txt --- a/testcode/CMakeLists.txt Thu Mar 21 13:14:49 2013 -0600 +++ b/testcode/CMakeLists.txt Fri Mar 22 17:02:42 2013 -0600 @@ -29,10 +29,10 @@ target_link_libraries(filetest ${CLIENTLIB} ${SERVERLIB} ${PCAP_LIB} ${GLIB_LIB}) target_link_libraries(mainlooptest ${CLIENTLIB} ${SERVERLIB} ${PCAP_LIB} ${GLIB_LIB}) - + target_link_libraries(pinger ${GLIB_LIB} ../clientlib/${CMAKE_BUILD_TYPE}/${CLIENTLIB}) ELSE(WIN32) target_link_libraries (filetest ${CLIENTLIB} ${SERVERLIB} -lpcap -lrt) target_link_libraries (mainlooptest ${CLIENTLIB} ${SERVERLIB} -lpcap -lrt) - target_link_libraries (pinger ${CLIENTLIB} ${SERVERLIB}) + target_link_libraries (pinger ${CLIENTLIB} ${GLIB_LIB}) ENDIF(WIN32) diff -r 2196db3eb8c0 -r 830d138cb854 testcode/pinger.c --- a/testcode/pinger.c Thu Mar 21 13:14:49 2013 -0600 +++ b/testcode/pinger.c Fri Mar 22 17:02:42 2013 -0600 @@ -24,7 +24,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#ifdef RHM #include <getopt.h> +#endif #include <netaddr.h> #include <frametypes.h> #include <reliableudp.h> @@ -139,7 +141,7 @@ Frame* frame = CASTTOCLASS(Frame, slframe->data); if (frame->type == FRAMETYPE_CINTVAL) { IntFrame* cntframe = CASTTOCLASS(IntFrame, frame); - gint theirnextcount = cntframe->getint(cntframe); + gint theirnextcount = (gint)cntframe->getint(cntframe); foundcount = TRUE; if (theirlastcount_p != NULL) { gint theirlastcount = GPOINTER_TO_INT(theirlastcount_p); @@ -201,16 +203,16 @@ }else{ cmd = cmdname; } - fprintf(stderr, "usage: %s [-d] [-c count ] ip-address1 [ip-address ...]", cmd); - fprintf(stderr, " -c count-of-ping-packets"); - fprintf(stderr, " -d increment debug [can be repeated for more debug]"); + fprintf(stderr, "usage: %s [-d debug-level] [-c count ] ip-address1 [ip-address ...]\n", cmd); + fprintf(stderr, " -c count-of-ping-packets\n"); + fprintf(stderr, " -d debug-level [0-5]\n"); exit(1); } int main(int argc, char **argv) { - int j; +// int j; FrameTypeToFrame decodeframes[] = FRAMETYPEMAP; PacketDecoder* decoder = packetdecoder_new(0, decodeframes, DIMOF(decodeframes)); SignFrame* signature = signframe_new(G_CHECKSUM_SHA256, 0); @@ -220,18 +222,41 @@ NetGSource* netpkt; AuthListener* act_on_packets; int liveobjcount; - gboolean optionerror = FALSE; - gboolean moreopts = TRUE; - int option_index = 0; - int c; +// gboolean optionerror = FALSE; +// gboolean moreopts = TRUE; +// int option_index = 0; +// int c; - static struct option long_options[] = { - {"count", required_argument, 0, 'c'}, - {"debug", no_argument, 0, 'd'}, + //static struct option long_options[] = { + // {"count", required_argument, 0, 'c'}, + // {"debug", no_argument, 0, 'd'}, + //}; + static int mycount = 0; + static int mydebug = 0; + static gchar **optremaining = NULL; + gchar *ipaddr = NULL; + static GOptionEntry long_options [] = { + {"count", 'c', 0, G_OPTION_ARG_INT, &mycount, "count of ping packets", NULL}, + {"debug", 'd', 0, G_OPTION_ARG_INT, &mydebug, "debug-level [0-5]", NULL}, + {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &optremaining, "ip_address [ip_address ...]", NULL}, + {NULL} }; + GError *optionerror; + GOptionContext *myOptionContext; + + myOptionContext = g_option_context_new(" ip_address [ip_address...]"); + g_option_context_add_main_entries(myOptionContext, long_options, NULL); g_setenv("G_MESSAGES_DEBUG", "all", TRUE); - g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL); + g_log_set_fatal_mask(NULL, (int) G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL); + + if(!(g_option_context_parse(myOptionContext, &argc, &argv, &optionerror))) { + g_print("option parsing failed %s\n", optionerror->message); + usage(argv[0]); + exit(1); + } + +#ifdef RHM while (moreopts) { c = getopt_long(argc, argv, "c:d", long_options, &option_index); switch(c) { @@ -265,6 +290,23 @@ usage(argv[0]); exit(1); } +#endif + + g_option_context_free(myOptionContext); + if((mycount != 0) && (mycount > 0)) { // an upper limit as well ? + maxpingcount = mycount; + } + if(mydebug > 0) { + if(mydebug > 5) mydebug = 5; + while(mydebug--) { + proj_class_incr_debug(NULL); + } + } + if(optremaining == NULL) { + usage(argv[0]); + exit(1); + } + // use -- to end option scanning theircounts = g_hash_table_new(netaddr_g_hash_hash, netaddr_g_hash_equal); ourcounts = g_hash_table_new(netaddr_g_hash_hash, netaddr_g_hash_equal); @@ -289,21 +331,22 @@ loop = g_main_loop_new(g_main_context_default(), TRUE); // Kick everything off with a pingy-dingy - for (j=optind; j < argc; ++j) { + for(ipaddr = *optremaining; ; ipaddr++) { +// for (j=optind; j < argc; ++j) { FrameSet* ping; NetAddr* toaddr; NetAddr* v6addr; IntFrame* iframe = intframe_new(FRAMETYPE_CINTVAL, 1); - if (strcmp(argv[j], "::") == 0) { + if (strcmp(ipaddr, "::") == 0) { fprintf(stderr, "WARNING: %s is not a valid ipv4/v6 address for our purposes.\n" - , argv[j]); + , ipaddr); continue; } - toaddr = netaddr_string_new(argv[j]); + toaddr = netaddr_string_new(ipaddr); if (toaddr == NULL) { fprintf(stderr, "WARNING: %s is not a valid ipv4/v6 address.\n" - , argv[j]); + , ipaddr); continue; } v6addr = toaddr->toIPv6(toaddr); UNREF(toaddr);
_______________________________________________ Assimilation mailing list - Discovery-Driven Monitoring [email protected] http://lists.community.tummy.com/cgi-bin/mailman/listinfo/assimilation http://assimmon.org/
