修改原版代码中strlcpy最大8个字节的限制, "enp175s0f0"这种网卡名被截断的BUG.

This commit is contained in:
lijia
2019-07-12 14:50:30 +08:00
parent f36a4fca25
commit 408d23b286
3 changed files with 47 additions and 43 deletions

13
configure vendored
View File

@@ -2965,8 +2965,9 @@ _ACEOF
USER_CFLAGS=$CFLAGS USER_CFLAGS=$CFLAGS
#CFLAGS="${CFLAGS} -Wall -O3 -std=gnu99" #CFLAGS="${CFLAGS} -Wall -O3 -std=gnu99"
CFLAGS="${CFLAGS} -Wall -g -O3 -std=gnu99 -DTCPBURST=1" #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 -DMARSIO=1"
LIBS="-lmarsio $LIBS"
# Make sure we can run config.sub. # Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || $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 $as_echo_n "(cached) " >&6
else else
ac_check_lib_save_LIBS=$LIBS ac_check_lib_save_LIBS=$LIBS
LIBS="-lnsl $LIBS" LIBS="-lnsl $LIBS -lpthread"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@@ -16614,7 +16615,7 @@ if test "x$ac_cv_lib_nsl_gethostbyname" = xyes; then :
#define HAVE_LIBNSL 1 #define HAVE_LIBNSL 1
_ACEOF _ACEOF
LIBS="-lnsl $LIBS" LIBS="-lnsl $LIBS -lpthread"
fi fi
@@ -16624,7 +16625,7 @@ if ${ac_cv_lib_rt_nanosleep+:} false; then :
$as_echo_n "(cached) " >&6 $as_echo_n "(cached) " >&6
else else
ac_check_lib_save_LIBS=$LIBS ac_check_lib_save_LIBS=$LIBS
LIBS="-lrt $LIBS" LIBS="-lrt $LIBS -lpthread"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@@ -16659,7 +16660,7 @@ if test "x$ac_cv_lib_rt_nanosleep" = xyes; then :
#define HAVE_LIBRT 1 #define HAVE_LIBRT 1
_ACEOF _ACEOF
LIBS="-lrt $LIBS" LIBS="-lrt $LIBS -lpthread"
fi fi

View File

@@ -73,7 +73,8 @@ get_interface(interface_list_t *list, const char *alias)
} while (ptr != NULL); } while (ptr != NULL);
} else { } else {
name = (char *)safe_malloc(strlen(alias) + 1); 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); return(name);
} }

View File

@@ -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 */); tcpburst_marsio4_vdev = marsio_open_device(tcpburst_marsio4_instance, marsio_send_device, 0/* rx_stream */, 1 /* tx_stream */);
if(NULL == tcpburst_marsio4_vdev) { 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); exit(1);
} }
@@ -1799,14 +1799,15 @@ replay_file(int file_idx)
#endif #endif
if (pcap != NULL) { if(1 == send_pkt_driver_mode){
dlt = sendpacket_get_dlt(options.intf1); if (pcap != NULL) {
if ((dlt > 0) && (dlt != pcap_datalink(pcap))) dlt = sendpacket_get_dlt(options.intf1);
warnx("%s DLT (%s) does not match that of the outbound interface: %s (%s)", if ((dlt > 0) && (dlt != pcap_datalink(pcap)))
path, pcap_datalink_val_to_name(pcap_datalink(pcap)), warnx("%s DLT (%s) does not match that of the outbound interface: %s (%s)",
options.intf1->device, pcap_datalink_val_to_name(dlt)); path, pcap_datalink_val_to_name(pcap_datalink(pcap)),
} options.intf1->device, pcap_datalink_val_to_name(dlt));
}
}
send_packets(pcap, file_idx); send_packets(pcap, file_idx);
if (pcap != NULL) if (pcap != NULL)
pcap_close(pcap); pcap_close(pcap);
@@ -2026,41 +2027,42 @@ post_args(void)
if (HAVE_OPT(PKTLEN)) if (HAVE_OPT(PKTLEN))
warn("--pktlen may cause problems. Use with caution."); warn("--pktlen may cause problems. Use with caution.");
if ((intname = get_interface(intlist, OPT_ARG(INTF1))) == NULL) if(1 == send_pkt_driver_mode){
errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); 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 */ /* open interfaces for writing */
if ((options.intf1 = sendpacket_open(options.intf1_name, ebuf, TCPR_DIR_C2S)) == NULL) if ((options.intf1 = sendpacket_open(options.intf1_name, ebuf, TCPR_DIR_C2S)) == NULL)
errx(-1, "Can't open %s: %s", options.intf1_name, ebuf); 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 (HAVE_OPT(INTF2)) {
if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL)
errx(-1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); 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 */ /* open interface for writing */
if ((options.intf2 = sendpacket_open(options.intf2_name, ebuf, TCPR_DIR_S2C)) == NULL) if ((options.intf2 = sendpacket_open(options.intf2_name, ebuf, TCPR_DIR_S2C)) == NULL)
errx(-1, "Can't open %s: %s", options.intf2_name, ebuf); errx(-1, "Can't open %s: %s", options.intf2_name, ebuf);
int2dlt = sendpacket_get_dlt(options.intf2); int2dlt = sendpacket_get_dlt(options.intf2);
if (int2dlt != int1dlt) if (int2dlt != int1dlt)
errx(-1, "DLT type missmatch for %s (%s) and %s (%s)", errx(-1, "DLT type missmatch for %s (%s) and %s (%s)",
options.intf1_name, pcap_datalink_val_to_name(int1dlt), options.intf1_name, pcap_datalink_val_to_name(int1dlt),
options.intf2_name, pcap_datalink_val_to_name(int2dlt)); 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(CACHEFILE)) {
temp = safe_strdup(OPT_ARG(CACHEFILE));
options.cache_packets = read_cache(&options.cachedata, temp,
&options.comment);
safe_free(temp);
}
}
if (! HAVE_OPT(QUIET)) if (! HAVE_OPT(QUIET))
notice("sending out %s %s", options.intf1_name, notice("sending out %s %s", options.intf1_name,
options.intf2_name == NULL ? "" : options.intf2_name); options.intf2_name == NULL ? "" : options.intf2_name);