Skip to content

Commit

Permalink
Add windows support (#940)
Browse files Browse the repository at this point in the history
For a long time there were no official binaries for the windows platform.
One of the reasons is the complexities of the build toolchain. Not only CGO is required, but also installing the needed libraries and header files, not talking about mingw and etc.

2 weeks ago [golang-crossbuild](https://github.com/elastic/golang-crossbuild) project added native support for Libpcap based applications.
Windows support is based on the WinPcap which is a bit (a lot) outdated, BUT, since we depend only on its interface, it is still possible to use projects like npcap https://nmap.org/npcap/#download.

Npcap needs be installed with WinPcap compatibe mode (checkbox during installation)
It is also possibe install it in silent mode like this: `npcap-0.86.exe /S /winpcap_mode=yes`

After PR merge, will be updated related documentation.

Additionally fix dependency on "unix" package (apparently it can be totally replaced using universal syscall package)
  • Loading branch information
buger committed Jun 9, 2021
1 parent b0f62de commit 9782d49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.rpm
*.dep
*.pkg
*.exe

*.out

Expand Down
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FPMCOMMON= \
-s dir \
-C /tmp/gor-build \

release: release-x64 release-mac
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)
Expand Down Expand Up @@ -58,11 +58,25 @@ release-mac:
fpm $(FPMCOMMON) -a amd64 -t osxpkg ./=/usr/local/bin
rm -rf /tmp/gor-build

release-windows:
echo $(pwd)
docker run -it --rm \
-v `pwd`:/go/src/github.com/buger/goreplay \
-w /go/src/github.com/buger/goreplay \
-e CGO_ENABLED=1 \
docker.elastic.co/beats-dev/golang-crossbuild:1.16.4-main \
--build-cmd "VERSION=make build" \
-p "windows/amd64"

mv ./gor ./gor-$(VERSION)$(PREFIX).exe

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

install:
go install $(MAC_LDFLAGS)

build:
build-env:
docker build -t $(CONTAINER) -f Dockerfile.dev .

profile:
Expand Down
4 changes: 2 additions & 2 deletions capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"runtime"
"strings"
"sync"
"syscall"
"time"

"github.com/buger/goreplay/size"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"golang.org/x/sys/unix"
)

// PacketHandler is a function that is used to handle packets
Expand Down Expand Up @@ -334,7 +334,7 @@ func (l *Listener) read(handler PacketHandler) {
if enext, ok := err.(pcap.NextError); ok && enext == pcap.NextErrorTimeoutExpired {
continue
}
if eno, ok := err.(unix.Errno); ok && eno.Temporary() {
if eno, ok := err.(syscall.Errno); ok && eno.Temporary() {
continue
}
if enet, ok := err.(*net.OpError); ok && (enet.Temporary() || enet.Timeout()) {
Expand Down

0 comments on commit 9782d49

Please sign in to comment.