Class/DhcpReleasePacket.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using module '.\Enums.psm1' using module '.\DhcpOptionObject.psm1' using module '.\DhcpPacket.psm1' # DHCP Release Packet class class DhcpReleasePacket : DhcpPacket { [ValidateNotNull()][ipaddress]$ClientIPAddress = [ipaddress]::None [ValidateNotNull()][ipaddress]$ServerIPAddress = [ipaddress]::None DhcpReleasePacket([ipaddress]$ClientIPAddress, [IPAddress]$ServerIPAddress, [PhysicalAddress]$MacAddress) : base() { [Random]::new().NextBytes($this.XID) $this.CHAddr = $MacAddress $this.ClientIPAddress = $ClientIPAddress $this.ServerIPAddress = $ServerIPAddress $this.CIAddr = $this.ClientIPAddress $this.AddDhcpOptions(@( [DhcpOptionObject]::new([DhcpOption]::DHCPMessageType, [DhcpMessageType]::DHCPRELEASE), [DhcpOptionObject]::new([DhcpOption]::ServerId, $this.ServerIPAddress.GetAddressBytes()), [DhcpOptionObject]::new([DhcpOption]::End, $null) )) } [byte[]]GetPacketBytes() { $this.CIAddr = $this.ClientIPAddress if (-not ($this._DhcpOptionsList.Keys -eq 61)) { $this.AddDhcpOptions( [DhcpOptionObject]::new([DhcpOption]::ClientId, (([byte[]]0x01) + $this.CHAddr.GetAddressBytes())) ) } $this.AddDhcpOptions(@( [DhcpOptionObject]::new([DhcpOption]::ServerId, $this.ServerIPAddress.GetAddressBytes()) )) return ([DhcpPacket]$this).GetPacketBytes() } } |