Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/ipv4: Recieving multiple Multicast UDP streams with same ports #16797

Closed
ahmadissa opened this issue Aug 19, 2016 · 1 comment
Closed

Comments

@ahmadissa
Copy link

@ahmadissa ahmadissa commented Aug 19, 2016

go version:
go version go1.7 linux/amd64

go env:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aissa/code/go"
GORACE=""
GOROOT="/home/aissa/go"
GOTOOLDIR="/home/aissa/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build583051275=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

with referance to : https://godoc.org/golang.org/x/net/ipv4

Im trying to catch to different multicast streams having the same port and saving its data to two separate files, both files are created but both files are having duplicate content from both streams.

'netstat -tulnp' is giving the below:

udp 0 0 0.0.0.0:1234 0.0.0.0:* 24951/main
udp 0 0 0.0.0.0:1234 0.0.0.0:* 24951/main

is should be

udp 0 238.1.2.2:1234 0.0.0.0:* 24951/main
udp 0 238.1.2.1:1234 0.0.0.0:* 24951/main

the code is below:

`package main

    import (
        "io"
        "net"
        "os"
        "time"

        "golang.org/x/net/ipv4"
    )

    func main() {
        c1, err := net.ListenPacket("udp4", "224.0.0.0:1234")
        if err != nil {
            // error handling
        }
        en0, err := net.InterfaceByName("en0")
        if err != nil {
            // error handling
        }
        c2, err := net.ListenPacket("udp4", "224.0.0.0:1234")
        if err != nil {
            // error handling
        }
        p1 := ipv4.NewPacketConn(c1)
        if err := p1.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(238, 1, 2, 2)}); err != nil {
            // error handling
        }
        p2 := ipv4.NewPacketConn(c2)
        if err := p2.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(238, 1, 2, 1)}); err != nil {
            // error handling
        }
        fo1, err := os.Create("test1.ts")
        defer fo1.Close()
        if err != nil {
            return
        }
        go io.Copy(fo1, p1)
        fo2, err := os.Create("test2.ts")
        defer fo2.Close()
        if err != nil {
            return
        }
        go io.Copy(fo2, p2)
        time.Sleep(time.Second * 10)
        p1.LeaveGroup(en0, c1.LocalAddr())
        p1.Close()
        c1.Close()
        p2.LeaveGroup(en0, c2.LocalAddr())
        p2.Close()
        c2.Close()
    }

`

@mikioh mikioh changed the title Recieving multiple Multicast UDP streams with same ports x/net/ipv4: Recieving multiple Multicast UDP streams with same ports Aug 21, 2016
@mikioh mikioh added this to the Unreleased milestone Aug 21, 2016
@mikioh
Copy link
Contributor

@mikioh mikioh commented Aug 21, 2016

In that case, you need to use ipv4.ControlMessage to distinguish the original IP destination addresses.

@mikioh mikioh closed this as completed Aug 21, 2016
@golang golang locked and limited conversation to collaborators Aug 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants