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;
}
#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;
}
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);
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;
}
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);
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;
signal(SIGINT, sigh_orig);
gsock = NULL;
ethsock_arp_del(sock, arpmac, &arpip);
+ ethsock_ip_del(sock, &gundo);
ethsock_close(sock);
return status;
}
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;