Developing lightweight computation at the DSG edge

Commit 3eec4c7c authored by Alirie Gray's avatar Alirie Gray Committed by Cameron Sparr
Browse files

Add ability to specifiy source IP address

parent 5cc5e292
...@@ -137,6 +137,9 @@ type Pinger struct { ...@@ -137,6 +137,9 @@ type Pinger struct {
// Tracker: Used to uniquely identify packet when non-priviledged // Tracker: Used to uniquely identify packet when non-priviledged
Tracker int64 Tracker int64
// Source is the source IP address
Source string
// stop chan bool // stop chan bool
done chan bool done chan bool
...@@ -144,7 +147,6 @@ type Pinger struct { ...@@ -144,7 +147,6 @@ type Pinger struct {
addr string addr string
ipv4 bool ipv4 bool
source string
size int size int
id int id int
sequence int sequence int
...@@ -277,12 +279,12 @@ func (p *Pinger) Run() { ...@@ -277,12 +279,12 @@ func (p *Pinger) Run() {
func (p *Pinger) run() { func (p *Pinger) run() {
var conn *icmp.PacketConn var conn *icmp.PacketConn
if p.ipv4 { if p.ipv4 {
if conn = p.listen(ipv4Proto[p.network], p.source); conn == nil { if conn = p.listen(ipv4Proto[p.network]); conn == nil {
return return
} }
conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true) conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true)
} else { } else {
if conn = p.listen(ipv6Proto[p.network], p.source); conn == nil { if conn = p.listen(ipv6Proto[p.network]); conn == nil {
return return
} }
conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true) conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true)
...@@ -570,8 +572,8 @@ func (p *Pinger) sendICMP(conn *icmp.PacketConn) error { ...@@ -570,8 +572,8 @@ func (p *Pinger) sendICMP(conn *icmp.PacketConn) error {
return nil return nil
} }
func (p *Pinger) listen(netProto string, source string) *icmp.PacketConn { func (p *Pinger) listen(netProto string) *icmp.PacketConn {
conn, err := icmp.ListenPacket(netProto, source) conn, err := icmp.ListenPacket(netProto, p.Source)
if err != nil { if err != nil {
fmt.Printf("Error listening for ICMP packets: %s\n", err.Error()) fmt.Printf("Error listening for ICMP packets: %s\n", err.Error())
close(p.done) close(p.done)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment