Skip to content

Commit

Permalink
fix: seq_no & udp_port zero omit
Browse files Browse the repository at this point in the history
 and  not omitted if zero
  • Loading branch information
arghyadipchak committed Dec 16, 2024
1 parent 4205d19 commit d8e5238
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/meta/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type RttSample struct {
SendTime float64 `json:"send_time"`
RecvTime float64 `json:"recv_time"`
RTT float64 `json:"rtt"`
IcmpSeqNo int `json:"icmp_seq_no,omitempty"`
UdpDestPort int `json:"udp_dest_port,omitempty"`
IcmpSeqNo *int `json:"icmp_seq_no,omitempty"`
UdpDestPort *int `json:"udp_dest_port,omitempty"`
}

type Measurements struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/ping/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func handleEchoReply(replyIP net.IP, recvTime time.Time, msg *icmp.Message) {
SendTime: timeUtil.UnixPrecise(reqTime),
RecvTime: timeUtil.UnixPrecise(recvTime),
RTT: rtt,
IcmpSeqNo: pktNo,
IcmpSeqNo: &pktNo,
}

if directHopIP == nil && i == config.DirectHop {
Expand Down Expand Up @@ -129,7 +129,7 @@ func lostLoggerICMP(i int) (total, dropped int) {
TTL: ttl,
Round: r + 1,
SendTime: timeUtil.UnixPrecise(value.(time.Time)),
IcmpSeqNo: pktNo,
IcmpSeqNo: &pktNo,
}
dropped += 1
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func PingProcess() {
TTL: config.DirectHop,
Round: 0,
ReplyIP: net.ParseIP("0.0.0.0"),
IcmpSeqNo: 0,
IcmpSeqNo: new(int),
}
} else {
total, dropped = lostLoggerICMP(0)
Expand Down
5 changes: 3 additions & 2 deletions internal/ping/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func handleTimeExceededUDP(replyIP net.IP, recvTime time.Time, msg *icmp.Message
SendTime: timeUtil.UnixPrecise(reqTime),
RecvTime: timeUtil.UnixPrecise(recvTime),
RTT: rtt,
UdpDestPort: dstPort,
UdpDestPort: &dstPort,
}

if i == config.DirectHop && directHopIP == nil {
Expand Down Expand Up @@ -109,11 +109,12 @@ func lostLoggerUDP(i int) (total, dropped int) {
total += 1

if _, ok := meta.MSamples[pktNo]; !ok {
udpPort := startingPort + pktNo
meta.MSamples[pktNo] = meta.RttSample{
TTL: ttl,
Round: r + 1,
SendTime: timeUtil.UnixPrecise(value.(time.Time)),
UdpDestPort: startingPort + pktNo,
UdpDestPort: &udpPort,
}
dropped += 1
}
Expand Down

0 comments on commit d8e5238

Please sign in to comment.