Add a pcap-split tool

This commit is contained in:
2026-10-05 20:16:01 +02:00
parent 5b5cf211d0
commit c11c893845
13 changed files with 769 additions and 22 deletions
+12 -3
View File
@@ -22,21 +22,28 @@ type Tool struct {
var tools = []Tool{
{Name: "Hex → pcap", Path: "/hex2pcap", Description: "Build a pcap file from hex-encoded layer 2, layer 3 and payload bytes, optionally fixing IP lengths and checksums."},
{Name: "Split pcap", Path: "/split", Description: "Split a pcap file into several files by packet count or file size, downloaded as a zip."},
}
// Config holds server settings.
type Config struct {
MaxUploadBytes int64 // largest accepted file upload
}
// Server is the HTTP handler for the whole application.
type Server struct {
cfg Config
mux *http.ServeMux
pages map[string]*template.Template
}
// New parses the templates and sets up the routes.
func New() (*Server, error) {
s := &Server{mux: http.NewServeMux(), pages: map[string]*template.Template{}}
func New(cfg Config) (*Server, error) {
s := &Server{cfg: cfg, mux: http.NewServeMux(), pages: map[string]*template.Template{}}
// Each page is parsed together with the shared layout so pages can define
// their own "title" and "content" blocks.
for _, page := range []string{"index.html", "hex2pcap.html"} {
for _, page := range []string{"index.html", "hex2pcap.html", "split.html"} {
t, err := template.New(page).ParseFS(assets, "templates/layout.html", "templates/"+page)
if err != nil {
return nil, err
@@ -52,6 +59,8 @@ func New() (*Server, error) {
s.mux.HandleFunc("GET /{$}", s.handleIndex)
s.mux.HandleFunc("GET /hex2pcap", s.handleHex2PcapForm)
s.mux.HandleFunc("POST /hex2pcap", s.handleHex2Pcap)
s.mux.HandleFunc("GET /split", s.handleSplitForm)
s.mux.HandleFunc("POST /split", s.handleSplit)
return s, nil
}