* Sends ARP requests to locate the server and waits for a response. * We first try to ARP the server itself, and fall back to the provided * gateway if the server appears to be off-link. * * Return value: * 0 on success * errno on error */
| 393 | * errno on error |
| 394 | */ |
| 395 | int |
| 396 | debugnet_arp_gw(struct debugnet_pcb *pcb) |
| 397 | { |
| 398 | in_addr_t dst; |
| 399 | int error, polls, retries; |
| 400 | |
| 401 | dst = pcb->dp_server; |
| 402 | restart: |
| 403 | for (retries = 0; retries < debugnet_arp_nretries; retries++) { |
| 404 | error = debugnet_send_arp(pcb, dst); |
| 405 | if (error != 0) |
| 406 | return (error); |
| 407 | for (polls = 0; polls < debugnet_npolls && |
| 408 | pcb->dp_state < DN_STATE_HAVE_GW_MAC; polls++) { |
| 409 | debugnet_network_poll(pcb); |
| 410 | DELAY(500); |
| 411 | } |
| 412 | if (pcb->dp_state >= DN_STATE_HAVE_GW_MAC) |
| 413 | break; |
| 414 | printf("(ARP retry)"); |
| 415 | } |
| 416 | if (pcb->dp_state >= DN_STATE_HAVE_GW_MAC) |
| 417 | return (0); |
| 418 | if (dst == pcb->dp_server) { |
| 419 | printf("\nFailed to ARP server"); |
| 420 | if (pcb->dp_gateway != INADDR_ANY) { |
| 421 | printf(", trying to reach gateway...\n"); |
| 422 | dst = pcb->dp_gateway; |
| 423 | goto restart; |
| 424 | } else |
| 425 | printf(".\n"); |
| 426 | } else |
| 427 | printf("\nFailed to ARP gateway.\n"); |
| 428 | |
| 429 | return (ETIMEDOUT); |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * Unreliable IPv4 transmission of an mbuf chain to the debugnet server |
no test coverage detected