Created
July 4, 2017 13:39
-
-
Save iamacarpet/d0ea5c28f1753c7b624b79b9f5d6504d to your computer and use it in GitHub Desktop.
GoLang Multicast Listen for SSDP (Solaris)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"golang.org/x/net/ipv4" | |
"net" | |
) | |
func main() { | |
e1000g0, err := net.InterfaceByName("aggr1") | |
if err != nil { | |
panic(err) | |
} | |
NetAddr, err := net.ResolveUDPAddr("udp4", "239.255.255.250:1900") | |
if err != nil { | |
panic(err) | |
} | |
c, err := net.ListenMulticastUDP("udp", e1000g0, NetAddr) | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
p := ipv4.NewPacketConn(c) | |
if err := p.SetMulticastTTL(2); err != nil { | |
panic(err) | |
} | |
if err := p.SetMulticastLoopback(true); err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"golang.org/x/net/ipv4" | |
"net" | |
) | |
func main() { | |
e1000g0, err := net.InterfaceByName("aggr1") | |
if err != nil { | |
panic(err) | |
} | |
group := net.IPv4(239, 255, 255, 250) | |
c, err := net.ListenPacket("udp4", "239.255.255.250:1900") | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
p := ipv4.NewPacketConn(c) | |
if err := p.JoinGroup(e1000g0, &net.UDPAddr{IP: group}); err != nil { | |
panic(err) | |
} | |
if err := p.SetMulticastTTL(2); err != nil { | |
panic(err) | |
} | |
if err := p.SetMulticastLoopback(true); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment