X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fmcd.go;h=b4de4f4cb602c97f0ced66027d744ca7441a03db;hb=0367cce2741e1ce6a89a49fd5c4e9df6005c9744;hp=be40f42de1edd50f03e0a1bc5d045ce88bf76bb5;hpb=1cc0df98a8d949b9f8137081b875d98a1aae2e67;p=nncp.git diff --git a/src/mcd.go b/src/mcd.go index be40f42..b4de4f4 100644 --- a/src/mcd.go +++ b/src/mcd.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -176,20 +176,24 @@ func (ctx *Ctx) MCDRx(ifiName string) error { } func (ctx *Ctx) MCDTx(ifiName string, port int, interval time.Duration) error { - conn, err := net.DialUDP("udp", - &net.UDPAddr{Port: port, Zone: ifiName}, - &net.UDPAddr{IP: mcdIP, Port: MCDPort, Zone: ifiName}, - ) + ifi, err := net.InterfaceByName(ifiName) + if err != nil { + return err + } + addr := &net.UDPAddr{IP: mcdIP, Port: port, Zone: ifiName} + conn, err := net.ListenMulticastUDP("udp", ifi, addr) if err != nil { return err } + + dst := &net.UDPAddr{IP: mcdIP, Port: MCDPort, Zone: ifiName} var buf bytes.Buffer mcd := MCD{Magic: MagicNNCPDv1.B, Sender: ctx.Self.Id} if _, err := xdr.Marshal(&buf, mcd); err != nil { panic(err) } if interval == 0 { - _, err = conn.Write(buf.Bytes()) + _, err = conn.WriteTo(buf.Bytes(), dst) return err } go func() { @@ -201,7 +205,7 @@ func (ctx *Ctx) MCDTx(ifiName string, port int, interval time.Duration) error { ifiName, MCDPort, port, ) }) - _, err = conn.Write(buf.Bytes()) + _, err = conn.WriteTo(buf.Bytes(), dst) if err != nil { ctx.LogE("mcd", les, err, func(les LEs) string { return fmt.Sprintf("MCD on %s/%d/%d", ifiName, MCDPort, port)