This commit is contained in:
esrrhs committed 2018-12-21 15:52:34 +08:00
1 parent e7fecd4e1c
commit 75edf4c3c1
3 files changed
+31 -7

No files matched your search

+10 -2
View File
@@ -3,6 +3,8 @@ package pingtunnel
import (
"fmt"
"golang.org/x/net/icmp"
"math"
"math/rand"
"net"
"time"
)
@@ -19,7 +21,10 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
return nil, err
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return &Client{
id: r.Intn(math.MaxInt16),
r: r,
ipaddr: ipaddr,
addr: addr,
ipaddrServer: ipaddrServer,
@@ -32,6 +37,9 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
}
type Client struct {
id int
r *rand.Rand
timeout int
sproto int
rproto int
@@ -156,7 +164,7 @@ func (p *Client) Accept() error {
}
clientConn.activeTime = now
sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(DATA), bytes[:n], p.sproto, p.rproto)
sendICMP(p.id, p.r.Intn(math.MaxInt16), *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(DATA), bytes[:n], p.sproto, p.rproto)
p.sendPacket++
p.sendPacketSize += (uint64)(n)
@@ -229,7 +237,7 @@ func (p *Client) ping() {
if p.sendPacket == 0 && p.recvPacket == 0 {
now := time.Now()
b, _ := now.MarshalBinary()
sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
sendICMP(p.id, p.r.Intn(math.MaxInt16), *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto)
}
}