2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 type UDPSender struct {
34 func (c UDPSender) Write(data []byte) (int, error) {
35 return c.conn.WriteToUDP(data, c.addr)
38 func startUDP() chan Pkt {
39 bind, err := net.ResolveUDPAddr("udp", *bindAddr)
40 ready := make(chan struct{})
42 log.Fatalln("Can not resolve bind address:", err)
44 lconn, err := net.ListenUDP("udp", bind)
46 log.Fatalln("Can not listen on UDP:", err)
48 sink := make(chan Pkt)
50 buf := make([]byte, govpn.MTU)
52 var raddr *net.UDPAddr
56 lconn.SetReadDeadline(time.Now().Add(time.Second))
57 n, raddr, err = lconn.ReadFromUDP(buf)
59 sink <- Pkt{ready: ready}
64 UDPSender{lconn, raddr},