| 196 | } |
| 197 | |
| 198 | bool DHCP_Server::Send(UDP_Packet* payload) |
| 199 | { |
| 200 | UDP_Packet* udpPacket = static_cast<UDP_Packet*>(payload); |
| 201 | PayloadPtr* udpPayload = static_cast<PayloadPtr*>(udpPacket->GetPayload()); |
| 202 | DHCP_Packet dhcp = DHCP_Packet(udpPayload->data, udpPayload->GetLength()); |
| 203 | |
| 204 | //State |
| 205 | u8 hType = dhcp.hardwareType; |
| 206 | u8 hLen = dhcp.hardwareAddressLength; |
| 207 | u32 xID = dhcp.transactionID; |
| 208 | u8* cMac = dhcp.clientHardwareAddress; |
| 209 | u32 cookie = dhcp.magicCookie; |
| 210 | |
| 211 | u8 msg = 0; |
| 212 | std::vector<u8> reqList; |
| 213 | |
| 214 | uint leaseTime = 86400; |
| 215 | |
| 216 | for (size_t i = 0; i < dhcp.options.size(); i++) |
| 217 | { |
| 218 | switch (dhcp.options[i]->GetCode()) |
| 219 | { |
| 220 | case 0: |
| 221 | continue; |
| 222 | case 1: |
| 223 | if (netmask != ((DHCPopSubnet*)dhcp.options[i])->subnetMask) |
| 224 | Console.Error("DHCP: SubnetMask missmatch"); |
| 225 | break; |
| 226 | case 3: |
| 227 | if (((DHCPopRouter*)dhcp.options[i])->routers.size() != 1) |
| 228 | Console.Error("DHCP: Routers count missmatch"); |
| 229 | |
| 230 | if (gateway != ((DHCPopRouter*)dhcp.options[i])->routers[0]) |
| 231 | Console.Error("DHCP: RouterIP missmatch"); |
| 232 | break; |
| 233 | case 6: |
| 234 | // clang-format off |
| 235 | if (((((DHCPopDNS*)dhcp.options[i])->dnsServers.size() == 0 && dns1.integer == 0) || |
| 236 | (((DHCPopDNS*)dhcp.options[i])->dnsServers.size() == 1 && dns1.integer != 0 && dns2.integer == 0) || |
| 237 | (((DHCPopDNS*)dhcp.options[i])->dnsServers.size() == 2 && dns2.integer != 0)) == false) |
| 238 | Console.Error("DHCP: DNS count missmatch"); |
| 239 | // clang-format on |
| 240 | |
| 241 | if ((((DHCPopDNS*)dhcp.options[i])->dnsServers.size() > 0 && dns1 != ((DHCPopDNS*)dhcp.options[i])->dnsServers[0]) || |
| 242 | (((DHCPopDNS*)dhcp.options[i])->dnsServers.size() > 1 && dns2 != ((DHCPopDNS*)dhcp.options[i])->dnsServers[1])) |
| 243 | Console.Error("DHCP: DNS missmatch"); |
| 244 | break; |
| 245 | case 12: |
| 246 | //TODO use name? |
| 247 | break; |
| 248 | case 50: |
| 249 | if (ps2IP != ((DHCPopREQIP*)dhcp.options[i])->requestedIP) |
| 250 | Console.Error("DHCP: ReqIP missmatch"); |
| 251 | break; |
| 252 | case 51: |
| 253 | leaseTime = ((DHCPopIPLT*)(dhcp.options[i]))->ipLeaseTime; |
| 254 | break; |
| 255 | case 53: |
nothing calls this directly
no test coverage detected