Windows bind() error fix (WIP)
This commit is contained in:
		
							parent
							
								
									9c7e7f1f80
								
							
						
					
					
						commit
						ca5fb06a84
					
				
					 1 changed files with 19 additions and 12 deletions
				
			
		
							
								
								
									
										29
									
								
								ethsock.c
									
										
									
									
									
								
							
							
						
						
									
										29
									
								
								ethsock.c
									
										
									
									
									
								
							|  | @ -1096,6 +1096,8 @@ 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)); | ||||||
| 
 | 
 | ||||||
|  | @ -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 */ | 			/* 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; | ||||||
|  | 				} | ||||||
| 
 | 
 | ||||||
| 		/*
 | 				if (row.DadState == IpDadStateTentative) { | ||||||
| 		while (bind(fd, (struct sockaddr*)&row.Address.Ipv4, sizeof(row.Address.Ipv4)) != 0) { | 					Sleep(500); | ||||||
| 			if ((time_monotonic() - beg) >= 5) { | 				} else { | ||||||
| 				fprintf(stderr, "Failed to bind after 5 seconds: "); | 					break; | ||||||
| 				sock_perror("bind"); | 				} | ||||||
| 				DeleteUnicastIpAddressEntry(&row); | 			} | ||||||
|  | 
 | ||||||
|  | 			if (row.DadState != IpDadStatePreferred) { | ||||||
|  | 				fprintf(stderr, "Failed to add IP address (state=%d).\n", row.DadState); | ||||||
| 				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