From 408d23b2860f2d6984bd27106ef296e82520b204 Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 12 Jul 2019 14:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8E=9F=E7=89=88=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=ADstrlcpy=E6=9C=80=E5=A4=A78=E4=B8=AA=E5=AD=97?= =?UTF-8?q?=E8=8A=82=E7=9A=84=E9=99=90=E5=88=B6,=20"enp175s0f0"=E8=BF=99?= =?UTF-8?q?=E7=A7=8D=E7=BD=91=E5=8D=A1=E5=90=8D=E8=A2=AB=E6=88=AA=E6=96=AD?= =?UTF-8?q?=E7=9A=84BUG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configure | 13 ++++---- src/common/interface.c | 3 +- src/tcpreplay.c | 74 ++++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/configure b/configure index a221f74..9468afa 100644 --- a/configure +++ b/configure @@ -2965,8 +2965,9 @@ _ACEOF USER_CFLAGS=$CFLAGS #CFLAGS="${CFLAGS} -Wall -O3 -std=gnu99" -CFLAGS="${CFLAGS} -Wall -g -O3 -std=gnu99 -DTCPBURST=1" -#CFLAGS="${CFLAGS} -Wall -g -O3 -std=gnu99 -DTCPBURST=1 -DMARSIO=1" +#CFLAGS="${CFLAGS} -Wall -g -O3 -std=gnu99 -DTCPBURST=1" +CFLAGS="${CFLAGS} -Wall -g -O3 -std=gnu99 -DTCPBURST=1 -DMARSIO=1" +LIBS="-lmarsio $LIBS" # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || @@ -16579,7 +16580,7 @@ if ${ac_cv_lib_nsl_gethostbyname+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-lnsl $LIBS" +LIBS="-lnsl $LIBS -lpthread" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16614,7 +16615,7 @@ if test "x$ac_cv_lib_nsl_gethostbyname" = xyes; then : #define HAVE_LIBNSL 1 _ACEOF - LIBS="-lnsl $LIBS" + LIBS="-lnsl $LIBS -lpthread" fi @@ -16624,7 +16625,7 @@ if ${ac_cv_lib_rt_nanosleep+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-lrt $LIBS" +LIBS="-lrt $LIBS -lpthread" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16659,7 +16660,7 @@ if test "x$ac_cv_lib_rt_nanosleep" = xyes; then : #define HAVE_LIBRT 1 _ACEOF - LIBS="-lrt $LIBS" + LIBS="-lrt $LIBS -lpthread" fi diff --git a/src/common/interface.c b/src/common/interface.c index d267117..ccbc71f 100644 --- a/src/common/interface.c +++ b/src/common/interface.c @@ -73,7 +73,8 @@ get_interface(interface_list_t *list, const char *alias) } while (ptr != NULL); } else { name = (char *)safe_malloc(strlen(alias) + 1); - strlcpy(name, alias, sizeof(name)); + memset(name, 0, strlen(alias) + 1); + strncpy(name, alias, strlen(alias) + 1); return(name); } diff --git a/src/tcpreplay.c b/src/tcpreplay.c index de57242..aa02786 100644 --- a/src/tcpreplay.c +++ b/src/tcpreplay.c @@ -1097,7 +1097,7 @@ int stream_burst_marsio_init(void) tcpburst_marsio4_vdev = marsio_open_device(tcpburst_marsio4_instance, marsio_send_device, 0/* rx_stream */, 1 /* tx_stream */); if(NULL == tcpburst_marsio4_vdev) { - fprintf(stderr,"%s\n","marsio_open_device() error!\n"); + fprintf(stderr,"%s\n","marsio_open_device %s error!\n", marsio_send_device); exit(1); } @@ -1799,14 +1799,15 @@ replay_file(int file_idx) #endif - if (pcap != NULL) { - dlt = sendpacket_get_dlt(options.intf1); - if ((dlt > 0) && (dlt != pcap_datalink(pcap))) - warnx("%s DLT (%s) does not match that of the outbound interface: %s (%s)", - path, pcap_datalink_val_to_name(pcap_datalink(pcap)), - options.intf1->device, pcap_datalink_val_to_name(dlt)); - } - + if(1 == send_pkt_driver_mode){ + if (pcap != NULL) { + dlt = sendpacket_get_dlt(options.intf1); + if ((dlt > 0) && (dlt != pcap_datalink(pcap))) + warnx("%s DLT (%s) does not match that of the outbound interface: %s (%s)", + path, pcap_datalink_val_to_name(pcap_datalink(pcap)), + options.intf1->device, pcap_datalink_val_to_name(dlt)); + } + } send_packets(pcap, file_idx); if (pcap != NULL) pcap_close(pcap); @@ -2026,41 +2027,42 @@ post_args(void) if (HAVE_OPT(PKTLEN)) warn("--pktlen may cause problems. Use with caution."); - if ((intname = get_interface(intlist, OPT_ARG(INTF1))) == NULL) - errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); + if(1 == send_pkt_driver_mode){ + if ((intname = get_interface(intlist, OPT_ARG(INTF1))) == NULL) + errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); - options.intf1_name = safe_strdup(intname); + options.intf1_name = safe_strdup(intname); - /* open interfaces for writing */ - if ((options.intf1 = sendpacket_open(options.intf1_name, ebuf, TCPR_DIR_C2S)) == NULL) - errx(-1, "Can't open %s: %s", options.intf1_name, ebuf); + /* open interfaces for writing */ + if ((options.intf1 = sendpacket_open(options.intf1_name, ebuf, TCPR_DIR_C2S)) == NULL) + errx(-1, "Can't open %s: %s", options.intf1_name, ebuf); - int1dlt = sendpacket_get_dlt(options.intf1); + int1dlt = sendpacket_get_dlt(options.intf1); - if (HAVE_OPT(INTF2)) { - if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) - errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); + if (HAVE_OPT(INTF2)) { + if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) + errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); - options.intf2_name = safe_strdup(intname); + options.intf2_name = safe_strdup(intname); - /* open interface for writing */ - if ((options.intf2 = sendpacket_open(options.intf2_name, ebuf, TCPR_DIR_S2C)) == NULL) - errx(-1, "Can't open %s: %s", options.intf2_name, ebuf); + /* open interface for writing */ + if ((options.intf2 = sendpacket_open(options.intf2_name, ebuf, TCPR_DIR_S2C)) == NULL) + errx(-1, "Can't open %s: %s", options.intf2_name, ebuf); - int2dlt = sendpacket_get_dlt(options.intf2); - if (int2dlt != int1dlt) - errx(-1, "DLT type missmatch for %s (%s) and %s (%s)", - options.intf1_name, pcap_datalink_val_to_name(int1dlt), - options.intf2_name, pcap_datalink_val_to_name(int2dlt)); - } - - if (HAVE_OPT(CACHEFILE)) { - temp = safe_strdup(OPT_ARG(CACHEFILE)); - options.cache_packets = read_cache(&options.cachedata, temp, - &options.comment); - safe_free(temp); - } + int2dlt = sendpacket_get_dlt(options.intf2); + if (int2dlt != int1dlt) + errx(-1, "DLT type missmatch for %s (%s) and %s (%s)", + options.intf1_name, pcap_datalink_val_to_name(int1dlt), + options.intf2_name, pcap_datalink_val_to_name(int2dlt)); + } + if (HAVE_OPT(CACHEFILE)) { + temp = safe_strdup(OPT_ARG(CACHEFILE)); + options.cache_packets = read_cache(&options.cachedata, temp, + &options.comment); + safe_free(temp); + } + } if (! HAVE_OPT(QUIET)) notice("sending out %s %s", options.intf1_name, options.intf2_name == NULL ? "" : options.intf2_name);