Skip to content
Snippets Groups Projects
Commit 91cd1e4c authored by Avi Kivity's avatar Avi Kivity
Browse files

osv_start_if: set address instead of adding a new one

SIOCAIFADDR appends an address to the interface's address list instead of
replacing it.  This causes 'ifconfig' to display 0.0.0.0 (the first address
configured) instead of the correct address obtained by dhcp.

Fix by also deleting the existing address, if it exists.
parent d9a5ed59
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
int osv_start_if(const char* if_name, const char* ip_addr, const char* mask_addr)
{
int error, success;
struct ifreq oldaddr;
struct in_aliasreq ifra;
struct bsd_sockaddr_in* addr = &ifra.ifra_addr;
struct bsd_sockaddr_in* mask = &ifra.ifra_mask;
......@@ -58,6 +59,11 @@ int osv_start_if(const char* if_name, const char* ip_addr, const char* mask_addr
broadcast->sin_addr.s_addr = (addr->sin_addr.s_addr &
mask->sin_addr.s_addr) |
~mask->sin_addr.s_addr ;
strncpy(oldaddr.ifr_name, if_name, IFNAMSIZ);
error = in_control(NULL, SIOCGIFADDR, (caddr_t)&oldaddr, ifp, NULL);
if (!error) {
in_control(NULL, SIOCDIFADDR, (caddr_t)&oldaddr, ifp, NULL);
}
error = in_control(NULL, SIOCAIFADDR, (caddr_t)&ifra, ifp, NULL);
out:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment