Skip to content

Commit

Permalink
added ttl logging to pcap2mgen
Browse files Browse the repository at this point in the history
  • Loading branch information
bebopagogo committed Oct 4, 2020
1 parent 13cb297 commit 5a9fc94
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/mgenMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class MgenMsg
bool logGpsFata,
UINT32* alignedMsgBuffer,
bool flush,
int ttl, // will be >= 0 when known
const struct timeval& theTime);
bool LogSendEvent(FILE* logFile,
bool logBinary,
Expand Down
6 changes: 5 additions & 1 deletion src/common/mgenMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ bool MgenMsg::LogRecvEvent(FILE* logFile,
bool logGpsData,
UINT32* alignedMsgBuffer,
bool flush,
int ttl, // will be >= 0 when known
const struct timeval& theTime)
{

Expand Down Expand Up @@ -1047,6 +1048,9 @@ bool MgenMsg::LogRecvEvent(FILE* logFile,
{
Mgen::Log(logFile, "host>%s/%hu ", host_addr.GetHostString(), host_addr.GetPort());
}

if (ttl >= 0)
Mgen::Log(logFile, "ttl>%d ", ttl);

// (TBD) only output GPS info if INVALID_GPS != gps_status
const char* statusString = NULL;
Expand Down Expand Up @@ -1589,7 +1593,7 @@ bool MgenMsg::ConvertBinaryLog(const char* path, Mgen& mgen)
msg.SetTxTime(eventTime);
ASSERT(0 == index%4)
msg.Unpack(alignedBuffer+index/4, recordLength - index, false, log_data);
msg.LogRecvEvent(logFile, false, localTime, log_rx, log_data, log_gps_data, NULL, log_flush,eventTime);
msg.LogRecvEvent(logFile, false, localTime, log_rx, log_data, log_gps_data, NULL, -1, log_flush,eventTime);
break;
}
case SEND_EVENT:
Expand Down
1 change: 1 addition & 0 deletions src/common/mgenTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ void MgenTransport::LogEvent(LogEventType eventType, MgenMsg* theMsg, const stru
mgen.GetLogGpsData(),
buffer,
mgen.GetLogFlush(),
-1,
theTime);

// Don't we want rapr to get the message regardless of logging??
Expand Down
14 changes: 13 additions & 1 deletion src/common/pcap2mgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ FILE* outfile = stdout;
bool trace = false;
bool log_rx = true;

bool flush = false;


const char* const CMD_LIST[] =
{
Expand All @@ -43,6 +45,7 @@ const char* const CMD_LIST[] =
"+outfile", // Name of output file
"-trace", // Prepends MGEN log lines with epoch time and MAC src/addr info
"+rxlog", // Turns on/off recv log info. For report messages only
"-flush", // flush writes to outfile
"+window" // Sets analytic window
};

Expand Down Expand Up @@ -149,6 +152,10 @@ bool OnCommand(const char* cmd, const char* val)
{
trace = true;
}
else if (!strncmp("flush", lowerCmd, len))
{
flush = true;
}
else if (!strncmp("rxlog", lowerCmd, len))
{
// std::cout << "lowerCmd = " << lowerCmd << std::endl;
Expand Down Expand Up @@ -336,6 +343,7 @@ int main(int argc, char* argv[])
}
ProtoPktIP ipPkt;
ProtoAddress srcAddr, dstAddr;
int ttl = -1;
ProtoPktETH::Type ethType = ethPkt.GetType();
if ((ProtoPktETH::IP == ethType) ||
(ProtoPktETH::IPv6 == ethType))
Expand All @@ -353,13 +361,15 @@ int main(int argc, char* argv[])
ProtoPktIPv4 ip4Pkt(ipPkt);
ip4Pkt.GetDstAddr(dstAddr);
ip4Pkt.GetSrcAddr(srcAddr);
ttl = ip4Pkt.GetTTL();
break;
}
case 6:
{
ProtoPktIPv6 ip6Pkt(ipPkt);
ip6Pkt.GetDstAddr(dstAddr);
ip6Pkt.GetSrcAddr(srcAddr);
ttl = ip6Pkt.GetHopLimit();
break;
}
default:
Expand All @@ -373,6 +383,8 @@ int main(int argc, char* argv[])
}
if (!srcAddr.IsValid()) continue; // wasn't an IP packet



ProtoPktUDP udpPkt;
if (!udpPkt.InitFromPacket(ipPkt)) continue; // not a UDP packet

Expand Down Expand Up @@ -429,7 +441,7 @@ int main(int argc, char* argv[])
}

// Should we make "flush" true by default?
msg.LogRecvEvent(outfile, false, false, log_rx, false, true, (UINT32*)udpPkt.AccessPayload(), false, hdr.ts);
msg.LogRecvEvent(outfile, false, false, log_rx, false, true, (UINT32*)udpPkt.AccessPayload(), flush, ttl, hdr.ts);
} // end while (pcap_next())

if (stdin != infile) fclose(infile);
Expand Down

0 comments on commit 5a9fc94

Please sign in to comment.