Windows bind() error fix (WIP)
This commit is contained in:
parent
9c7e7f1f80
commit
ca5fb06a84
1 changed files with 19 additions and 12 deletions
31
ethsock.c
31
ethsock.c
|
@ -1096,13 +1096,15 @@ static int ethsock_ip_add_del(struct ethsock *sock, uint32_t ipaddr, uint32_t ip
|
||||||
#endif
|
#endif
|
||||||
#else // NMRPFLASH_WINDOWS
|
#else // NMRPFLASH_WINDOWS
|
||||||
MIB_UNICASTIPADDRESS_ROW row;
|
MIB_UNICASTIPADDRESS_ROW row;
|
||||||
|
DWORD err;
|
||||||
|
int i;
|
||||||
|
|
||||||
memset(&row, 0, sizeof(row));
|
memset(&row, 0, sizeof(row));
|
||||||
|
|
||||||
row.InterfaceIndex = sock->index;
|
row.InterfaceIndex = sock->index;
|
||||||
set_addr(&row.Address.Ipv4, ipaddr);
|
set_addr(&row.Address.Ipv4, ipaddr);
|
||||||
row.Address.si_family = AF_INET;
|
row.Address.si_family = AF_INET;
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
row.PrefixOrigin = IpPrefixOriginManual;
|
row.PrefixOrigin = IpPrefixOriginManual;
|
||||||
row.SuffixOrigin = IpPrefixOriginManual;
|
row.SuffixOrigin = IpPrefixOriginManual;
|
||||||
|
@ -1112,8 +1114,6 @@ static int ethsock_ip_add_del(struct ethsock *sock, uint32_t ipaddr, uint32_t ip
|
||||||
row.ValidLifetime = 0xffffffff;
|
row.ValidLifetime = 0xffffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD err;
|
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
err = CreateUnicastIpAddressEntry(&row);
|
err = CreateUnicastIpAddressEntry(&row);
|
||||||
if (err != NO_ERROR && err != ERROR_OBJECT_ALREADY_EXISTS) {
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait until the new IP has actually been added */
|
if (row.DadState == IpDadStateTentative) {
|
||||||
|
Sleep(500);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
if (row.DadState != IpDadStatePreferred) {
|
||||||
while (bind(fd, (struct sockaddr*)&row.Address.Ipv4, sizeof(row.Address.Ipv4)) != 0) {
|
fprintf(stderr, "Failed to add IP address (state=%d).\n", row.DadState);
|
||||||
if ((time_monotonic() - beg) >= 5) {
|
|
||||||
fprintf(stderr, "Failed to bind after 5 seconds: ");
|
|
||||||
sock_perror("bind");
|
|
||||||
DeleteUnicastIpAddressEntry(&row);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
err = DeleteUnicastIpAddressEntry(&row);
|
err = DeleteUnicastIpAddressEntry(&row);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue