#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
return 0;
}
+static struct ethsock *gsock = NULL;
+
+static void sigh(int sig)
+{
+ printf("\n");
+ if (gsock) {
+ ethsock_close(gsock);
+ }
+
+ exit(1);
+}
+
static const char *spinner = "\\|/-";
int nmrp_do(struct nmrpd_args *args)
time_t beg;
int i, err, ulreqs, expect;
struct ethsock *sock;
+ sig_t sigh_orig;
if (args->op != NMRP_UPLOAD_FW) {
fprintf(stderr, "Operation not implemented.\n");
return 1;
}
+ gsock = sock;
+ sigh_orig = signal(SIGINT, sigh);
+
if (ethsock_set_timeout(sock, args->rx_timeout)) {
- return 1;
+ goto out;
}
src = ethsock_get_hwaddr(sock);
if (!src) {
- return 1;
+ goto out;
}
memcpy(tx.eh.ether_shost, src, 6);
err = 0;
out:
+ signal(SIGINT, sigh_orig);
+ gsock = NULL;
ethsock_close(sock);
return err;
}