mirror of
https://github.com/soypat/lneto.git
synced 2026-08-20 06:29:03 +00:00
Fix slow exchanges on linux by adding polling and other improvements (#14)
* add prints to investigate slowness * add loop sleep for blocking Stack * add connection close http attribute and detect end of HTML page * add timeout to bridge read * examples/xnet: add ntp timestamp to prints and show output in readme * add polling to http tap interface * more digits in ntp format * prevent crashes on non-8 timestamp
This commit is contained in:
@@ -671,6 +671,7 @@ const (
|
||||
// FieldClassBinaryText represents long stretches of binary data such as BOOTP DHCPv4 field.
|
||||
FieldClassBinaryText // binary-text
|
||||
FieldClassOperation // op
|
||||
FieldClassTimestamp // timestamp
|
||||
)
|
||||
|
||||
const octet = 8
|
||||
@@ -1058,25 +1059,25 @@ var baseNTPFields = [...]FrameField{
|
||||
},
|
||||
{
|
||||
Name: "Reference Time",
|
||||
Class: FieldClassText,
|
||||
Class: FieldClassTimestamp,
|
||||
FrameBitOffset: 16 * octet,
|
||||
BitLength: 8 * octet,
|
||||
},
|
||||
{
|
||||
Name: "Origin Time",
|
||||
Class: FieldClassText,
|
||||
Class: FieldClassTimestamp,
|
||||
FrameBitOffset: 24 * octet,
|
||||
BitLength: 8 * octet,
|
||||
},
|
||||
{
|
||||
Name: "Receive Time",
|
||||
Class: FieldClassText,
|
||||
Class: FieldClassTimestamp,
|
||||
FrameBitOffset: 32 * octet,
|
||||
BitLength: 8 * octet,
|
||||
},
|
||||
{
|
||||
Name: "Transit Time",
|
||||
Class: FieldClassText,
|
||||
Class: FieldClassTimestamp,
|
||||
FrameBitOffset: 40 * octet,
|
||||
BitLength: 8 * octet,
|
||||
},
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package pcap
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
_ "time"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/ethernet"
|
||||
"github.com/soypat/lneto/ntp"
|
||||
"github.com/soypat/lneto/tcp"
|
||||
)
|
||||
|
||||
@@ -106,6 +110,14 @@ func (f *Formatter) formatField(dst []byte, pktStartOff int, field FrameField, p
|
||||
switch field.Class {
|
||||
default:
|
||||
fallthrough
|
||||
case FieldClassTimestamp:
|
||||
// inspired by [time.RFC3339]
|
||||
const littlerfc3339 = "2006-01-02T15:04:05.9999"
|
||||
if len(f.buf) != 8 {
|
||||
return dst, errors.New("only timestamp8 supported")
|
||||
}
|
||||
ts := ntp.TimestampFromUint64(binary.BigEndian.Uint64(f.buf))
|
||||
dst = ts.Time().AppendFormat(dst, littlerfc3339)
|
||||
case FieldClassChecksum, FieldClassID, FieldClassFlags, FieldClassOptions:
|
||||
// Binary data to be printed as hexadecimal.
|
||||
dst = append(dst, "0x"...)
|
||||
|
||||
Reference in New Issue
Block a user