func ListenAndServe(handler Handler) error {
	l, err := net.ListenPacket("udp4", ":67")
	if err != nil {
		return err
	}
	defer l.Close()
	return Serve(l, handler)
}
ListenAndServe listens on the UDP network address addr and then calls
Serve with handler to handle requests on incoming packets.
package dhcp4
import (
	"net"
	"strconv"
)
type Handler interface {
	ServeDHCP(req Packet, msgType MessageType, options Options) Packet
}
type ServeConn interface {
	ReadFrom(b []byte) (n int, addr net.Addr, err error)
	WriteTo(b []byte, addr net.Addr) (n int, err error)
}
func Serve(conn ServeConn, handler Handler) error {
	buffer := make([]byte, 1500)
	for {
		n, addr, err := conn.ReadFrom(buffer)
		if err != nil {
			return err
		}
		if n < 240 {  
			continue
		}
		req := Packet(buffer[:n])
		if req.HLen() > 16 {  
			continue
		}
		options := req.ParseOptions()
		var reqType MessageType
		if t := options[OptionDHCPMessageType]; len(t) != 1 {
			continue
		} else {
			reqType = MessageType(t[0])
			if reqType < Discover || reqType > Inform {
				continue
			}
		}
		if res := handler.ServeDHCP(req, reqType, options); res != nil {
			ipStr, portStr, err := net.SplitHostPort(addr.String())
			if err != nil {
				return err
			}
			if net.ParseIP(ipStr).Equal(net.IPv4zero) || req.Broadcast() {
				port, _ := strconv.Atoi(portStr)
				addr = &net.UDPAddr{IP: net.IPv4bcast, Port: port}
			}
			if _, e := conn.WriteTo(res, addr); e != nil {
				return e
			}
		}
	}
}