Add DNS support to pcap (#100)

* begin adding dns pcap functionality

* improve question formatting

* work on capturing answers as well

* finalize DNS printing

* increase subfield limits

* add FlagContainer type

* prettier DNS printing
This commit is contained in:
Pat Whittingslow
2026-04-24 19:41:10 -03:00
committed by GitHub
parent b2c3d11c4c
commit 198db3789b
8 changed files with 401 additions and 23 deletions
+3 -1
View File
@@ -6,6 +6,8 @@ import (
"github.com/soypat/lneto"
)
//go:generate stringer -type=Type,CodeDestinationUnreachable,CodeRedirect -linecomment -output stringers.go
const (
sizeHeader = 8
)
@@ -33,7 +35,7 @@ const (
type CodeTimeExceeded uint8
const (
CodeExceededInTransit CodeTimeExceeded = iota // TTL exceeded in transit
CodeExceededInTransit CodeTimeExceeded = iota // TTL exceeded
CodeFragmentReassembly // fragment reassembly time exceeded
)
+93
View File
@@ -0,0 +1,93 @@
// Code generated by "stringer -type=Type,CodeDestinationUnreachable,CodeRedirect -linecomment -output stringers.go"; DO NOT EDIT.
package icmpv4
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[TypeEchoReply-0]
_ = x[TypeEcho-8]
_ = x[TypeDestinationUnreachable-3]
_ = x[TypeSourceQuench-4]
_ = x[TypeRedirect-5]
_ = x[TypeTimeExceeded-11]
_ = x[TypeParameterProblem-12]
_ = x[TypeTimestamp-13]
_ = x[TypeTimestampReply-14]
_ = x[TypeInfoRequest-15]
_ = x[TypeInfoRequestReply-16]
}
const (
_Type_name_0 = "echo reply"
_Type_name_1 = "destination unreachablesource quenchredirect"
_Type_name_2 = "echo"
_Type_name_3 = "time exceededparameter problemtimestamptimestamp replyinformation requestinformation request reply"
)
var (
_Type_index_1 = [...]uint8{0, 23, 36, 44}
_Type_index_3 = [...]uint8{0, 13, 30, 39, 54, 73, 98}
)
func (i Type) String() string {
switch {
case i == 0:
return _Type_name_0
case 3 <= i && i <= 5:
i -= 3
return _Type_name_1[_Type_index_1[i]:_Type_index_1[i+1]]
case i == 8:
return _Type_name_2
case 11 <= i && i <= 16:
i -= 11
return _Type_name_3[_Type_index_3[i]:_Type_index_3[i+1]]
default:
return "Type(" + strconv.FormatInt(int64(i), 10) + ")"
}
}
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[CodeNetUnreachable-0]
_ = x[CodeHostUnreachable-1]
_ = x[CodeProtoUnreachable-2]
_ = x[CodePortUnreachable-3]
_ = x[CodeFragNeededAndDFSet-4]
_ = x[CodeSourceRouteFailed-5]
}
const _CodeDestinationUnreachable_name = "net unreachablehost unreachableprotocol unreachableport unreachablefragmentation needed and DF setsource route failed"
var _CodeDestinationUnreachable_index = [...]uint8{0, 15, 31, 51, 67, 98, 117}
func (i CodeDestinationUnreachable) String() string {
if i >= CodeDestinationUnreachable(len(_CodeDestinationUnreachable_index)-1) {
return "CodeDestinationUnreachable(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _CodeDestinationUnreachable_name[_CodeDestinationUnreachable_index[i]:_CodeDestinationUnreachable_index[i+1]]
}
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[CodeRedirectForNetwork-0]
_ = x[CodeRedirectForHost-1]
_ = x[CodeRedirectForToSAndNetwork-2]
_ = x[CodeRedirectToSAndHost-3]
}
const _CodeRedirect_name = "redirect for networkredirect for hostredirect for ToS+networkredirect for ToS+host"
var _CodeRedirect_index = [...]uint8{0, 20, 37, 61, 82}
func (i CodeRedirect) String() string {
if i >= CodeRedirect(len(_CodeRedirect_index)-1) {
return "CodeRedirect(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _CodeRedirect_name[_CodeRedirect_index[i]:_CodeRedirect_index[i+1]]
}