Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
brutella committed Jun 4, 2019
1 parent ddb232d commit f2e42a0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func setupStreamManagement(m *service.CameraRTPStreamManagement, ff ffmpeg.FFMPE
})
}

// ipAtInterface returns the ip at iface with a specific version.
// version is either `rtp.IPAddrVersionv4` or `rtp.IPAddrVersionv6`.
func ipAtInterface(iface net.Interface, version uint8) (net.IP, error) {
addrs, err := iface.Addrs()
if err != nil {
Expand Down Expand Up @@ -162,16 +164,19 @@ func ipAtInterface(iface net.Interface, version uint8) (net.IP, error) {
return nil, fmt.Errorf("%s: No ip address found for version %d", iface.Name, version)
}

// ifaceOfConnection returns the network interface at which the connection was established.
func ifaceOfConnection(conn net.Conn) (*net.Interface, error) {
host, _, err := net.SplitHostPort(conn.LocalAddr().String())
if err != nil {
return nil, err
}

ip := net.ParseIP(host)
// 2019-06-04 (mah) ip might be nil if `host` contains the network interface name
// I couldn't find any documentation why v6 ip address contains the interface name
if ip == nil {
// host might include the interface name separated by %
// for example fe80::e627:bec4:30b9:cb12%wlan0
// get the interface name from the host string
// ex. host = "fe80::e627:bec4:30b9:cb12%wlan0"
comps := strings.Split(host, "%")
if len(comps) == 2 {
name := comps[1]
Expand Down

0 comments on commit f2e42a0

Please sign in to comment.