mirror of
https://github.com/soypat/lneto.git
synced 2026-08-25 08:59:05 +00:00
add dhcp failing test
This commit is contained in:
+2
-22
@@ -5,11 +5,9 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -87,26 +85,8 @@ func run() error {
|
||||
return err
|
||||
}
|
||||
fmt.Println("listening on http://127.0.0.1:7070/recv and http://127.0.0.1:7070/send on hwaddr:", net.HardwareAddr(hwaddr[:]).String())
|
||||
go http.ListenAndServe(":7070", sv)
|
||||
const standbyDuration = 5 * time.Second
|
||||
lastHit := time.Now().Add(-standbyDuration)
|
||||
for {
|
||||
result, err := sv.HandleTap()
|
||||
if err != nil {
|
||||
slog.Error("handletap:error", slog.String("err", err.Error()), slog.Any("result", result))
|
||||
}
|
||||
if result.Failed {
|
||||
return errors.New("tap failed, exit program")
|
||||
} else if result.ReceivedSize == 0 && result.SentSize == 0 {
|
||||
if time.Since(lastHit) > standbyDuration {
|
||||
time.Sleep(5 * time.Millisecond) // Enter standby.
|
||||
} else {
|
||||
runtime.Gosched()
|
||||
}
|
||||
} else {
|
||||
lastHit = time.Now()
|
||||
}
|
||||
}
|
||||
http.ListenAndServe(":7070", sv)
|
||||
return errors.New("finished")
|
||||
}
|
||||
|
||||
func getTCPData(frames []pcap.Frame, pkt []byte) (flags tcp.Flags, src, dst uint16) {
|
||||
|
||||
Reference in New Issue
Block a user