Corrected the MS/TP capture to limit data to the input buffer.
This commit is contained in:
@@ -190,6 +190,7 @@ static void write_received_packet(
|
||||
uint32_t orig_len; /* actual length of packet */
|
||||
uint8_t header[8]; /* MS/TP header */
|
||||
struct timeval tv;
|
||||
size_t max_data;
|
||||
|
||||
if (pFile) {
|
||||
gettimeofday(&tv, NULL);
|
||||
@@ -214,7 +215,8 @@ static void write_received_packet(
|
||||
header[7] = mstp_port->HeaderCRCActual;
|
||||
fwrite(header, sizeof(header), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
fwrite(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile);
|
||||
max_data = min(mstp_port->InputBufferSize,mstp_port->DataLength);
|
||||
fwrite(mstp_port->InputBuffer, max_data, 1, pFile);
|
||||
fwrite((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile);
|
||||
fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,8 @@ static void snap_received_packet(
|
||||
{
|
||||
uint16_t mtu_len = 0; /* number of octets of packet saved in file */
|
||||
unsigned i = 0; /* counter */
|
||||
static uint8_t mtu[1500] = { 0 };
|
||||
static uint8_t mtu[1500] = { 0 };
|
||||
size_t max_data = 0;
|
||||
|
||||
mtu[0] = 0;
|
||||
mtu[1] = 0;
|
||||
@@ -198,13 +199,14 @@ static void snap_received_packet(
|
||||
mtu[29] = LO_BYTE(mstp_port->DataLength);
|
||||
mtu[30] = mstp_port->HeaderCRCActual;
|
||||
mtu_len = 31;
|
||||
if (mstp_port->DataLength) {
|
||||
for (i = 0; i < mstp_port->DataLength; i++) {
|
||||
if (mstp_port->DataLength) {
|
||||
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
|
||||
for (i = 0; i < max_data; i++) {
|
||||
mtu[31 + i] = mstp_port->InputBuffer[i];
|
||||
}
|
||||
mtu[31 + mstp_port->DataLength] = mstp_port->DataCRCActualMSB;
|
||||
mtu[31 + mstp_port->DataLength + 1] = mstp_port->DataCRCActualLSB;
|
||||
mtu_len += (mstp_port->DataLength + 2);
|
||||
mtu[31 + max_data] = mstp_port->DataCRCActualMSB;
|
||||
mtu[31 + max_data + 1] = mstp_port->DataCRCActualLSB;
|
||||
mtu_len += (max_data + 2);
|
||||
}
|
||||
/* Ethernet length is data only - not address or length bytes */
|
||||
encode_unsigned16(&mtu[12], mtu_len - 14);
|
||||
|
||||
@@ -209,7 +209,8 @@ static void write_received_packet(
|
||||
header[7] = mstp_port->HeaderCRCActual;
|
||||
fwrite(header, sizeof(header), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
fwrite(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile);
|
||||
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
|
||||
fwrite(mstp_port->InputBuffer, max_data, 1, pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualMSB), 1, 1, pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualLSB), 1, 1, pFile);
|
||||
}
|
||||
@@ -253,7 +254,8 @@ static void print_received_packet(
|
||||
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
|
||||
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
|
||||
if (mstp_port->DataLength) {
|
||||
for (i = 0; i < mstp_port->DataLength; i++) {
|
||||
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
|
||||
for (i = 0; i < max_data; i++) {
|
||||
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
|
||||
}
|
||||
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
|
||||
|
||||
@@ -156,7 +156,8 @@ static void print_received_packet(
|
||||
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
|
||||
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
|
||||
if (mstp_port->DataLength) {
|
||||
for (i = 0; i < mstp_port->DataLength; i++) {
|
||||
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
|
||||
for (i = 0; i < max_data; i++) {
|
||||
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
|
||||
}
|
||||
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
|
||||
|
||||
Reference in New Issue
Block a user