Skip to content

Commit

Permalink
Fix linux compilation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Jul 7, 2021
1 parent 5d718e9 commit 59b12ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
*.swp
*.gor
*.rpm
Expand Down
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 2 additions & 14 deletions capture/af_packet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package capture

import (
"flag"
"fmt"
"time"

Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 59b12ab

Please sign in to comment.