Skip to content

Commit b89bb75

Browse files
authored
Report whether or not the TTL value was read (#205)
In IPv6 a hop limit of 0 is valid, so the TTL the code is reporting is actually a valid value in that case. Initialize ttl to -1, so that in the case of not getting a TTL value from the control message, we can let the rest of the code whether the reported value was actually 0 or whether it couldn't be read. Signed-off-by: Marcelo E. Magallon <[email protected]>
1 parent 6d40342 commit b89bb75

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packetconn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *icmpv4Conn) SetFlagTTL() error {
6565
}
6666

6767
func (c *icmpv4Conn) ReadFrom(b []byte) (int, int, net.Addr, error) {
68-
var ttl int
68+
ttl := -1
6969
n, cm, src, err := c.c.IPv4PacketConn().ReadFrom(b)
7070
if cm != nil {
7171
ttl = cm.TTL
@@ -90,7 +90,7 @@ func (c *icmpV6Conn) SetFlagTTL() error {
9090
}
9191

9292
func (c *icmpV6Conn) ReadFrom(b []byte) (int, int, net.Addr, error) {
93-
var ttl int
93+
ttl := -1
9494
n, cm, src, err := c.c.IPv6PacketConn().ReadFrom(b)
9595
if cm != nil {
9696
ttl = cm.HopLimit

0 commit comments

Comments
 (0)