Windows bind() error fix (WIP)

This commit is contained in:
Joseph C. Lehner 2020-12-08 17:22:27 +01:00
parent 9c7e7f1f80
commit ca5fb06a84

View file

@ -1096,6 +1096,8 @@ static int ethsock_ip_add_del(struct ethsock *sock, uint32_t ipaddr, uint32_t ip
#endif
#else // NMRPFLASH_WINDOWS
MIB_UNICASTIPADDRESS_ROW row;
DWORD err;
int i;
memset(&row, 0, sizeof(row));
@ -1112,8 +1114,6 @@ static int ethsock_ip_add_del(struct ethsock *sock, uint32_t ipaddr, uint32_t ip
row.ValidLifetime = 0xffffffff;
}
DWORD err;
if (add) {
err = CreateUnicastIpAddressEntry(&row);
if (err != NO_ERROR && err != ERROR_OBJECT_ALREADY_EXISTS) {
@ -1121,20 +1121,27 @@ static int ethsock_ip_add_del(struct ethsock *sock, uint32_t ipaddr, uint32_t ip
goto out;
}
time_t beg = time_monotonic();
if (err != ERROR_OBJECT_ALREADY_EXISTS) {
/* Wait until the new IP has actually been added */
for (i = 0; i < 20; ++i) {
err = GetUnicastIpAddressEntry(&row);
if (err != NO_ERROR) {
win_perror2("GetUnicastIpAddressEntry", err);
goto out;
}
/*
while (bind(fd, (struct sockaddr*)&row.Address.Ipv4, sizeof(row.Address.Ipv4)) != 0) {
if ((time_monotonic() - beg) >= 5) {
fprintf(stderr, "Failed to bind after 5 seconds: ");
sock_perror("bind");
DeleteUnicastIpAddressEntry(&row);
if (row.DadState == IpDadStateTentative) {
Sleep(500);
} else {
break;
}
}
if (row.DadState != IpDadStatePreferred) {
fprintf(stderr, "Failed to add IP address (state=%d).\n", row.DadState);
goto out;
}
}
*/
} else {
err = DeleteUnicastIpAddressEntry(&row);
if (err != NO_ERROR) {