diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2001-10-22 16:23:33 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2001-10-22 16:23:33 +0400 |
commit | c270dc2555b88173abfd962036e99f986101158a (patch) | |
tree | 6c82fcbab6fa732b53ebc858ee54dcde5491ac9a | |
parent | 8b6234ca12393fdb9824a3ddd2dca5807804b75b (diff) |
* net.cc (get_2k_ifconf): Change multiple IP address naming scheme
to Linux style.
Patch by Alexander Gottwald <ago@informatik.tu-chemnitz.de>:
* net.cc (get_2k_ifconf): Added support for multiple IP addresses on
one interface.
-rw-r--r-- | winsup/cygwin/ChangeLog | 10 | ||||
-rw-r--r-- | winsup/cygwin/net.cc | 162 |
2 files changed, 98 insertions, 74 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 68ce1afa8..0b231e1b8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,15 @@ 2001-10-22 Corinna Vinschen <corinna@vinschen.de> + * net.cc (get_2k_ifconf): Change multiple IP address naming scheme + to Linux style. + +Sun Oct 21 19:04:37 2001 Alexander Gottwald <ago@informatik.tu-chemnitz.de> + + * net.cc (get_2k_ifconf): Added support for multiple IP addresses on + one interface. + +2001-10-22 Corinna Vinschen <corinna@vinschen.de> + * miscfuncs.cc (__check_invalid_read_ptr_errno): Return error, if any. 2001-10-21 Christopher Faylor <cgf@redhat.com> diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index c7c4650ef..9e2984f42 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -1551,7 +1551,7 @@ static void get_2k_ifconf (struct ifconf *ifc, int what) { int cnt = 0; - char eth[2] = "/", ppp[2] = "/", slp[2] = "/"; + char eth[2] = "/", ppp[2] = "/", slp[2] = "/", sub[2] = "0"; /* Union maps buffer to correct struct */ struct ifreq *ifr = ifc->ifc_req; @@ -1571,84 +1571,98 @@ get_2k_ifconf (struct ifconf *ifc, int what) !GetIfTable(ift, &siz_if_table, TRUE) && !GetIpAddrTable(ipt, &siz_ip_table, TRUE)) { + /* Iterate over all known interfaces */ for (if_cnt = 0; if_cnt < ift->dwNumEntries; ++if_cnt) - { - switch (ift->table[if_cnt].dwType) + { + *sub = '0'; + /* Iterate over all configured IP-addresses */ + for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) { - case MIB_IF_TYPE_ETHERNET: - ++*eth; - strcpy (ifr->ifr_name, "eth"); - strcat (ifr->ifr_name, eth); - break; - case MIB_IF_TYPE_PPP: - ++*ppp; - strcpy (ifr->ifr_name, "ppp"); - strcat (ifr->ifr_name, ppp); - break; - case MIB_IF_TYPE_SLIP: - ++*slp; - strcpy (ifr->ifr_name, "slp"); - strcat (ifr->ifr_name, slp); - break; - case MIB_IF_TYPE_LOOPBACK: - strcpy (ifr->ifr_name, "lo"); - break; - default: - continue; - } - for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) - if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex) - { - switch (what) - { - case SIOCGIFCONF: - case SIOCGIFADDR: - sa = (struct sockaddr_in *) &ifr->ifr_addr; - sa->sin_addr.s_addr = ipt->table[ip_cnt].dwAddr; - sa->sin_family = AF_INET; - sa->sin_port = 0; - break; - case SIOCGIFBRDADDR: - sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; + /* Does the IP address belong to the interface? */ + if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex) + { + /* Setup the interface name */ + switch (ift->table[if_cnt].dwType) + { + case MIB_IF_TYPE_ETHERNET: + if (*sub == '0') + ++*eth; + strcpy (ifr->ifr_name, "eth"); + strcat (ifr->ifr_name, eth); + break; + case MIB_IF_TYPE_PPP: + ++*ppp; + strcpy (ifr->ifr_name, "ppp"); + strcat (ifr->ifr_name, ppp); + break; + case MIB_IF_TYPE_SLIP: + ++*slp; + strcpy (ifr->ifr_name, "slp"); + strcat (ifr->ifr_name, slp); + break; + case MIB_IF_TYPE_LOOPBACK: + strcpy (ifr->ifr_name, "lo"); + break; + default: + continue; + } + if (*sub > '0') + { + strcat (ifr->ifr_name, ":"); + strcat (ifr->ifr_name, sub); + } + ++*sub; + /* setup sockaddr struct */ + switch (what) + { + case SIOCGIFCONF: + case SIOCGIFADDR: + sa = (struct sockaddr_in *) &ifr->ifr_addr; + sa->sin_addr.s_addr = ipt->table[ip_cnt].dwAddr; + sa->sin_family = AF_INET; + sa->sin_port = 0; + break; + case SIOCGIFBRDADDR: + sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; #if 0 - /* Unfortunately, the field returns only crap. */ - sa->sin_addr.s_addr = ipt->table[ip_cnt].dwBCastAddr; + /* Unfortunately, the field returns only crap. */ + sa->sin_addr.s_addr = ipt->table[ip_cnt].dwBCastAddr; #else - lip = ipt->table[ip_cnt].dwAddr; - lnp = ipt->table[ip_cnt].dwMask; - sa->sin_addr.s_addr = lip & lnp | ~lnp; - sa->sin_family = AF_INET; - sa->sin_port = 0; + lip = ipt->table[ip_cnt].dwAddr; + lnp = ipt->table[ip_cnt].dwMask; + sa->sin_addr.s_addr = lip & lnp | ~lnp; + sa->sin_family = AF_INET; + sa->sin_port = 0; #endif - break; - case SIOCGIFNETMASK: - sa = (struct sockaddr_in *) &ifr->ifr_netmask; - sa->sin_addr.s_addr = ipt->table[ip_cnt].dwMask; - sa->sin_family = AF_INET; - sa->sin_port = 0; - break; - case SIOCGIFHWADDR: - so = &ifr->ifr_hwaddr; - for (UINT i = 0; i < IFHWADDRLEN; ++i) - if (i >= ift->table[if_cnt].dwPhysAddrLen) - so->sa_data[i] = '\0'; - else - so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i]; - so->sa_family = AF_INET; - break; - case SIOCGIFMETRIC: - ifr->ifr_metric = 1; - break; - case SIOCGIFMTU: - ifr->ifr_mtu = ift->table[if_cnt].dwMtu; - break; - } - ++cnt; - if ((caddr_t) ++ifr > - ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq)) - goto done; - break; - } + break; + case SIOCGIFNETMASK: + sa = (struct sockaddr_in *) &ifr->ifr_netmask; + sa->sin_addr.s_addr = ipt->table[ip_cnt].dwMask; + sa->sin_family = AF_INET; + sa->sin_port = 0; + break; + case SIOCGIFHWADDR: + so = &ifr->ifr_hwaddr; + for (UINT i = 0; i < IFHWADDRLEN; ++i) + if (i >= ift->table[if_cnt].dwPhysAddrLen) + so->sa_data[i] = '\0'; + else + so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i]; + so->sa_family = AF_INET; + break; + case SIOCGIFMETRIC: + ifr->ifr_metric = 1; + break; + case SIOCGIFMTU: + ifr->ifr_mtu = ift->table[if_cnt].dwMtu; + break; + } + ++cnt; + if ((caddr_t) ++ifr > + ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq)) + goto done; + } + } } } done: |