There are a number of barriers to transition with what you offer:
Security
In general, being able to set the source IP address for a packet can be a very dangerous security thing. Under linux, to create your own raw DHCP packets with custom headers, you will need to run the application as root or from the application using the CAP_NET_RAW Feature (see setcap ).
Raw sockets in Go
The standard network library does not provide socket capabilities because it is very specialized, and the API can be changed as people begin to use it in anger.
The go.net subcategory provides ipv4 and the ipv6 package, the first of which should meet your needs:
http://godoc.org/code.google.com/p/go.net/ipv4#NewRawConn
Header Subversion
You will need to use ipv4.RawConn ReadFrom to read the source package. Then you should use most of these fields along with the GIADDR logic to configure the headers for the WriteTo call. It probably looks something like this:
for { hdr, payload, _, err := conn.ReadFrom(buf) if err != nil { ... } hdr.ID = 0 hdr.Checksum = 0 hdr.Src = ... hdr.Dst = ... if err := conn.WriteTo(hdr, payload, nil); err != nil { ... } }
source share