return 0;
}
#else
-static int ethsock_arp(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr, int add, int nofail)
+static int ethsock_arp(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr, int add)
{
DWORD ret;
MIB_IPNETROW arp = {
memcpy(arp.bPhysAddr, hwaddr, 6);
- ret = add ? CreateIpNetEntry(&arp) : DeleteIpNetEntry(&arp);
- if (ret != NO_ERROR && !nofail) {
- win_perror2(add ? "CreateIpNetEntry" : "DeleteIpNetEntry", ret);
- return -1;
+ if (add) {
+ ret = CreateIpNetEntry(&arp);
+ if (ret != NO_ERROR) {
+ win_perror2("CreateIpNetEntry", ret);
+ return -1;
+ }
+ } else {
+ DeleteIpNetEntry(&arp);
}
return 0;
int ethsock_arp_add(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr)
{
- ethsock_arp(sock, hwaddr, ipaddr, 0, 1);
- return ethsock_arp(sock, hwaddr, ipaddr, 1, 0);
+ ethsock_arp_del(sock, hwaddr, ipaddr);
+ return ethsock_arp(sock, hwaddr, ipaddr, 1);
}
int ethsock_arp_del(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr)
{
- return ethsock_arp(sock, hwaddr, ipaddr, 0, 0);
+ return ethsock_arp(sock, hwaddr, ipaddr, 0);
}
#endif
}
static struct ethsock *gsock = NULL;
+static int garp = 0;
+static struct in_addr arpip = { 0 };
+static uint8_t arpmac[6] = { 0 };
static void sigh(int sig)
{
printf("\n");
if (gsock) {
+ if (garp) {
+ ethsock_arp_del(gsock, arpmac, &arpip);
+ }
ethsock_close(gsock);
+ gsock = NULL;
}
exit(1);
}
gsock = sock;
+ garp = 0;
sigh_orig = signal(SIGINT, sigh);
if (ethsock_set_timeout(sock, args->rx_timeout)) {
printf("Sending configuration: ip %s, mask %s.\n",
args->ipaddr, args->ipmask);
+ memcpy(arpmac, rx.eh.ether_shost, 6);
+ memcpy(&arpip, &ipconf.addr, sizeof(ipconf.addr));
+
+ if (ethsock_arp_add(sock, arpmac, &arpip) != 0) {
+ goto out;
+ }
+
+ garp = 1;
+
break;
case NMRP_C_TFTP_UL_REQ:
if (!upload_ok) {
out:
signal(SIGINT, sigh_orig);
gsock = NULL;
+ ethsock_arp_del(sock, arpmac, &arpip);
ethsock_close(sock);
return status;
}
ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len);
int ethsock_set_timeout(struct ethsock *sock, unsigned msec);
uint8_t *ethsock_get_hwaddr(struct ethsock *sock);
+int ethsock_arp_add(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr);
+int ethsock_arp_del(struct ethsock *sock, uint8_t *hwaddr, struct in_addr *ipaddr);
int ethsock_list_all(void);
struct ethsock_ip_callback_args