Windows fixes
This commit is contained in:
parent
951f1214f0
commit
482b03db23
3 changed files with 43 additions and 21 deletions
15
ethsock.c
15
ethsock.c
|
@ -152,7 +152,7 @@ static bool get_intf_info(const char *intf, uint8_t *hwaddr, DWORD *index)
|
|||
|
||||
if ((ret = GetAdaptersInfo(adapters, &bufLen) == NO_ERROR)) {
|
||||
for (adapter = adapters; adapter; adapter = adapter->Next) {
|
||||
if (adapter->Type != MIB_IF_TYPE_ETHERNET) {
|
||||
if (adapter->Type != MIB_IF_TYPE_ETHERNET && adapter->Type != IF_TYPE_IEEE80211) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -751,8 +751,10 @@ out:
|
|||
#else // NMRPFLASH_WINDOWS
|
||||
ULONG instance;
|
||||
|
||||
(*undo)->context = 0;
|
||||
|
||||
DWORD ret = AddIPAddress(ipaddr, ipmask, sock->index, &(*undo)->context, &instance);
|
||||
if (ret != NO_ERROR) {
|
||||
if (ret != NO_ERROR && ret != ERROR_DUP_DOMAINNAME && ret != ERROR_OBJECT_ALREADY_EXISTS) {
|
||||
win_perror2("AddIPAddress", ret);
|
||||
return -1;
|
||||
}
|
||||
|
@ -776,13 +778,8 @@ int ethsock_ip_del(struct ethsock *sock, struct ethsock_ip_undo **undo)
|
|||
ret = 0;
|
||||
}
|
||||
#else
|
||||
DWORD err = DeleteIPAddress((*undo)->context);
|
||||
if (err != NO_ERROR) {
|
||||
win_perror2("DeleteIPAddress", ret);
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
DeleteIPAddress((*undo)->context);
|
||||
ret = 0;
|
||||
#endif
|
||||
|
||||
free(*undo);
|
||||
|
|
17
nmrp.c
17
nmrp.c
|
@ -583,6 +583,12 @@ int nmrp_do(struct nmrpd_args *args)
|
|||
memcpy(arpmac, rx.eh.ether_shost, 6);
|
||||
memcpy(&arpip, &ipconf.addr, sizeof(ipconf.addr));
|
||||
|
||||
if (autoip) {
|
||||
if (ethsock_ip_add(sock, intf_addr, ipconf.mask.s_addr, &gundo) != 0) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (ethsock_arp_add(sock, arpmac, &arpip) != 0) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -622,12 +628,6 @@ int nmrp_do(struct nmrpd_args *args)
|
|||
|
||||
status = 0;
|
||||
|
||||
if (autoip) {
|
||||
if (ethsock_ip_add(sock, intf_addr, ipconf.mask.s_addr, &gundo) != 0) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (args->tftpcmd) {
|
||||
printf("Executing '%s' ... ", args->tftpcmd);
|
||||
fflush(stdout);
|
||||
|
@ -662,10 +662,6 @@ int nmrp_do(struct nmrpd_args *args)
|
|||
status = tftp_put(args);
|
||||
}
|
||||
|
||||
if (ethsock_ip_del(sock, &gundo) != 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
printf("OK\nWaiting for remote to respond.\n");
|
||||
upload_ok = 1;
|
||||
|
@ -739,6 +735,7 @@ out:
|
|||
signal(SIGINT, sigh_orig);
|
||||
gsock = NULL;
|
||||
ethsock_arp_del(sock, arpmac, &arpip);
|
||||
ethsock_ip_del(sock, &gundo);
|
||||
ethsock_close(sock);
|
||||
return status;
|
||||
}
|
||||
|
|
32
tftp.c
32
tftp.c
|
@ -262,12 +262,40 @@ int tftp_put(struct nmrpd_args *args)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
if (args->ipaddr_intf) {
|
||||
if ((addr.sin_addr.s_addr = inet_addr(args->ipaddr_intf)) == INADDR_NONE) {
|
||||
perror("inet_addr");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
int tries = 100;
|
||||
|
||||
while (1) {
|
||||
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||
#ifdef NMRPFLASH_WINDOWS
|
||||
// Wait for AddIPAddress to update the IP tables
|
||||
if (WSAGetLastError() == WSAEADDRNOTAVAIL) {
|
||||
if (--tries) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sock_perror("bind");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((addr.sin_addr.s_addr = inet_addr(args->ipaddr)) == INADDR_NONE) {
|
||||
perror("inet_addr");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(args->port);
|
||||
|
||||
block = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue