uint16_t region;
char *filename;
time_t beg;
- int i, timeout, status, ulreqs, expect, upload_ok, autoip, kareqs;
+ int i, timeout, status, ulreqs, expect, upload_ok, autoip, ka_reqs, fake;
struct ethsock *sock;
struct ethsock_ip_undo *ip_undo = NULL;
struct ethsock_arp_undo *arp_undo = NULL;
i = 0;
upload_ok = 0;
+ fake = 0;
timeout = args->blind ? 10 : NMRP_INITIAL_TIMEOUT;
beg = time_monotonic();
// we're blind, so fake a response from the MAC specified by -m
memcpy(rx.eh.ether_shost, dest, 6);
msg_init(&rx.msg, NMRP_C_CONF_REQ);
- printf("Faking one.");
+ printf("Continuing blindly.");
+ fake = 1;
break;
}
}
expect = NMRP_C_CONF_REQ;
ulreqs = 0;
- kareqs = 0;
+ ka_reqs = 0;
while (!g_interrupted) {
if (expect != NMRP_C_NONE && rx.msg.code != expect) {
msg_mkconfack(&tx.msg, ipaddr.s_addr, ipmask.s_addr, region);
expect = NMRP_C_TFTP_UL_REQ;
- printf("Received configuration request from %s.\n",
- mac_to_str(rx.eh.ether_shost));
+ if (!fake) {
+ printf("Received configuration request from %s.\n",
+ mac_to_str(rx.eh.ether_shost));
+ }
printf("Sending configuration: %s/%d.\n",
args->ipaddr, bitcount(ipmask.s_addr));
printf("Received upload request: filename '%s'.\n", filename);
} else if (!args->file_remote) {
args->file_remote = leafname(args->file_local);
- printf("Received upload request without filename.\n");
+ if (!fake) {
+ printf("Received upload request without filename.\n");
+ }
}
status = 0;
case NMRP_C_KEEP_ALIVE_REQ:
tx.msg.code = NMRP_C_KEEP_ALIVE_ACK;
ethsock_set_timeout(sock, args->ul_timeout);
- printf("\rReceived keep-alive request (%d). ", ++kareqs);
+ printf("\rReceived keep-alive request (%d). ", ++ka_reqs);
break;
case NMRP_C_CLOSE_REQ:
tx.msg.code = NMRP_C_CLOSE_ACK;
}
if (tx.msg.code != NMRP_C_NONE) {
- if (pkt_send(sock, &tx) < 0) {
- goto out;
- }
-
- if (tx.msg.code == NMRP_C_CLOSE_REQ) {
+ if (pkt_send(sock, &tx) != 0 || tx.msg.code == NMRP_C_CLOSE_REQ) {
goto out;
}
}
if (rx.msg.code == NMRP_C_CLOSE_REQ) {
- if (kareqs) {
+ if (ka_reqs) {
printf("\n");
}
status = pkt_recv(sock, &rx);
if (status) {
if (status == 2) {
- fprintf(stderr, "Timeout while waiting for %s. ",
- msg_code_str(expect));
- }
+ if (!args->blind) {
+ fprintf(stderr, "Timeout while waiting for %s.\n",
+ msg_code_str(expect));
+ goto out;
+ }
- if (!args->blind) {
- printf("\n");
- goto out;
- } else {
- printf("Faking response.\n");
+ // fake response
msg_init(&rx.msg, expect);
memcpy(rx.eh.ether_shost, tx.eh.ether_dhost, 6);
+ fake = 1;
+ } else {
+ goto out;
}
+ } else {
+ fake = 0;
}
ethsock_set_timeout(sock, args->rx_timeout);