diff options
| author | 李佳 <[email protected]> | 2019-07-12 14:52:15 +0800 |
|---|---|---|
| committer | 李佳 <[email protected]> | 2019-07-12 14:52:15 +0800 |
| commit | bb59225c16a6b128f54b6e4bde20c18e1d832812 (patch) | |
| tree | 79c6df9253a91bccbd431ef920a84462d280ee13 | |
| parent | f36a4fca258fc0a725352cfc744037634a08b076 (diff) | |
| parent | 408d23b2860f2d6984bd27106ef296e82520b204 (diff) | |
Merge branch 'bug_fix_strlcpy' into 'master'
修改原版代码中strlcpy最大8个字节的限制, "enp175s0f0"这种网卡名被截断的BUG.
See merge request common_tools/tcp_burst!1
| -rw-r--r-- | configure | 13 | ||||
| -rw-r--r-- | src/common/interface.c | 3 | ||||
| -rw-r--r-- | src/tcpreplay.c | 74 |
3 files changed, 47 insertions, 43 deletions
@@ -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)); - - options.intf1_name = safe_strdup(intname); + 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)); - /* 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); + options.intf1_name = safe_strdup(intname); - int1dlt = sendpacket_get_dlt(options.intf1); + /* 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); - if (HAVE_OPT(INTF2)) { - if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) - errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); + int1dlt = sendpacket_get_dlt(options.intf1); - options.intf2_name = safe_strdup(intname); + if (HAVE_OPT(INTF2)) { + if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) + errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); - /* 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); + options.intf2_name = safe_strdup(intname); - 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)); - } + /* 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); - 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); |
