Skip to content

Commit

Permalink
Fix MacOS builds
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Jun 29, 2021
1 parent ad43405 commit f701dac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 61 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ FPMCOMMON= \
release: release-x64 release-mac release-windows

release-bin:
docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -o $(BIN_NAME) -tags netgo $(LDFLAGS)
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)

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 -o $(BIN_NAME) -tags netgo $(LDFLAGS)
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)
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 +44,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 -o $(BIN_NAME) -tags netgo $(LDFLAGS)
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)
tar -czf gor_$(VERSION)$(PREFIX)_x86.tar.gz $(BIN_NAME)
rm $(BIN_NAME)

release-mac:
go build -o $(BIN_NAME) $(MAC_LDFLAGS)
go build -mod=mod -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 +71,7 @@ release-windows:
rm -rf ./gor.exe

build:
go build -o $(BIN_NAME) $(LDFLAGS)
go build -mod=mod -o $(BIN_NAME) $(LDFLAGS)

install:
go install $(MAC_LDFLAGS)
Expand Down
2 changes: 2 additions & 0 deletions capture/af_packet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !linux

package capture

import (
Expand Down
56 changes: 0 additions & 56 deletions capture/af_packet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,59 +128,3 @@ func afpacketComputeSize(targetSizeMb int, snaplen int, pageSize int) (

return frameSize, blockSize, numBlocks, nil
}

func main() {
flag.Parse()
if *cpuprofile != "" {
log.Printf("Writing CPU profile to %q", *cpuprofile)
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal(err)
}
defer pprof.StopCPUProfile()
}
log.Printf("Starting on interface %q", *iface)
if *snaplen <= 0 {
*snaplen = 65535
}

err = afpacketHandle.SetBPFFilter(*filter, *snaplen)
if err != nil {
log.Fatal(err)
}
source := gopacket.ZeroCopyPacketDataSource(afpacketHandle)
defer afpacketHandle.Close()

bytes := uint64(0)
packets := uint64(0)
for ; *count != 0; *count-- {
data, _, err := source.ZeroCopyReadPacketData()
if err != nil {
log.Fatal(err)
}
bytes += uint64(len(data))
packets++
if *count%*verbose == 0 {
_, afpacketStats, err := afpacketHandle.SocketStats()
if err != nil {
log.Println(err)
}
log.Printf("Read in %d bytes in %d packets", bytes, packets)
log.Printf("Stats {received dropped queue-freeze}: %d", afpacketStats)
}
}
}

func (l *Listener) PcapHandle(ifi pcap.Interface) (handle *pcap.Handle, err error) {

szFrame, szBlock, numBlocks, err := afpacketComputeSize(*bufferSize, *snaplen, os.Getpagesize())
if err != nil {
log.Fatal(err)
}
handle, err = newAfpacketHandle(*ifi, szFrame, szBlock, numBlocks, *addVLAN, pcap.BlockForever)

return afpacketHandle
}

0 comments on commit f701dac

Please sign in to comment.