diff options
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 630 |
1 files changed, 315 insertions, 315 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index bdf679d..04b30fd 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -55,7 +55,7 @@ public: ~wsock_event () { if (event) - WSACloseEvent (event); + WSACloseEvent (event); event = NULL; }; @@ -77,7 +77,7 @@ wsock_event::prepare () } else if (GetLastError () == ERROR_PROC_NOT_FOUND) /* winsock2 not available */ WSASetLastError (0); - + debug_printf ("%d = wsock_event::prepare ()", ret); return ret; } @@ -100,9 +100,9 @@ wsock_event::wait (int socket, LPDWORD flags) { debug_printf ("CancelIo() %E, fallback to blocking io"); WSAGetOverlappedResult(socket, &ovr, &len, TRUE, flags); - } + } else - WSASetLastError (WSAEINTR); + WSASetLastError (WSAEINTR); break; case WSA_WAIT_FAILED: break; @@ -470,7 +470,7 @@ static int get_inet_addr (const struct sockaddr *in, int inlen, char buf[128]; memset (buf, 0, sizeof buf); if (read (fd, buf, sizeof buf) != -1) - { + { sockaddr_in sin; sin.sin_family = AF_INET; sscanf (buf + strlen (SOCKET_COOKIE), "%hu %08x-%08x-%08x-%08x", @@ -481,7 +481,7 @@ static int get_inet_addr (const struct sockaddr *in, int inlen, *out = sin; *outlen = sizeof sin; ret = 1; - } + } _close (fd); return ret; } @@ -526,15 +526,15 @@ cygwin_sendto (int fd, WSABUF wsabuf = { len, (char *) buf }; DWORD ret = 0; if (WSASendTo (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags, - to, tolen, ovr, NULL) != SOCKET_ERROR) - res = ret; + to, tolen, ovr, NULL) != SOCKET_ERROR) + res = ret; else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } + { + set_winsock_errno (); + res = -1; + } else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); + set_winsock_errno (); } syscall_printf ("%d = sendto (%d, %x, %x, %x)", res, fd, buf, len, flags); @@ -561,7 +561,7 @@ cygwin_recvfrom (int fd, { debug_printf ("Fallback to winsock 1 recvfrom call"); if ((res = recvfrom (h->get_socket (), buf, len, flags, from, fromlen)) - == SOCKET_ERROR) + == SOCKET_ERROR) { set_winsock_errno (); res = -1; @@ -572,15 +572,15 @@ cygwin_recvfrom (int fd, WSABUF wsabuf = { len, (char *) buf }; DWORD ret = 0; if (WSARecvFrom (h->get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags, - from, fromlen, ovr, NULL) != SOCKET_ERROR) - res = ret; + from, fromlen, ovr, NULL) != SOCKET_ERROR) + res = ret; else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } + { + set_winsock_errno (); + res = -1; + } else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); + set_winsock_errno (); } syscall_printf ("%d = recvfrom (%d, %x, %x, %x)", res, fd, buf, len, flags); @@ -756,7 +756,7 @@ cygwin_connect (int fd, { res = connect (sock->get_socket (), (sockaddr *) &sin, namelen); if (res) - { + { /* Special handling for connect to return the correct error code when called to early on a non-blocking socket. */ if (WSAGetLastError () == WSAEWOULDBLOCK) @@ -766,37 +766,37 @@ cygwin_connect (int fd, } set_winsock_errno (); - } + } if (sock->get_addr_family () == AF_UNIX) - { - if (!res || in_progress) - { - if (!sock->create_secret_event (secret)) - { + { + if (!res || in_progress) + { + if (!sock->create_secret_event (secret)) + { secret_check_failed = TRUE; } else if (in_progress) sock->signal_secret_event (); - } + } - if (!secret_check_failed && !res) - { + if (!secret_check_failed && !res) + { if (!sock->check_peer_secret_event (&sin, secret)) { debug_printf ( "accept from unauthorized server" ); secret_check_failed = TRUE; } - } + } - if (secret_check_failed) - { + if (secret_check_failed) + { sock->close_secret_event (); - if (res) - closesocket (res); + if (res) + closesocket (res); set_errno (ECONNREFUSED); res = -1; - } - } + } + } } return res; } @@ -913,7 +913,7 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len) in_progress = TRUE; if (sock->get_addr_family () == AF_UNIX) - { + { if ((SOCKET) res != (SOCKET) INVALID_SOCKET || in_progress) { if (!sock->create_secret_event ()) @@ -923,25 +923,25 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len) } if (!secret_check_failed && - (SOCKET) res != (SOCKET) INVALID_SOCKET) - { + (SOCKET) res != (SOCKET) INVALID_SOCKET) + { if (!sock->check_peer_secret_event ((struct sockaddr_in*) peer)) { debug_printf ("connect from unauthorized client"); secret_check_failed = TRUE; - } - } - - if (secret_check_failed) - { - sock->close_secret_event (); - if ((SOCKET) res != (SOCKET) INVALID_SOCKET) - closesocket (res); + } + } + + if (secret_check_failed) + { + sock->close_secret_event (); + if ((SOCKET) res != (SOCKET) INVALID_SOCKET) + closesocket (res); set_errno (ECONNABORTED); - res = -1; - goto done; - } - } + res = -1; + goto done; + } + } SetResourceLock (LOCK_FD_LIST, WRITE_LOCK|READ_LOCK, "accept"); @@ -1020,11 +1020,11 @@ cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen) goto out; } - sock->set_connect_secret (); + sock->set_connect_secret (); char buf[sizeof (SOCKET_COOKIE) + 80]; __small_sprintf (buf, "%s%u ", SOCKET_COOKIE, sin.sin_port); - sock->get_connect_secret (strchr (buf, '\0')); + sock->get_connect_secret (strchr (buf, '\0')); len = strlen (buf) + 1; /* Note that the terminating nul is written. */ @@ -1158,14 +1158,14 @@ cygwin_herror (const char *s) switch (h_errno) { case NETDB_INTERNAL: - h_errstr = "Resolver internal error"; - break; + h_errstr = "Resolver internal error"; + break; case NETDB_SUCCESS: - h_errstr = "Resolver error 0 (no error)"; - break; + h_errstr = "Resolver error 0 (no error)"; + break; default: - h_errstr = "Unknown resolver error"; - break; + h_errstr = "Unknown resolver error"; + break; } write (2, h_errstr, strlen (h_errstr)); write (2, "\n", 1); @@ -1200,7 +1200,7 @@ cygwin_recv (int fd, void *buf, int len, unsigned int flags) { debug_printf ("Fallback to winsock 1 recv call"); if ((res = recv (h->get_socket (), (char *) buf, len, flags)) - == SOCKET_ERROR) + == SOCKET_ERROR) { set_winsock_errno (); res = -1; @@ -1252,15 +1252,15 @@ cygwin_send (int fd, const void *buf, int len, unsigned int flags) WSABUF wsabuf = { len, (char *) buf }; DWORD ret = 0; if (WSASend (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags, - ovr, NULL) != SOCKET_ERROR) - res = ret; + ovr, NULL) != SOCKET_ERROR) + res = ret; else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } + { + set_winsock_errno (); + res = -1; + } else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); + set_winsock_errno (); } syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags); @@ -1327,7 +1327,7 @@ get_2k_ifconf (struct ifconf *ifc, int what) !GetIpAddrTable(ipt, &siz_ip_table, TRUE)) { for (if_cnt = 0; if_cnt < ift->dwNumEntries; ++if_cnt) - { + { switch (ift->table[if_cnt].dwType) { case MIB_IF_TYPE_ETHERNET: @@ -1351,44 +1351,44 @@ get_2k_ifconf (struct ifconf *ifc, int what) default: continue; } - for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) - if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex) + 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; + 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; + 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; + 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; + 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; + 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; + break; case SIOCGIFHWADDR: - so = &ifr->ifr_hwaddr; + so = &ifr->ifr_hwaddr; for (UINT i = 0; i < IFHWADDRLEN; ++i) if (i >= ift->table[if_cnt].dwPhysAddrLen) - so->sa_data[i] = '\0'; + so->sa_data[i] = '\0'; else - so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i]; + so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i]; so->sa_family = AF_INET; break; case SIOCGIFMETRIC: @@ -1397,13 +1397,13 @@ get_2k_ifconf (struct ifconf *ifc, int what) case SIOCGIFMTU: ifr->ifr_mtu = ift->table[if_cnt].dwMtu; break; - } - ++cnt; - if ((caddr_t) ++ifr > + } + ++cnt; + if ((caddr_t) ++ifr > ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq)) goto done; - break; - } + break; + } } } done: @@ -1438,26 +1438,26 @@ get_nt_ifconf (struct ifconf *ifc, int what) struct ifreq *ifr = ifc->ifc_req; if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, - "SYSTEM\\" - "CurrentControlSet\\" - "Services\\" - "Tcpip\\" - "Linkage", - 0, KEY_READ, &key) == ERROR_SUCCESS) + "SYSTEM\\" + "CurrentControlSet\\" + "Services\\" + "Tcpip\\" + "Linkage", + 0, KEY_READ, &key) == ERROR_SUCCESS) { if (RegQueryValueEx (key, "Bind", - NULL, NULL, - NULL, &size) == ERROR_SUCCESS) - { - binding = (char *) alloca (size); - if (RegQueryValueEx (key, "Bind", - NULL, NULL, - (unsigned char *) binding, - &size) != ERROR_SUCCESS) - { - binding = NULL; - } - } + NULL, NULL, + NULL, &size) == ERROR_SUCCESS) + { + binding = (char *) alloca (size); + if (RegQueryValueEx (key, "Bind", + NULL, NULL, + (unsigned char *) binding, + &size) != ERROR_SUCCESS) + { + binding = NULL; + } + } RegCloseKey (key); } @@ -1467,141 +1467,141 @@ get_nt_ifconf (struct ifconf *ifc, int what) char cardkey[256], ipaddress[256], netmask[256]; for (bp = binding; *bp; bp += strlen (bp) + 1) - { - bp += strlen ("\\Device\\"); - strcpy (cardkey, "SYSTEM\\CurrentControlSet\\Services\\"); - strcat (cardkey, bp); - strcat (cardkey, "\\Parameters\\Tcpip"); - - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, cardkey, - 0, KEY_READ, &key) != ERROR_SUCCESS) - continue; - - if (RegQueryValueEx (key, "IPAddress", - NULL, NULL, - (unsigned char *) ipaddress, - (size = 256, &size)) == ERROR_SUCCESS - && RegQueryValueEx (key, "SubnetMask", - NULL, NULL, - (unsigned char *) netmask, - (size = 256, &size)) == ERROR_SUCCESS) - { - char *ip, *np; - char dhcpaddress[256], dhcpnetmask[256]; - - for (ip = ipaddress, np = netmask; - *ip && *np; - ip += strlen (ip) + 1, np += strlen (np) + 1) - { - if ((caddr_t) ++ifr > ifc->ifc_buf - + ifc->ifc_len - - sizeof (struct ifreq)) - break; - - if (! strncmp (bp, "NdisWan", 7)) - { - strcpy (ifr->ifr_name, "ppp"); - strcat (ifr->ifr_name, bp + 7); - } - else - { - ++*eth; - strcpy (ifr->ifr_name, "eth"); - strcat (ifr->ifr_name, eth); - } - memset (&ifr->ifr_addr, '\0', sizeof ifr->ifr_addr); - if (cygwin_inet_addr (ip) == 0L - && RegQueryValueEx (key, "DhcpIPAddress", - NULL, NULL, - (unsigned char *) dhcpaddress, - (size = 256, &size)) - == ERROR_SUCCESS - && RegQueryValueEx (key, "DhcpSubnetMask", - NULL, NULL, - (unsigned char *) dhcpnetmask, - (size = 256, &size)) - == ERROR_SUCCESS) - { - switch (what) - { - case SIOCGIFCONF: - case SIOCGIFADDR: - sa = (struct sockaddr_in *) &ifr->ifr_addr; - sa->sin_addr.s_addr = cygwin_inet_addr (dhcpaddress); + { + bp += strlen ("\\Device\\"); + strcpy (cardkey, "SYSTEM\\CurrentControlSet\\Services\\"); + strcat (cardkey, bp); + strcat (cardkey, "\\Parameters\\Tcpip"); + + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, cardkey, + 0, KEY_READ, &key) != ERROR_SUCCESS) + continue; + + if (RegQueryValueEx (key, "IPAddress", + NULL, NULL, + (unsigned char *) ipaddress, + (size = 256, &size)) == ERROR_SUCCESS + && RegQueryValueEx (key, "SubnetMask", + NULL, NULL, + (unsigned char *) netmask, + (size = 256, &size)) == ERROR_SUCCESS) + { + char *ip, *np; + char dhcpaddress[256], dhcpnetmask[256]; + + for (ip = ipaddress, np = netmask; + *ip && *np; + ip += strlen (ip) + 1, np += strlen (np) + 1) + { + if ((caddr_t) ++ifr > ifc->ifc_buf + + ifc->ifc_len + - sizeof (struct ifreq)) + break; + + if (! strncmp (bp, "NdisWan", 7)) + { + strcpy (ifr->ifr_name, "ppp"); + strcat (ifr->ifr_name, bp + 7); + } + else + { + ++*eth; + strcpy (ifr->ifr_name, "eth"); + strcat (ifr->ifr_name, eth); + } + memset (&ifr->ifr_addr, '\0', sizeof ifr->ifr_addr); + if (cygwin_inet_addr (ip) == 0L + && RegQueryValueEx (key, "DhcpIPAddress", + NULL, NULL, + (unsigned char *) dhcpaddress, + (size = 256, &size)) + == ERROR_SUCCESS + && RegQueryValueEx (key, "DhcpSubnetMask", + NULL, NULL, + (unsigned char *) dhcpnetmask, + (size = 256, &size)) + == ERROR_SUCCESS) + { + switch (what) + { + case SIOCGIFCONF: + case SIOCGIFADDR: + sa = (struct sockaddr_in *) &ifr->ifr_addr; + sa->sin_addr.s_addr = cygwin_inet_addr (dhcpaddress); sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFBRDADDR: - lip = cygwin_inet_addr (dhcpaddress); - lnp = cygwin_inet_addr (dhcpnetmask); - sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; - sa->sin_addr.s_addr = lip & lnp | ~lnp; + break; + case SIOCGIFBRDADDR: + lip = cygwin_inet_addr (dhcpaddress); + lnp = cygwin_inet_addr (dhcpnetmask); + sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; + sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFNETMASK: - sa = (struct sockaddr_in *) &ifr->ifr_netmask; - sa->sin_addr.s_addr = - cygwin_inet_addr (dhcpnetmask); + break; + case SIOCGIFNETMASK: + sa = (struct sockaddr_in *) &ifr->ifr_netmask; + sa->sin_addr.s_addr = + cygwin_inet_addr (dhcpnetmask); sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFHWADDR: + break; + case SIOCGIFHWADDR: so = &ifr->ifr_hwaddr; memset (so->sa_data, 0, IFHWADDRLEN); so->sa_family = AF_INET; break; - case SIOCGIFMETRIC: + case SIOCGIFMETRIC: ifr->ifr_metric = 1; break; case SIOCGIFMTU: ifr->ifr_mtu = 1500; break; - } - } - else - { - switch (what) - { - case SIOCGIFCONF: - case SIOCGIFADDR: - sa = (struct sockaddr_in *) &ifr->ifr_addr; - sa->sin_addr.s_addr = cygwin_inet_addr (ip); + } + } + else + { + switch (what) + { + case SIOCGIFCONF: + case SIOCGIFADDR: + sa = (struct sockaddr_in *) &ifr->ifr_addr; + sa->sin_addr.s_addr = cygwin_inet_addr (ip); sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFBRDADDR: - lip = cygwin_inet_addr (ip); - lnp = cygwin_inet_addr (np); - sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; - sa->sin_addr.s_addr = lip & lnp | ~lnp; + break; + case SIOCGIFBRDADDR: + lip = cygwin_inet_addr (ip); + lnp = cygwin_inet_addr (np); + sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; + sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFNETMASK: - sa = (struct sockaddr_in *) &ifr->ifr_netmask; - sa->sin_addr.s_addr = cygwin_inet_addr (np); + break; + case SIOCGIFNETMASK: + sa = (struct sockaddr_in *) &ifr->ifr_netmask; + sa->sin_addr.s_addr = cygwin_inet_addr (np); sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFHWADDR: + break; + case SIOCGIFHWADDR: so = &ifr->ifr_hwaddr; memset (so->sa_data, 0, IFHWADDRLEN); so->sa_family = AF_INET; break; - case SIOCGIFMETRIC: + case SIOCGIFMETRIC: ifr->ifr_metric = 1; break; case SIOCGIFMTU: ifr->ifr_mtu = 1500; break; - } - } - ++cnt; - } - } - RegCloseKey (key); - } + } + } + ++cnt; + } + } + RegCloseKey (key); + } } /* Set the correct length */ @@ -1644,7 +1644,7 @@ get_95_ifconf (struct ifconf *ifc, int what) struct ifreq *ifr = ifc->ifc_req; if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Enum\\Network\\MSTCP", - 0, KEY_READ, &key) != ERROR_SUCCESS) + 0, KEY_READ, &key) != ERROR_SUCCESS) { /* Set the correct length */ ifc->ifc_len = cnt * sizeof (struct ifreq); @@ -1653,8 +1653,8 @@ get_95_ifconf (struct ifconf *ifc, int what) for (int i = 0; (res = RegEnumKeyEx (key, i, ifname, - (size = sizeof ifname, &size), - 0, 0, 0, &update)) != ERROR_NO_MORE_ITEMS; + (size = sizeof ifname, &size), + 0, 0, 0, &update)) != ERROR_NO_MORE_ITEMS; ++i) { HKEY ifkey, subkey; @@ -1662,62 +1662,62 @@ get_95_ifconf (struct ifconf *ifc, int what) char adapter[256], ip[256], np[256]; if (res != ERROR_SUCCESS - || RegOpenKeyEx (key, ifname, 0, - KEY_READ, &ifkey) != ERROR_SUCCESS) - continue; + || RegOpenKeyEx (key, ifname, 0, + KEY_READ, &ifkey) != ERROR_SUCCESS) + continue; if (RegQueryValueEx (ifkey, "Driver", 0, - NULL, (unsigned char *) driver, - (size = sizeof driver, &size)) != ERROR_SUCCESS) - { - RegCloseKey (ifkey); - continue; - } + NULL, (unsigned char *) driver, + (size = sizeof driver, &size)) != ERROR_SUCCESS) + { + RegCloseKey (ifkey); + continue; + } strcpy (classname, "System\\CurrentControlSet\\Services\\Class\\"); strcat (classname, driver); if ((res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, classname, - 0, KEY_READ, &subkey)) != ERROR_SUCCESS) - { - RegCloseKey (ifkey); - continue; - } + 0, KEY_READ, &subkey)) != ERROR_SUCCESS) + { + RegCloseKey (ifkey); + continue; + } if (RegQueryValueEx (subkey, "IPAddress", 0, - NULL, (unsigned char *) ip, - (size = sizeof ip, &size)) == ERROR_SUCCESS - && RegQueryValueEx (subkey, "IPMask", 0, - NULL, (unsigned char *) np, - (size = sizeof np, &size)) == ERROR_SUCCESS) - { - if ((caddr_t)++ifr > ifc->ifc_buf - + ifc->ifc_len - - sizeof (struct ifreq)) - goto out; - - switch (what) - { - case SIOCGIFCONF: - case SIOCGIFADDR: - sa = (struct sockaddr_in *) &ifr->ifr_addr; - sa->sin_addr.s_addr = cygwin_inet_addr (ip); + NULL, (unsigned char *) ip, + (size = sizeof ip, &size)) == ERROR_SUCCESS + && RegQueryValueEx (subkey, "IPMask", 0, + NULL, (unsigned char *) np, + (size = sizeof np, &size)) == ERROR_SUCCESS) + { + if ((caddr_t)++ifr > ifc->ifc_buf + + ifc->ifc_len + - sizeof (struct ifreq)) + goto out; + + switch (what) + { + case SIOCGIFCONF: + case SIOCGIFADDR: + sa = (struct sockaddr_in *) &ifr->ifr_addr; + sa->sin_addr.s_addr = cygwin_inet_addr (ip); sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFBRDADDR: - lip = cygwin_inet_addr (ip); - lnp = cygwin_inet_addr (np); - sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; - sa->sin_addr.s_addr = lip & lnp | ~lnp; + break; + case SIOCGIFBRDADDR: + lip = cygwin_inet_addr (ip); + lnp = cygwin_inet_addr (np); + sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; + sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_family = AF_INET; sa->sin_port = 0; - break; - case SIOCGIFNETMASK: - sa = (struct sockaddr_in *) &ifr->ifr_netmask; - sa->sin_addr.s_addr = cygwin_inet_addr (np); + break; + case SIOCGIFNETMASK: + sa = (struct sockaddr_in *) &ifr->ifr_netmask; + sa->sin_addr.s_addr = cygwin_inet_addr (np); sa->sin_family = AF_INET; sa->sin_port = 0; - break; + break; case SIOCGIFHWADDR: so = &ifr->ifr_hwaddr; memset (so->sa_data, 0, IFHWADDRLEN); @@ -1729,61 +1729,61 @@ get_95_ifconf (struct ifconf *ifc, int what) case SIOCGIFMTU: ifr->ifr_mtu = 1500; break; - } - } + } + } RegCloseKey (subkey); if (RegOpenKeyEx (ifkey, "Bindings", - 0, KEY_READ, &subkey) != ERROR_SUCCESS) - { - RegCloseKey (ifkey); - --ifr; - continue; - } + 0, KEY_READ, &subkey) != ERROR_SUCCESS) + { + RegCloseKey (ifkey); + --ifr; + continue; + } for (int j = 0; - (res = RegEnumValue (subkey, j, bindname, - (size = sizeof bindname, &size), - 0, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS; - ++j) - if (!strncasecmp (bindname, "VREDIR\\", 7)) - break; + (res = RegEnumValue (subkey, j, bindname, + (size = sizeof bindname, &size), + 0, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS; + ++j) + if (!strncasecmp (bindname, "VREDIR\\", 7)) + break; RegCloseKey (subkey); if (res == ERROR_SUCCESS) - { - strcpy (netname, "System\\CurrentControlSet\\Services\\Class\\Net\\"); - strcat (netname, bindname + 7); - - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, netname, - 0, KEY_READ, &subkey) != ERROR_SUCCESS) - { - RegCloseKey (ifkey); - --ifr; - continue; - } - - if (RegQueryValueEx (subkey, "AdapterName", 0, - NULL, (unsigned char *) adapter, - (size = sizeof adapter, &size)) == ERROR_SUCCESS - && strcasematch (adapter, "MS$PPP")) - { - ++*ppp; - strcpy (ifr->ifr_name, "ppp"); - strcat (ifr->ifr_name, ppp); - } - else - { - ++*eth; - strcpy (ifr->ifr_name, "eth"); - strcat (ifr->ifr_name, eth); - } - - RegCloseKey (subkey); - - } + { + strcpy (netname, "System\\CurrentControlSet\\Services\\Class\\Net\\"); + strcat (netname, bindname + 7); + + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, netname, + 0, KEY_READ, &subkey) != ERROR_SUCCESS) + { + RegCloseKey (ifkey); + --ifr; + continue; + } + + if (RegQueryValueEx (subkey, "AdapterName", 0, + NULL, (unsigned char *) adapter, + (size = sizeof adapter, &size)) == ERROR_SUCCESS + && strcasematch (adapter, "MS$PPP")) + { + ++*ppp; + strcpy (ifr->ifr_name, "ppp"); + strcat (ifr->ifr_name, ppp); + } + else + { + ++*eth; + strcpy (ifr->ifr_name, "eth"); + strcat (ifr->ifr_name, eth); + } + + RegCloseKey (subkey); + + } RegCloseKey (ifkey); @@ -1863,14 +1863,14 @@ get_ifconf (struct ifconf *ifc, int what) /* We have a win95 version... */ if (os_version_info.dwPlatformId != VER_PLATFORM_WIN32_NT && (os_version_info.dwMajorVersion < 4 - || (os_version_info.dwMajorVersion == 4 - && os_version_info.dwMinorVersion == 0))) + || (os_version_info.dwMajorVersion == 4 + && os_version_info.dwMinorVersion == 0))) get_95_ifconf (ifc, what); /* ...and a NT <= SP3 version... */ else if (os_version_info.dwPlatformId == VER_PLATFORM_WIN32_NT - && (os_version_info.dwMajorVersion < 4 + && (os_version_info.dwMajorVersion < 4 || (os_version_info.dwMajorVersion == 4 - && strcmp (os_version_info.szCSDVersion, "Service Pack 4") < 0))) + && strcmp (os_version_info.szCSDVersion, "Service Pack 4") < 0))) get_nt_ifconf (ifc, what); /* ...and finally a "modern" version for win98/ME, NT >= SP4 and W2K! */ else |