[Solved] How to send a fake udp package in golang


At the end I managed to make works this check to send in periods of 10 minuts an upd package with an mac address I know is gonna never be reached as following.

func (h *DHCPHandler) check() {
    //Fetch parameters from config file
    config := getConfig() // here is a mac saved on a json file 01:ff:ff:ff:ff:ff
    macFake, err := net.ParseMAC(config.MacFake)

    if err != nil {
            fmt.Println("error with the fake mac provided on the json file", err)
    }

    // create connection
    conn, err := net.Dial("udp4", "127.0.0.1:67")
    if err != nil {
            fmt.Println("error with the connection", err)
    }

    //stay alive
    for {
            fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
            conn.Write(dhcp.RequestPacket(dhcp.Discover, macFake, h.ip, []byte{0, 1, 2, 3}, true, nil))
            time.Sleep(10 * time.Minute)
    }

}

On the main function, I just need to call this check goroutine and add on the server side (ServeDHCP) this code:

    mac := p.CHAddr().String()
    //Fetch parameters from config file
    config := getConfig()
    if mac == config.MacFake { //udp package received and a mac saved on a json file 01:ff:ff:ff:ff:ff
            // send notification to restart if failure on a systemd
            daemon.SdNotify(false, "WATCHDOG=1")
            return
    }

The last part needed is to add a systemd check, in my case I send the watchdog every 10 min, so, the systemd check will be setted it to 11min

[Service]
ExecStartPre=//something 
WatchdogSec=11min 
Restart=on-failure

solved How to send a fake udp package in golang