mirror of
https://github.com/maride/afl-transmit.git
synced 2024-10-18 11:06:34 +00:00
31 lines
548 B
Go
31 lines
548 B
Go
package net
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
)
|
|
|
|
type Peer struct {
|
|
Address string
|
|
}
|
|
|
|
// Sends the given content to the peer
|
|
func (p *Peer) SendToPeer(content []byte) {
|
|
// Build up a connection
|
|
tcpConn, dialErr := net.Dial("tcp", p.Address)
|
|
if dialErr != nil {
|
|
log.Printf("Unable to connect to peer %s: %s", p.Address, dialErr)
|
|
return
|
|
}
|
|
|
|
// Send
|
|
_, writeErr := tcpConn.Write(content)
|
|
if writeErr != nil {
|
|
log.Printf("Unable to write to peer %s: %s", tcpConn.RemoteAddr().String(), writeErr)
|
|
return
|
|
}
|
|
|
|
// Close connection
|
|
tcpConn.Close()
|
|
}
|