| 254 | } |
| 255 | |
| 256 | uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId) |
| 257 | { |
| 258 | uint8_t type = 0; |
| 259 | uint8_t opt_len = 0; |
| 260 | |
| 261 | unsigned long startTime = millis(); |
| 262 | |
| 263 | |
| 264 | |
| 265 | while(_dhcpUdpSocket.parsePacket() <= 0) |
| 266 | { |
| 267 | if((millis() - startTime) > responseTimeout) |
| 268 | { |
| 269 | |
| 270 | return 255; |
| 271 | } |
| 272 | delay(50); |
| 273 | } |
| 274 | |
| 275 | // start reading in the packet |
| 276 | RIP_MSG_FIXED fixedMsg; |
| 277 | _dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED)); |
| 278 | |
| 279 | if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT) |
| 280 | { |
| 281 | transactionId = ntohl(fixedMsg.xid); |
| 282 | if(memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 || (transactionId < _dhcpInitialTransactionId) || (transactionId > _dhcpTransactionId)) |
| 283 | { |
| 284 | // Need to read the rest of the packet here regardless |
| 285 | _dhcpUdpSocket.flush(); |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | memcpy(_dhcpLocalIp, fixedMsg.yiaddr, 4); |
| 290 | |
| 291 | // Skip to the option part |
| 292 | // Doing this a byte at a time so we don't have to put a big buffer |
| 293 | // on the stack (as we don't have lots of memory lying around) |
| 294 | for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++) |
| 295 | { |
| 296 | _dhcpUdpSocket.read(); // we don't care about the returned byte |
| 297 | } |
| 298 | |
| 299 | while (_dhcpUdpSocket.available() > 0) |
| 300 | { |
| 301 | switch (_dhcpUdpSocket.read()) |
| 302 | { |
| 303 | case endOption : |
| 304 | |
| 305 | break; |
| 306 | |
| 307 | case padOption : |
| 308 | |
| 309 | break; |
| 310 | |
| 311 | case dhcpMessageType : |
| 312 | |
| 313 | opt_len = _dhcpUdpSocket.read(); |
nothing calls this directly
no test coverage detected