File: tunnel.go

package info (click to toggle)
golang-github-containers-gvisor-tap-vsocks 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 800 kB
  • sloc: sh: 95; makefile: 59
file content (28 lines) | stat: -rw-r--r-- 481 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package transport

import (
	"errors"
	"fmt"
	"io"
	"net"
	"net/http"
)

func Tunnel(conn net.Conn, ip string, port int) error {
	req, err := http.NewRequest("POST", fmt.Sprintf("/tunnel?ip=%s&port=%d", ip, port), nil)
	if err != nil {
		return err
	}
	if err := req.Write(conn); err != nil {
		return err
	}

	ok := make([]byte, 2)
	if _, err := io.ReadFull(conn, ok); err != nil {
		return err
	}
	if string(ok) != "OK" {
		return errors.New("handshake failed")
	}
	return nil
}