diff --git a/README.md b/README.md index 7e1005f..4da6c22 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,12 @@ For the moment you'll have to install go and compile `sclient` yourself: ```bash git clone https://git.coolaj86.com/coolaj86/sclient.go.git pushd sclient.go -go build -o dist/sclient sclient*.go +go build -o dist/sclient cmd/sclient/main.go rsync -av dist/sclient /usr/local/bin/sclient ``` ```bash -go run sclient*.go example.com:443 localhost:3000 +go run cmd/sclient/main.go example.com:443 localhost:3000 ``` Usage diff --git a/build-all.sh b/build-all.sh index 3bf3632..a94845a 100644 --- a/build-all.sh +++ b/build-all.sh @@ -1,29 +1,31 @@ #GOOS=windows GOARCH=amd64 go install go tool dist list +gocmd=cmd/sclient/main.go +golib="" echo "" echo "" echo "Windows amd64" -GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe sclient*.go +GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe $gocmd $golib echo "Windows 386" -GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe sclient*.go +GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe $gocmd $golib echo "" echo "Darwin (macOS) amd64" -GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient sclient*.go +GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient $gocmd $golib echo "" echo "Linux amd64" -GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient sclient*.go +GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient $gocmd $golib echo "Linux 386" echo "" -GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient sclient*.go +GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient $gocmd $golib echo "RPi 3 B+ ARMv7" -GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient sclient*.go +GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient $gocmd $golib echo "RPi Zero ARMv5" -GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient sclient*.go +GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient $gocmd $golib echo "" echo "" diff --git a/sclient-cli.go b/cmd/sclient/main.go similarity index 92% rename from sclient-cli.go rename to cmd/sclient/main.go index 0e0eef4..ce58ce2 100644 --- a/sclient-cli.go +++ b/cmd/sclient/main.go @@ -6,10 +6,12 @@ import ( "os" "strconv" "strings" + + sclient "git.coolaj86.com/sclient.go" ) func usage() { - fmt.Fprintf(os.Stderr, "\nusage: go run sclient*.go \n"+ + fmt.Fprintf(os.Stderr, "\nusage: sclient \n"+ "\n"+ " ex: sclient example.com 3000\n"+ " (sclient example.com:443 localhost:3000)\n"+ @@ -39,7 +41,7 @@ func main() { } } - opts := &SclientOpts{} + opts := &sclient.PipeOpts{} opts.RemotePort = 443 opts.LocalAddress = "localhost" opts.InsecureSkipVerify = *insecure @@ -85,7 +87,7 @@ func main() { } } - sclient := &Sclient{} + sclient := &sclient.Tun{} err := sclient.DialAndListen(opts) if nil != err { fmt.Fprintf(os.Stderr, "%s\n", err) diff --git a/sclient.go b/sclient.go index a4ef49f..49ed4cf 100644 --- a/sclient.go +++ b/sclient.go @@ -1,4 +1,4 @@ -package main +package sclient import ( "crypto/tls" @@ -40,7 +40,7 @@ type Rwc interface { RemoteAddr() net.Addr } -type SclientOpts struct { +type PipeOpts struct { RemoteAddress string RemotePort int LocalAddress string @@ -48,7 +48,7 @@ type SclientOpts struct { InsecureSkipVerify bool } -type Sclient struct{} +type Tun struct{} func pipe(r Rwc, w Rwc, t string) { buffer := make([]byte, 2048) @@ -86,7 +86,7 @@ func pipe(r Rwc, w Rwc, t string) { } } -func handleConnection(remote string, conn Rwc, opts *SclientOpts) { +func handleConnection(remote string, conn Rwc, opts *PipeOpts) { sclient, err := tls.Dial("tcp", remote, &tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify}) @@ -108,7 +108,7 @@ func handleConnection(remote string, conn Rwc, opts *SclientOpts) { pipe(sclient, conn, "remote") } -func (*Sclient) DialAndListen(opts *SclientOpts) error { +func (*Tun) DialAndListen(opts *PipeOpts) error { remote := opts.RemoteAddress + ":" + strconv.Itoa(opts.RemotePort) conn, err := tls.Dial("tcp", remote, &tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify})