1
0
mirror of https://github.com/taigrr/go-fastping synced 2025-01-18 05:03:15 -08:00

Remove packet struct

The recv channel isn't used anymore so it doesn't need to pack received
packet bytes and a remote address into a packet struct.

This removes packet struct, fixes procRecv arguments and so on.
This commit is contained in:
Tatsushi Demachi 2015-10-25 14:47:07 +09:00
parent d7610ec331
commit 022e2c3afe

View File

@ -110,11 +110,6 @@ func numGoRoutines() int {
return runtime.NumCPU() * 4 return runtime.NumCPU() * 4
} }
type packet struct {
bytes []byte
addr net.Addr
}
type context struct { type context struct {
stop chan bool stop chan bool
done chan bool done chan bool
@ -642,13 +637,13 @@ func (p *Pinger) recvICMP(conn *icmp.PacketConn, ctx *context, wg *sync.WaitGrou
} }
} }
} }
p.procRecv(&packet{bytes: bytes, addr: ra}) p.procRecv(bytes, ra)
} }
} }
func (p *Pinger) procRecv(recv *packet) { func (p *Pinger) procRecv(bytes []byte, ra net.Addr) {
var ipaddr *net.IPAddr var ipaddr *net.IPAddr
switch adr := recv.addr.(type) { switch adr := ra.(type) {
case *net.IPAddr: case *net.IPAddr:
ipaddr = adr ipaddr = adr
case *net.UDPAddr: case *net.UDPAddr:
@ -665,17 +660,13 @@ func (p *Pinger) procRecv(recv *packet) {
} }
p.mu.Unlock() p.mu.Unlock()
var bytes []byte
var proto int var proto int
if isIPv4(ipaddr.IP) { if isIPv4(ipaddr.IP) {
if p.network == "ip" { if p.network == "ip" {
bytes = ipv4Payload(recv.bytes) bytes = ipv4Payload(bytes)
} else {
bytes = recv.bytes
} }
proto = ProtocolICMP proto = ProtocolICMP
} else if isIPv6(ipaddr.IP) { } else if isIPv6(ipaddr.IP) {
bytes = recv.bytes
proto = ProtocolIPv6ICMP proto = ProtocolIPv6ICMP
} else { } else {
return return