Skip to content

Commit

Permalink
Reduce duplication between New and NewWithContext, per hugelgupf@'s c…
Browse files Browse the repository at this point in the history
…omment.

Signed-off-by: Mark Suter <[email protected]>
  • Loading branch information
marksuter authored and hugelgupf committed Jan 9, 2025
1 parent 86bc934 commit b203261
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions dhcpv4/dhcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,7 @@ func New(modifiers ...Modifier) (*DHCPv4, error) {
if err != nil {
return nil, err
}
d := DHCPv4{
OpCode: OpcodeBootRequest,
HWType: iana.HWTypeEthernet,
ClientHWAddr: make(net.HardwareAddr, 6),
HopCount: 0,
TransactionID: xid,
NumSeconds: 0,
Flags: 0,
ClientIPAddr: net.IPv4zero,
YourIPAddr: net.IPv4zero,
ServerIPAddr: net.IPv4zero,
GatewayIPAddr: net.IPv4zero,
Options: make(Options),
}
for _, mod := range modifiers {
mod(&d)
}
return &d, nil
return newDHCPv4(xid, modifiers), nil
}

// NewWithContext creates a new DHCPv4 structure and fill it up with default
Expand All @@ -175,6 +158,10 @@ func NewWithContext(ctx context.Context, modifiers ...Modifier) (*DHCPv4, error)
if err != nil {
return nil, err
}
return newDHCPv4(xid, modifiers), nil
}

func newDHCPv4(xid TransactionID, modifiers ...Modifier) *DHCPv4 {
d := DHCPv4{
OpCode: OpcodeBootRequest,
HWType: iana.HWTypeEthernet,
Expand All @@ -192,7 +179,7 @@ func NewWithContext(ctx context.Context, modifiers ...Modifier) (*DHCPv4, error)
for _, mod := range modifiers {
mod(&d)
}
return &d, nil
return &d
}

// NewDiscoveryForInterface builds a new DHCPv4 Discovery message, with a default
Expand Down

0 comments on commit b203261

Please sign in to comment.