<commit_before>package dhcp4

import (
	"net"
	"time"
)

type Option struct {
	Code  OptionCode
	Value []byte
}
type OptionCode byte
type OpCode byte
type MessageType byte // Option 53

// A DHCP packet
type Packet []byte

func (p Packet) OpCode() OpCode           { return OpCode(p[0]) }
func (p Packet) HType() byte              { return p[1] }
func (p Packet) HLen() byte               { return p[2] }
func (p Packet) Hops() byte               { return p[3] } // Never Used?
func (p Packet) XId() []byte              { return p[4:8] }
func (p Packet) Secs() []byte             { return p[8:10] } // Never Used?
func (p Packet) Flags() []byte            { return p[10:12] }
func (p Packet) CIAddr() net.IP           { return net.IP(p[12:16]) }
func (p Packet) YIAddr() net.IP           { return net.IP(p[16:20]) }
func (p Packet) SIAddr() net.IP           { return net.IP(p[20:24]) }
func (p Packet) GIAddr() net.IP           { return net.IP(p[24:28]) }
func (p Packet) CHAddr() net.HardwareAddr { return net.HardwareAddr(p[28 : 28+p.HLen()]) } // max endPos 44
// 192 bytes of zeros BOOTP legacy
func (p Packet) Cookie() []byte { return p[236:240] }
func (p Packet) Options() []byte {
	if len(p) > 240 {
		return p[240:]
	}
	return nil
}

func (p Packet) Broadcast() bool { return p.Flags()[0] > 127 }

func (p Packet) SetBroadcast(broadcast bool) {
	if p.Broadcast() != broadcast {
		p.Flags()[0] ^= 128
	}
}

func (p Packet) SetOpCode(c OpCode) { p[0] = byte(c) }
func (p Packet) SetCHAddr(a net.HardwareAddr) {
	copy(p[28:44], a)
	p[2] = byte(len(a))
}
func (p Packet) SetHType(hType byte)     { p[1] = hType }
func (p Packet) SetCookie(cookie []byte) { copy(p.Cookie(), cookie) }
func (p Packet) SetXId(xId []byte)       { copy(p.XId(), xId) }
func (p Packet) SetSecs(secs []byte)     { copy(p.Secs(), secs) }
func (p Packet) SetFlags(flags []byte)   { copy(p.Flags(), flags) }
func (p Packet) SetCIAddr(ip net.IP)     { copy(p.CIAddr(), ip) }
func (p Packet) SetYIAddr(ip net.IP)     { copy(p.YIAddr(), ip) }
func (p Packet) SetSIAddr(ip net.IP)     { copy(p.SIAddr(), ip) }
func (p Packet) SetGIAddr(ip net.IP)     { copy(p.GIAddr(), ip) }

// Map of DHCP options
type Options map[OptionCode][]byte

// Parses the packet's options into an Options map
func (p Packet) ParseOptions() Options {
	opts := p.Options()
	options := make(Options, 10)
	for len(opts) >= 2 && OptionCode(opts[0]) != End {
		if OptionCode(opts[0]) == Pad {<commit_msg>More .To4()s<commit_after>package dhcp4

import (
	"net"
	"time"
)

type Option struct {
	Code  OptionCode
	Value []byte
}
type OptionCode byte
type OpCode byte
type MessageType byte // Option 53

// A DHCP packet
type Packet []byte

func (p Packet) OpCode() OpCode           { return OpCode(p[0]) }
func (p Packet) HType() byte              { return p[1] }
func (p Packet) HLen() byte               { return p[2] }
func (p Packet) Hops() byte               { return p[3] } // Never Used?
func (p Packet) XId() []byte              { return p[4:8] }
func (p Packet) Secs() []byte             { return p[8:10] } // Never Used?
func (p Packet) Flags() []byte            { return p[10:12] }
func (p Packet) CIAddr() net.IP           { return net.IP(p[12:16]) }
func (p Packet) YIAddr() net.IP           { return net.IP(p[16:20]) }
func (p Packet) SIAddr() net.IP           { return net.IP(p[20:24]) }
func (p Packet) GIAddr() net.IP           { return net.IP(p[24:28]) }
func (p Packet) CHAddr() net.HardwareAddr { return net.HardwareAddr(p[28 : 28+p.HLen()]) } // max endPos 44
// 192 bytes of zeros BOOTP legacy
func (p Packet) Cookie() []byte { return p[236:240] }
func (p Packet) Options() []byte {
	if len(p) > 240 {
		return p[240:]
	}
	return nil
}

func (p Packet) Broadcast() bool { return p.Flags()[0] > 127 }

func (p Packet) SetBroadcast(broadcast bool) {
	if p.Broadcast() != broadcast {
		p.Flags()[0] ^= 128
	}
}

func (p Packet) SetOpCode(c OpCode) { p[0] = byte(c) }
func (p Packet) SetCHAddr(a net.HardwareAddr) {
	copy(p[28:44], a)
	p[2] = byte(len(a))
}
func (p Packet) SetHType(hType byte)     { p[1] = hType }
func (p Packet) SetCookie(cookie []byte) { copy(p.Cookie(), cookie) }
func (p Packet) SetXId(xId []byte)       { copy(p.XId(), xId) }
func (p Packet) SetSecs(secs []byte)     { copy(p.Secs(), secs) }
func (p Packet) SetFlags(flags []byte)   { copy(p.Flags(), flags) }
func (p Packet) SetCIAddr(ip net.IP)     { copy(p.CIAddr(), ip.To4()) }
func (p Packet) SetYIAddr(ip net.IP)     { copy(p.YIAddr(), ip.To4()) }
func (p Packet) SetSIAddr(ip net.IP)     { copy(p.SIAddr(), ip.To4()) }
func (p Packet) SetGIAddr(ip net.IP)     { copy(p.GIAddr(), ip.To4()) }

// Map of DHCP options
type Options map[OptionCode][]byte

// Parses the packet's options into an Options map
func (p Packet) ParseOptions() Options {
	opts := p.Options()
	options := make(Options, 10)
	for len(opts) >= 2 && OptionCode(opts[0]) != End {
		if OptionCode(opts[0]) == Pad {
{'fraction_non_alphanumeric': 0.1721194879089616, 'fraction_numerical': 0.030684820158504367, 'mean_word_length': 3.1119465329991645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2668879', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1821, 'n_words': 553}