From 59b12abbe1c834a964f9a8d20b7287227a03ce8c Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Wed, 7 Jul 2021 19:33:49 +0300 Subject: [PATCH] Fix linux compilation issue --- .gitignore | 1 + Makefile | 15 +++++++++------ capture/af_packet_linux.go | 16 ++-------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index b03350b5..b976a8d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +vendor *.swp *.gor *.rpm diff --git a/Makefile b/Makefile index aa99e890..3450857e 100644 --- a/Makefile +++ b/Makefile @@ -23,16 +23,19 @@ FPMCOMMON= \ -s dir \ -C /tmp/gor-build \ -release: release-x64 release-mac release-windows +release: vendor release-x64 release-mac release-windows + +vendor: + go mod vendor release-bin: - docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -mod=mod -o $(BIN_NAME) -tags netgo $(LDFLAGS) + docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) release-bin-mac: GOOS=darwin go build -o $(BIN_NAME) $(MAC_LDFLAGS) release-x64: - docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -mod=mod -o $(BIN_NAME) -tags netgo $(LDFLAGS) + docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) tar -czf gor_$(VERSION)$(PREFIX)_x64.tar.gz $(BIN_NAME) mkdir -p /tmp/gor-build mv ./$(BIN_NAME) /tmp/gor-build/$(BIN_NAME) @@ -44,12 +47,12 @@ release-x64: rm -rf /tmp/gor-build release-x86: - docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=386 -i $(CONTAINER) go build -mod=mod -o $(BIN_NAME) -tags netgo $(LDFLAGS) + docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=386 -i $(CONTAINER) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) tar -czf gor_$(VERSION)$(PREFIX)_x86.tar.gz $(BIN_NAME) rm $(BIN_NAME) release-mac: - go build -mod=mod -o $(BIN_NAME) $(MAC_LDFLAGS) + go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) tar -czf gor_$(VERSION)$(PREFIX)_mac.tar.gz $(BIN_NAME) mkdir -p /tmp/gor-build mv ./$(BIN_NAME) /tmp/gor-build/$(BIN_NAME) @@ -71,7 +74,7 @@ release-windows: rm -rf ./gor.exe build: - go build -mod=mod -o $(BIN_NAME) $(LDFLAGS) + go build -mod=vendor -o $(BIN_NAME) $(LDFLAGS) install: go install $(MAC_LDFLAGS) diff --git a/capture/af_packet_linux.go b/capture/af_packet_linux.go index 53debc8a..cbf7d646 100644 --- a/capture/af_packet_linux.go +++ b/capture/af_packet_linux.go @@ -3,7 +3,6 @@ package capture import ( - "flag" "fmt" "time" @@ -16,17 +15,6 @@ import ( _ "github.com/google/gopacket/layers" ) -var ( - iface = flag.String("i", "any", "Interface to read from") - cpuprofile = flag.String("cpuprofile", "", "If non-empty, write CPU profile here") - snaplen = flag.Int("s", 0, "Snaplen, if <= 0, use 65535") - bufferSize = flag.Int("b", 8, "Interface buffersize (MB)") - filter = flag.String("f", "port not 22", "BPF filter") - count = flag.Int64("c", -1, "If >= 0, # of packets to capture before returning") - verbose = flag.Int64("log_every", 1, "Write a log every X packets") - addVLAN = flag.Bool("add_vlan", false, "If true, add VLAN header") -) - type afpacketHandle struct { TPacket *afpacket.TPacket } @@ -42,7 +30,7 @@ func newAfpacketHandle(device string, snaplen int, block_size int, num_blocks in afpacket.OptFrameSize(snaplen), afpacket.OptBlockSize(block_size), afpacket.OptNumBlocks(num_blocks), - afpacket.OptAddVLANHeader(useVLAN), + afpacket.OptAddVLANHeader(false), afpacket.OptPollTimeout(timeout), afpacket.SocketRaw, afpacket.TPacketVersion3) @@ -52,7 +40,7 @@ func newAfpacketHandle(device string, snaplen int, block_size int, num_blocks in afpacket.OptFrameSize(snaplen), afpacket.OptBlockSize(block_size), afpacket.OptNumBlocks(num_blocks), - afpacket.OptAddVLANHeader(useVLAN), + afpacket.OptAddVLANHeader(false), afpacket.OptPollTimeout(timeout), afpacket.SocketRaw, afpacket.TPacketVersion3)