* net.cc: Run indent.
* autoload.cc (GetIfEntry): Add symbol. * net.cc (get_2k_ifconf): Get the interface entries with the GetIfEntry call intead of the GetIfTable call. Clean-up multiple IP address naming.
This commit is contained in:
parent
5d7bffe927
commit
7922485391
|
@ -1,3 +1,13 @@
|
||||||
|
2002-11-10 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* net.cc: Run indent.
|
||||||
|
|
||||||
|
2002-11-10 Alexander Gottwald <Alexander.Gottwald@s1999.tu-chemnitz.de>
|
||||||
|
|
||||||
|
* autoload.cc (GetIfEntry): Add symbol.
|
||||||
|
* net.cc (get_2k_ifconf): Get the interface entries with the GetIfEntry
|
||||||
|
call intead of the GetIfTable call. Clean-up multiple IP address naming.
|
||||||
|
|
||||||
2002-11-09 Sergey Okhapkin <sos@prospect.com.ru>
|
2002-11-09 Sergey Okhapkin <sos@prospect.com.ru>
|
||||||
|
|
||||||
* fhandler.h (class fhandler_pipe): New ioctl() method.
|
* fhandler.h (class fhandler_pipe): New ioctl() method.
|
||||||
|
|
|
@ -485,6 +485,7 @@ LoadDLLfuncEx (WSAEventSelect, 12, ws2_32, 1)
|
||||||
LoadDLLfuncEx (WSAEnumNetworkEvents, 12, ws2_32, 1)
|
LoadDLLfuncEx (WSAEnumNetworkEvents, 12, ws2_32, 1)
|
||||||
|
|
||||||
LoadDLLfuncEx (GetIfTable, 12, iphlpapi, 1)
|
LoadDLLfuncEx (GetIfTable, 12, iphlpapi, 1)
|
||||||
|
LoadDLLfuncEx (GetIfEntry, 4, iphlpapi, 1)
|
||||||
LoadDLLfuncEx (GetIpAddrTable, 12, iphlpapi, 1)
|
LoadDLLfuncEx (GetIpAddrTable, 12, iphlpapi, 1)
|
||||||
|
|
||||||
LoadDLLfunc (CoInitialize, 4, ole32)
|
LoadDLLfunc (CoInitialize, 4, ole32)
|
||||||
|
|
|
@ -34,15 +34,16 @@ details. */
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
#include "wsock_event.h"
|
#include "wsock_event.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C"
|
||||||
int h_errno;
|
{
|
||||||
|
int h_errno;
|
||||||
|
|
||||||
int __stdcall rcmd (char **ahost, unsigned short inport, char *locuser,
|
int __stdcall rcmd (char **ahost, unsigned short inport, char *locuser,
|
||||||
char *remuser, char *cmd, SOCKET *fd2p);
|
char *remuser, char *cmd, SOCKET * fd2p);
|
||||||
int __stdcall rexec (char **ahost, unsigned short inport, char *locuser,
|
int __stdcall rexec (char **ahost, unsigned short inport, char *locuser,
|
||||||
char *password, char *cmd, SOCKET *fd2p);
|
char *password, char *cmd, SOCKET * fd2p);
|
||||||
int __stdcall rresvport (int *);
|
int __stdcall rresvport (int *);
|
||||||
int sscanf (const char *, const char *, ...);
|
int sscanf (const char *, const char *, ...);
|
||||||
} /* End of "C" section */
|
} /* End of "C" section */
|
||||||
|
|
||||||
LPWSAOVERLAPPED
|
LPWSAOVERLAPPED
|
||||||
|
@ -78,7 +79,7 @@ wsock_event::wait (int socket, LPDWORD flags)
|
||||||
ret = (int) len;
|
ret = (int) len;
|
||||||
break;
|
break;
|
||||||
case WSA_WAIT_EVENT_0 + 1:
|
case WSA_WAIT_EVENT_0 + 1:
|
||||||
if (!CancelIo ((HANDLE)socket))
|
if (!CancelIo ((HANDLE) socket))
|
||||||
{
|
{
|
||||||
debug_printf ("CancelIo() %E, fallback to blocking io");
|
debug_printf ("CancelIo() %E, fallback to blocking io");
|
||||||
WSAGetOverlappedResult (socket, &ovr, &len, TRUE, flags);
|
WSAGetOverlappedResult (socket, &ovr, &len, TRUE, flags);
|
||||||
|
@ -104,10 +105,12 @@ static fhandler_socket *
|
||||||
get (const int fd)
|
get (const int fd)
|
||||||
{
|
{
|
||||||
cygheap_fdget cfd (fd);
|
cygheap_fdget cfd (fd);
|
||||||
|
|
||||||
if (cfd < 0)
|
if (cfd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fhandler_socket *const fh = cfd->is_socket ();
|
fhandler_socket *const fh = cfd->is_socket ();
|
||||||
|
|
||||||
if (!fh)
|
if (!fh)
|
||||||
set_errno (ENOTSOCK);
|
set_errno (ENOTSOCK);
|
||||||
|
|
||||||
|
@ -119,6 +122,7 @@ static SOCKET __stdcall
|
||||||
set_socket_inheritance (SOCKET sock)
|
set_socket_inheritance (SOCKET sock)
|
||||||
{
|
{
|
||||||
SOCKET osock = sock;
|
SOCKET osock = sock;
|
||||||
|
|
||||||
if (!DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &sock,
|
if (!DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &sock,
|
||||||
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
|
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
|
||||||
system_printf ("DuplicateHandle failed %E");
|
system_printf ("DuplicateHandle failed %E");
|
||||||
|
@ -178,6 +182,7 @@ cygwin_inet_ntoa (struct in_addr in)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *res = inet_ntoa (in);
|
char *res = inet_ntoa (in);
|
||||||
|
|
||||||
if (ntoa_buf)
|
if (ntoa_buf)
|
||||||
{
|
{
|
||||||
free (ntoa_buf);
|
free (ntoa_buf);
|
||||||
|
@ -195,6 +200,7 @@ cygwin_inet_addr (const char *cp)
|
||||||
if (check_null_str_errno (cp))
|
if (check_null_str_errno (cp))
|
||||||
return INADDR_NONE;
|
return INADDR_NONE;
|
||||||
unsigned long res = inet_addr (cp);
|
unsigned long res = inet_addr (cp);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +214,7 @@ cygwin_inet_aton (const char *cp, struct in_addr *inp)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
unsigned long res = inet_addr (cp);
|
unsigned long res = inet_addr (cp);
|
||||||
|
|
||||||
if (res == INADDR_NONE && strcmp (cp, "255.255.255.255"))
|
if (res == INADDR_NONE && strcmp (cp, "255.255.255.255"))
|
||||||
return 0;
|
return 0;
|
||||||
if (inp)
|
if (inp)
|
||||||
|
@ -224,6 +231,7 @@ cygwin_inet_network (const char *cp)
|
||||||
if (check_null_str_errno (cp))
|
if (check_null_str_errno (cp))
|
||||||
return INADDR_NONE;
|
return INADDR_NONE;
|
||||||
unsigned int res = inet_network (cp);
|
unsigned int res = inet_network (cp);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,8 +288,7 @@ struct tl
|
||||||
int e;
|
int e;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NO_COPY struct tl errmap[] =
|
static NO_COPY struct tl errmap[] = {
|
||||||
{
|
|
||||||
{WSAEINTR, "WSAEINTR", EINTR},
|
{WSAEINTR, "WSAEINTR", EINTR},
|
||||||
{WSAEWOULDBLOCK, "WSAEWOULDBLOCK", EWOULDBLOCK},
|
{WSAEWOULDBLOCK, "WSAEWOULDBLOCK", EWOULDBLOCK},
|
||||||
{WSAEINPROGRESS, "WSAEINPROGRESS", EINPROGRESS},
|
{WSAEINPROGRESS, "WSAEINPROGRESS", EINPROGRESS},
|
||||||
|
@ -342,6 +349,7 @@ __set_winsock_errno (const char *fn, int ln)
|
||||||
{
|
{
|
||||||
DWORD werr = WSAGetLastError ();
|
DWORD werr = WSAGetLastError ();
|
||||||
int err = find_winsock_errno (werr);
|
int err = find_winsock_errno (werr);
|
||||||
|
|
||||||
set_errno (err);
|
set_errno (err);
|
||||||
syscall_printf ("%s:%d - winsock error %d -> errno %d", fn, ln, werr, err);
|
syscall_printf ("%s:%d - winsock error %d -> errno %d", fn, ln, werr, err);
|
||||||
}
|
}
|
||||||
|
@ -350,8 +358,7 @@ __set_winsock_errno (const char *fn, int ln)
|
||||||
* Since the member `s' isn't used for debug output we can use it
|
* Since the member `s' isn't used for debug output we can use it
|
||||||
* for the error text returned by herror and hstrerror.
|
* for the error text returned by herror and hstrerror.
|
||||||
*/
|
*/
|
||||||
static NO_COPY struct tl host_errmap[] =
|
static NO_COPY struct tl host_errmap[] = {
|
||||||
{
|
|
||||||
{WSAHOST_NOT_FOUND, "Unknown host", HOST_NOT_FOUND},
|
{WSAHOST_NOT_FOUND, "Unknown host", HOST_NOT_FOUND},
|
||||||
{WSATRY_AGAIN, "Host name lookup failure", TRY_AGAIN},
|
{WSATRY_AGAIN, "Host name lookup failure", TRY_AGAIN},
|
||||||
{WSANO_RECOVERY, "Unknown server error", NO_RECOVERY},
|
{WSANO_RECOVERY, "Unknown server error", NO_RECOVERY},
|
||||||
|
@ -366,6 +373,7 @@ set_host_errno ()
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
int why = WSAGetLastError ();
|
int why = WSAGetLastError ();
|
||||||
|
|
||||||
for (i = 0; host_errmap[i].w != 0; ++i)
|
for (i = 0; host_errmap[i].w != 0; ++i)
|
||||||
if (why == host_errmap[i].w)
|
if (why == host_errmap[i].w)
|
||||||
break;
|
break;
|
||||||
|
@ -445,6 +453,7 @@ dup_protoent_ptr (struct protoent *src)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct protoent *dst = (struct protoent *) calloc (1, sizeof *dst);
|
struct protoent *dst = (struct protoent *) calloc (1, sizeof *dst);
|
||||||
|
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -468,7 +477,7 @@ out:
|
||||||
#ifdef _MT_SAFE
|
#ifdef _MT_SAFE
|
||||||
#define protoent_buf _reent_winsup ()->_protoent_buf
|
#define protoent_buf _reent_winsup ()->_protoent_buf
|
||||||
#else
|
#else
|
||||||
static struct protoent *protoent_buf = NULL;
|
static struct protoent *protoent_buf = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* exported as getprotobyname: standards? */
|
/* exported as getprotobyname: standards? */
|
||||||
|
@ -500,19 +509,22 @@ cygwin_getprotobynumber (int number)
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandler_socket *
|
fhandler_socket *
|
||||||
fdsock (int& fd, const char *name, SOCKET soc)
|
fdsock (int &fd, const char *name, SOCKET soc)
|
||||||
{
|
{
|
||||||
if (!winsock2_active)
|
if (!winsock2_active)
|
||||||
soc = set_socket_inheritance (soc);
|
soc = set_socket_inheritance (soc);
|
||||||
else if (wincap.has_set_handle_information ())
|
else if (wincap.has_set_handle_information ())
|
||||||
{
|
{
|
||||||
/* NT systems apparently set sockets to inheritable by default */
|
/* NT systems apparently set sockets to inheritable by default */
|
||||||
SetHandleInformation ((HANDLE)soc, HANDLE_FLAG_INHERIT, 0);
|
SetHandleInformation ((HANDLE) soc, HANDLE_FLAG_INHERIT, 0);
|
||||||
debug_printf ("reset socket inheritance since winsock2_active %d", winsock2_active);
|
debug_printf ("reset socket inheritance since winsock2_active %d",
|
||||||
|
winsock2_active);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_printf ("not setting socket inheritance since winsock2_active %d", winsock2_active);
|
debug_printf ("not setting socket inheritance since winsock2_active %d",
|
||||||
fhandler_socket *fh = (fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name);
|
winsock2_active);
|
||||||
|
fhandler_socket *fh =
|
||||||
|
(fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name);
|
||||||
fh->set_io_handle ((HANDLE) soc);
|
fh->set_io_handle ((HANDLE) soc);
|
||||||
fh->set_flags (O_RDWR | O_BINARY);
|
fh->set_flags (O_RDWR | O_BINARY);
|
||||||
fh->set_r_no_interrupt (winsock2_active);
|
fh->set_r_no_interrupt (winsock2_active);
|
||||||
|
@ -526,7 +538,7 @@ cygwin_socket (int af, int type, int protocol)
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
SOCKET soc = 0;
|
SOCKET soc = 0;
|
||||||
fhandler_socket* fh = NULL;
|
fhandler_socket *fh = NULL;
|
||||||
|
|
||||||
cygheap_fdnew fd;
|
cygheap_fdnew fd;
|
||||||
|
|
||||||
|
@ -543,6 +555,7 @@ cygwin_socket (int af, int type, int protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (af == AF_INET)
|
if (af == AF_INET)
|
||||||
name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp");
|
name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp");
|
||||||
else
|
else
|
||||||
|
@ -573,7 +586,7 @@ cygwin_sendto (int fd, const void *buf, int len, int flags,
|
||||||
fhandler_socket *fh = get (fd);
|
fhandler_socket *fh = get (fd);
|
||||||
|
|
||||||
if ((len && __check_invalid_read_ptr_errno (buf, (unsigned) len))
|
if ((len && __check_invalid_read_ptr_errno (buf, (unsigned) len))
|
||||||
|| (to &&__check_invalid_read_ptr_errno (to, tolen))
|
|| (to && __check_invalid_read_ptr_errno (to, tolen))
|
||||||
|| !fh)
|
|| !fh)
|
||||||
res = -1;
|
res = -1;
|
||||||
else if ((res = len) != 0)
|
else if ((res = len) != 0)
|
||||||
|
@ -598,7 +611,7 @@ cygwin_recvfrom (int fd, void *buf, int len, int flags,
|
||||||
if ((len && __check_null_invalid_struct_errno (buf, (unsigned) len))
|
if ((len && __check_null_invalid_struct_errno (buf, (unsigned) len))
|
||||||
|| (from
|
|| (from
|
||||||
&& (check_null_invalid_struct_errno (fromlen)
|
&& (check_null_invalid_struct_errno (fromlen)
|
||||||
||__check_null_invalid_struct_errno (from, (unsigned) *fromlen)))
|
|| __check_null_invalid_struct_errno (from, (unsigned) *fromlen)))
|
||||||
|| !fh)
|
|| !fh)
|
||||||
res = -1;
|
res = -1;
|
||||||
else if ((res = len) != 0)
|
else if ((res = len) != 0)
|
||||||
|
@ -623,34 +636,34 @@ cygwin_setsockopt (int fd, int level, int optname, const void *optval,
|
||||||
switch (optname)
|
switch (optname)
|
||||||
{
|
{
|
||||||
case SO_DEBUG:
|
case SO_DEBUG:
|
||||||
name="SO_DEBUG";
|
name = "SO_DEBUG";
|
||||||
break;
|
break;
|
||||||
case SO_ACCEPTCONN:
|
case SO_ACCEPTCONN:
|
||||||
name="SO_ACCEPTCONN";
|
name = "SO_ACCEPTCONN";
|
||||||
break;
|
break;
|
||||||
case SO_REUSEADDR:
|
case SO_REUSEADDR:
|
||||||
name="SO_REUSEADDR";
|
name = "SO_REUSEADDR";
|
||||||
break;
|
break;
|
||||||
case SO_KEEPALIVE:
|
case SO_KEEPALIVE:
|
||||||
name="SO_KEEPALIVE";
|
name = "SO_KEEPALIVE";
|
||||||
break;
|
break;
|
||||||
case SO_DONTROUTE:
|
case SO_DONTROUTE:
|
||||||
name="SO_DONTROUTE";
|
name = "SO_DONTROUTE";
|
||||||
break;
|
break;
|
||||||
case SO_BROADCAST:
|
case SO_BROADCAST:
|
||||||
name="SO_BROADCAST";
|
name = "SO_BROADCAST";
|
||||||
break;
|
break;
|
||||||
case SO_USELOOPBACK:
|
case SO_USELOOPBACK:
|
||||||
name="SO_USELOOPBACK";
|
name = "SO_USELOOPBACK";
|
||||||
break;
|
break;
|
||||||
case SO_LINGER:
|
case SO_LINGER:
|
||||||
name="SO_LINGER";
|
name = "SO_LINGER";
|
||||||
break;
|
break;
|
||||||
case SO_OOBINLINE:
|
case SO_OOBINLINE:
|
||||||
name="SO_OOBINLINE";
|
name = "SO_OOBINLINE";
|
||||||
break;
|
break;
|
||||||
case SO_ERROR:
|
case SO_ERROR:
|
||||||
name="SO_ERROR";
|
name = "SO_ERROR";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,34 +698,34 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
|
||||||
switch (optname)
|
switch (optname)
|
||||||
{
|
{
|
||||||
case SO_DEBUG:
|
case SO_DEBUG:
|
||||||
name="SO_DEBUG";
|
name = "SO_DEBUG";
|
||||||
break;
|
break;
|
||||||
case SO_ACCEPTCONN:
|
case SO_ACCEPTCONN:
|
||||||
name="SO_ACCEPTCONN";
|
name = "SO_ACCEPTCONN";
|
||||||
break;
|
break;
|
||||||
case SO_REUSEADDR:
|
case SO_REUSEADDR:
|
||||||
name="SO_REUSEADDR";
|
name = "SO_REUSEADDR";
|
||||||
break;
|
break;
|
||||||
case SO_KEEPALIVE:
|
case SO_KEEPALIVE:
|
||||||
name="SO_KEEPALIVE";
|
name = "SO_KEEPALIVE";
|
||||||
break;
|
break;
|
||||||
case SO_DONTROUTE:
|
case SO_DONTROUTE:
|
||||||
name="SO_DONTROUTE";
|
name = "SO_DONTROUTE";
|
||||||
break;
|
break;
|
||||||
case SO_BROADCAST:
|
case SO_BROADCAST:
|
||||||
name="SO_BROADCAST";
|
name = "SO_BROADCAST";
|
||||||
break;
|
break;
|
||||||
case SO_USELOOPBACK:
|
case SO_USELOOPBACK:
|
||||||
name="SO_USELOOPBACK";
|
name = "SO_USELOOPBACK";
|
||||||
break;
|
break;
|
||||||
case SO_LINGER:
|
case SO_LINGER:
|
||||||
name="SO_LINGER";
|
name = "SO_LINGER";
|
||||||
break;
|
break;
|
||||||
case SO_OOBINLINE:
|
case SO_OOBINLINE:
|
||||||
name="SO_OOBINLINE";
|
name = "SO_OOBINLINE";
|
||||||
break;
|
break;
|
||||||
case SO_ERROR:
|
case SO_ERROR:
|
||||||
name="SO_ERROR";
|
name = "SO_ERROR";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,6 +742,7 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
|
||||||
if (optname == SO_ERROR)
|
if (optname == SO_ERROR)
|
||||||
{
|
{
|
||||||
int *e = (int *) optval;
|
int *e = (int *) optval;
|
||||||
|
|
||||||
*e = find_winsock_errno (*e);
|
*e = find_winsock_errno (*e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,6 +798,7 @@ struct pservent
|
||||||
short s_port;
|
short s_port;
|
||||||
char *s_proto;
|
char *s_proto;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
static struct servent *
|
static struct servent *
|
||||||
dup_servent_ptr (struct servent *src)
|
dup_servent_ptr (struct servent *src)
|
||||||
|
@ -792,6 +807,7 @@ dup_servent_ptr (struct servent *src)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct servent *dst = (struct servent *) calloc (1, sizeof *dst);
|
struct servent *dst = (struct servent *) calloc (1, sizeof *dst);
|
||||||
|
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -803,9 +819,10 @@ dup_servent_ptr (struct servent *src)
|
||||||
if (src->s_aliases && !(dst->s_aliases = dup_char_list (src->s_aliases)))
|
if (src->s_aliases && !(dst->s_aliases = dup_char_list (src->s_aliases)))
|
||||||
goto out;
|
goto out;
|
||||||
char *s_proto;
|
char *s_proto;
|
||||||
|
|
||||||
if (IsBadReadPtr (src->s_proto, sizeof (src->s_proto))
|
if (IsBadReadPtr (src->s_proto, sizeof (src->s_proto))
|
||||||
&& !IsBadReadPtr (((pservent *) src)->s_proto, sizeof (src->s_proto)))
|
&& !IsBadReadPtr (((pservent *) src)->s_proto, sizeof (src->s_proto)))
|
||||||
s_proto = ((pservent *)src)->s_proto;
|
s_proto = ((pservent *) src)->s_proto;
|
||||||
else
|
else
|
||||||
s_proto = src->s_proto;
|
s_proto = src->s_proto;
|
||||||
|
|
||||||
|
@ -824,7 +841,7 @@ out:
|
||||||
#ifdef _MT_SAFE
|
#ifdef _MT_SAFE
|
||||||
#define servent_buf _reent_winsup ()->_servent_buf
|
#define servent_buf _reent_winsup ()->_servent_buf
|
||||||
#else
|
#else
|
||||||
static struct servent *servent_buf = NULL;
|
static struct servent *servent_buf = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* exported as getservbyname: standards? */
|
/* exported as getservbyname: standards? */
|
||||||
|
@ -863,13 +880,12 @@ cygwin_getservbyport (int port, const char *proto)
|
||||||
extern "C" int
|
extern "C" int
|
||||||
cygwin_gethostname (char *name, size_t len)
|
cygwin_gethostname (char *name, size_t len)
|
||||||
{
|
{
|
||||||
int PASCAL win32_gethostname (char*, int);
|
int PASCAL win32_gethostname (char *, int);
|
||||||
|
|
||||||
if (__check_null_invalid_struct_errno (name, len))
|
if (__check_null_invalid_struct_errno (name, len))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (wsock32_handle == NULL ||
|
if (wsock32_handle == NULL || win32_gethostname (name, len) == SOCKET_ERROR)
|
||||||
win32_gethostname (name, len) == SOCKET_ERROR)
|
|
||||||
{
|
{
|
||||||
DWORD local_len = len;
|
DWORD local_len = len;
|
||||||
|
|
||||||
|
@ -892,7 +908,7 @@ free_hostent_ptr (struct hostent *&p)
|
||||||
debug_printf ("hostent: %s", p->h_name);
|
debug_printf ("hostent: %s", p->h_name);
|
||||||
|
|
||||||
if (p->h_name)
|
if (p->h_name)
|
||||||
free ((void *)p->h_name);
|
free ((void *) p->h_name);
|
||||||
free_char_list (p->h_aliases);
|
free_char_list (p->h_aliases);
|
||||||
free_addr_list (p->h_addr_list);
|
free_addr_list (p->h_addr_list);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
@ -906,6 +922,7 @@ dup_hostent_ptr (struct hostent *src)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct hostent *dst = (struct hostent *) calloc (1, sizeof *dst);
|
struct hostent *dst = (struct hostent *) calloc (1, sizeof *dst);
|
||||||
|
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -933,7 +950,7 @@ out:
|
||||||
#ifdef _MT_SAFE
|
#ifdef _MT_SAFE
|
||||||
#define hostent_buf _reent_winsup ()->_hostent_buf
|
#define hostent_buf _reent_winsup ()->_hostent_buf
|
||||||
#else
|
#else
|
||||||
static struct hostent *hostent_buf = NULL;
|
static struct hostent *hostent_buf = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* exported as gethostbyname: standards? */
|
/* exported as gethostbyname: standards? */
|
||||||
|
@ -1192,8 +1209,7 @@ getdomainname (char *domain, size_t len)
|
||||||
(!wincap.is_winnt ()) ? "System" : "SYSTEM",
|
(!wincap.is_winnt ()) ? "System" : "SYSTEM",
|
||||||
"CurrentControlSet", "Services",
|
"CurrentControlSet", "Services",
|
||||||
(!wincap.is_winnt ()) ? "VxD" : "Tcpip",
|
(!wincap.is_winnt ()) ? "VxD" : "Tcpip",
|
||||||
(!wincap.is_winnt ()) ? "MSTCP" : "Parameters",
|
(!wincap.is_winnt ()) ? "MSTCP" : "Parameters", NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* FIXME: Are registry keys case sensitive? */
|
/* FIXME: Are registry keys case sensitive? */
|
||||||
if (r.error () || r.get_string ("Domain", domain, len, "") != ERROR_SUCCESS)
|
if (r.error () || r.get_string ("Domain", domain, len, "") != ERROR_SUCCESS)
|
||||||
|
@ -1216,59 +1232,139 @@ static void
|
||||||
get_2k_ifconf (struct ifconf *ifc, int what)
|
get_2k_ifconf (struct ifconf *ifc, int what)
|
||||||
{
|
{
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
char eth[2] = "/", ppp[2] = "/", slp[2] = "/", sub[2] = "0", tok[2] = "/";
|
int ethId = 0, pppId = 0, slpId = 0, tokId = 0;
|
||||||
|
|
||||||
/* Union maps buffer to correct struct */
|
/* Union maps buffer to correct struct */
|
||||||
struct ifreq *ifr = ifc->ifc_req;
|
struct ifreq *ifr = ifc->ifc_req;
|
||||||
|
|
||||||
DWORD if_cnt, ip_cnt, lip, lnp;
|
DWORD ip_cnt, lip, lnp;
|
||||||
DWORD siz_if_table = 0;
|
|
||||||
DWORD siz_ip_table = 0;
|
DWORD siz_ip_table = 0;
|
||||||
PMIB_IFTABLE ift;
|
|
||||||
PMIB_IPADDRTABLE ipt;
|
PMIB_IPADDRTABLE ipt;
|
||||||
|
PMIB_IFROW ifrow;
|
||||||
struct sockaddr_in *sa = NULL;
|
struct sockaddr_in *sa = NULL;
|
||||||
struct sockaddr *so = NULL;
|
struct sockaddr *so = NULL;
|
||||||
|
|
||||||
if (GetIfTable (NULL, &siz_if_table, TRUE) == ERROR_INSUFFICIENT_BUFFER &&
|
typedef struct ifcount_t
|
||||||
GetIpAddrTable (NULL, &siz_ip_table, TRUE) == ERROR_INSUFFICIENT_BUFFER &&
|
|
||||||
(ift = (PMIB_IFTABLE) alloca (siz_if_table)) &&
|
|
||||||
(ipt = (PMIB_IPADDRTABLE) alloca (siz_ip_table)) &&
|
|
||||||
!GetIfTable (ift, &siz_if_table, TRUE) &&
|
|
||||||
!GetIpAddrTable (ipt, &siz_ip_table, TRUE))
|
|
||||||
{
|
{
|
||||||
/* Iterate over all known interfaces */
|
DWORD ifIndex;
|
||||||
for (if_cnt = 0; if_cnt < ift->dwNumEntries; ++if_cnt)
|
size_t count;
|
||||||
|
unsigned int enumerated; // for eth0:1
|
||||||
|
unsigned int classId; // for eth0, tok0 ...
|
||||||
|
|
||||||
|
};
|
||||||
|
ifcount_t *iflist, *ifEntry;
|
||||||
|
|
||||||
|
if (GetIpAddrTable (NULL, &siz_ip_table, TRUE) == ERROR_INSUFFICIENT_BUFFER
|
||||||
|
&& (ifrow = (PMIB_IFROW) alloca (sizeof (MIB_IFROW)))
|
||||||
|
&& (ipt = (PMIB_IPADDRTABLE) alloca (siz_ip_table))
|
||||||
|
&& !GetIpAddrTable (ipt, &siz_ip_table, TRUE))
|
||||||
{
|
{
|
||||||
*sub = '0';
|
iflist =
|
||||||
|
(ifcount_t *) alloca (sizeof (ifcount_t) * (ipt->dwNumEntries + 1));
|
||||||
|
memset (iflist, 0, sizeof (ifcount_t) * (ipt->dwNumEntries + 1));
|
||||||
|
for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt)
|
||||||
|
{
|
||||||
|
ifEntry = iflist;
|
||||||
|
/* search for matching entry (and stop at first free entry) */
|
||||||
|
while (ifEntry->count != 0)
|
||||||
|
{
|
||||||
|
if (ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex)
|
||||||
|
break;
|
||||||
|
ifEntry++;
|
||||||
|
}
|
||||||
|
if (ifEntry->count == 0)
|
||||||
|
{
|
||||||
|
ifEntry->count = 1;
|
||||||
|
ifEntry->ifIndex = ipt->table[ip_cnt].dwIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ifEntry->count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// reset the last element. This is just the stopper for the loop.
|
||||||
|
iflist[ipt->dwNumEntries].count = 0;
|
||||||
|
|
||||||
/* Iterate over all configured IP-addresses */
|
/* Iterate over all configured IP-addresses */
|
||||||
for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt)
|
for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt)
|
||||||
{
|
{
|
||||||
/* Does the IP address belong to the interface? */
|
memset (ifrow, 0, sizeof (MIB_IFROW));
|
||||||
if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex)
|
ifrow->dwIndex = ipt->table[ip_cnt].dwIndex;
|
||||||
|
if (GetIfEntry (ifrow) != NO_ERROR)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ifcount_t *ifEntry = iflist;
|
||||||
|
|
||||||
|
/* search for matching entry (and stop at first free entry) */
|
||||||
|
while (ifEntry->count != 0)
|
||||||
{
|
{
|
||||||
|
if (ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex)
|
||||||
|
break;
|
||||||
|
ifEntry++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup the interface name */
|
/* Setup the interface name */
|
||||||
switch (ift->table[if_cnt].dwType)
|
switch (ifrow->dwType)
|
||||||
{
|
{
|
||||||
case MIB_IF_TYPE_TOKENRING:
|
case MIB_IF_TYPE_TOKENRING:
|
||||||
++*tok;
|
if (ifEntry->enumerated == 0)
|
||||||
strcpy (ifr->ifr_name, "tok");
|
{
|
||||||
strcat (ifr->ifr_name, tok);
|
ifEntry->classId = tokId++;
|
||||||
|
__small_sprintf (ifr->ifr_name, "tok%u",
|
||||||
|
ifEntry->classId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__small_sprintf (ifr->ifr_name, "tok%u:%u",
|
||||||
|
ifEntry->classId,
|
||||||
|
ifEntry->enumerated - 1);
|
||||||
|
}
|
||||||
|
ifEntry->enumerated++;
|
||||||
break;
|
break;
|
||||||
case MIB_IF_TYPE_ETHERNET:
|
case MIB_IF_TYPE_ETHERNET:
|
||||||
if (*sub == '0')
|
if (ifEntry->enumerated == 0)
|
||||||
++*eth;
|
{
|
||||||
strcpy (ifr->ifr_name, "eth");
|
ifEntry->classId = ethId++;
|
||||||
strcat (ifr->ifr_name, eth);
|
__small_sprintf (ifr->ifr_name, "eth%u",
|
||||||
|
ifEntry->classId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__small_sprintf (ifr->ifr_name, "eth%u:%u",
|
||||||
|
ifEntry->classId,
|
||||||
|
ifEntry->enumerated - 1);
|
||||||
|
}
|
||||||
|
ifEntry->enumerated++;
|
||||||
break;
|
break;
|
||||||
case MIB_IF_TYPE_PPP:
|
case MIB_IF_TYPE_PPP:
|
||||||
++*ppp;
|
if (ifEntry->enumerated == 0)
|
||||||
strcpy (ifr->ifr_name, "ppp");
|
{
|
||||||
strcat (ifr->ifr_name, ppp);
|
ifEntry->classId = pppId++;
|
||||||
|
__small_sprintf (ifr->ifr_name, "ppp%u",
|
||||||
|
ifEntry->classId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__small_sprintf (ifr->ifr_name, "ppp%u:%u",
|
||||||
|
ifEntry->classId,
|
||||||
|
ifEntry->enumerated - 1);
|
||||||
|
}
|
||||||
|
ifEntry->enumerated++;
|
||||||
break;
|
break;
|
||||||
case MIB_IF_TYPE_SLIP:
|
case MIB_IF_TYPE_SLIP:
|
||||||
++*slp;
|
if (ifEntry->enumerated == 0)
|
||||||
strcpy (ifr->ifr_name, "slp");
|
{
|
||||||
strcat (ifr->ifr_name, slp);
|
ifEntry->classId = slpId++;
|
||||||
|
__small_sprintf (ifr->ifr_name, "slp%u",
|
||||||
|
ifEntry->classId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__small_sprintf (ifr->ifr_name, "slp%u:%u",
|
||||||
|
ifEntry->classId,
|
||||||
|
ifEntry->enumerated - 1);
|
||||||
|
}
|
||||||
|
ifEntry->enumerated++;
|
||||||
break;
|
break;
|
||||||
case MIB_IF_TYPE_LOOPBACK:
|
case MIB_IF_TYPE_LOOPBACK:
|
||||||
strcpy (ifr->ifr_name, "lo");
|
strcpy (ifr->ifr_name, "lo");
|
||||||
|
@ -1276,12 +1372,6 @@ get_2k_ifconf (struct ifconf *ifc, int what)
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*sub > '0')
|
|
||||||
{
|
|
||||||
strcat (ifr->ifr_name, ":");
|
|
||||||
strcat (ifr->ifr_name, sub);
|
|
||||||
}
|
|
||||||
++*sub;
|
|
||||||
/* setup sockaddr struct */
|
/* setup sockaddr struct */
|
||||||
switch (what)
|
switch (what)
|
||||||
{
|
{
|
||||||
|
@ -1314,27 +1404,26 @@ get_2k_ifconf (struct ifconf *ifc, int what)
|
||||||
case SIOCGIFHWADDR:
|
case SIOCGIFHWADDR:
|
||||||
so = &ifr->ifr_hwaddr;
|
so = &ifr->ifr_hwaddr;
|
||||||
for (UINT i = 0; i < IFHWADDRLEN; ++i)
|
for (UINT i = 0; i < IFHWADDRLEN; ++i)
|
||||||
if (i >= ift->table[if_cnt].dwPhysAddrLen)
|
if (i >= ifrow->dwPhysAddrLen)
|
||||||
so->sa_data[i] = '\0';
|
so->sa_data[i] = '\0';
|
||||||
else
|
else
|
||||||
so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i];
|
so->sa_data[i] = ifrow->bPhysAddr[i];
|
||||||
so->sa_family = AF_INET;
|
so->sa_family = AF_INET;
|
||||||
break;
|
break;
|
||||||
case SIOCGIFMETRIC:
|
case SIOCGIFMETRIC:
|
||||||
ifr->ifr_metric = 1;
|
ifr->ifr_metric = 1;
|
||||||
break;
|
break;
|
||||||
case SIOCGIFMTU:
|
case SIOCGIFMTU:
|
||||||
ifr->ifr_mtu = ift->table[if_cnt].dwMtu;
|
ifr->ifr_mtu = ifrow->dwMtu;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++cnt;
|
++cnt;
|
||||||
if ((caddr_t) ++ifr >
|
if ((caddr_t)++ ifr >
|
||||||
ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq))
|
ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq))
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
done:
|
done:
|
||||||
/* Set the correct length */
|
/* Set the correct length */
|
||||||
ifc->ifc_len = cnt * sizeof (struct ifreq);
|
ifc->ifc_len = cnt * sizeof (struct ifreq);
|
||||||
|
@ -1370,8 +1459,7 @@ get_nt_ifconf (struct ifconf *ifc, int what)
|
||||||
"SYSTEM\\"
|
"SYSTEM\\"
|
||||||
"CurrentControlSet\\"
|
"CurrentControlSet\\"
|
||||||
"Services\\"
|
"Services\\"
|
||||||
"Tcpip\\"
|
"Tcpip\\" "Linkage",
|
||||||
"Linkage",
|
|
||||||
0, KEY_READ, &key) == ERROR_SUCCESS)
|
0, KEY_READ, &key) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
if (RegQueryValueEx (key, "Bind",
|
if (RegQueryValueEx (key, "Bind",
|
||||||
|
@ -1422,12 +1510,11 @@ get_nt_ifconf (struct ifconf *ifc, int what)
|
||||||
*ip && *np;
|
*ip && *np;
|
||||||
ip += strlen (ip) + 1, np += strlen (np) + 1)
|
ip += strlen (ip) + 1, np += strlen (np) + 1)
|
||||||
{
|
{
|
||||||
if ((caddr_t) ++ifr > ifc->ifc_buf
|
if ((caddr_t)++ ifr > ifc->ifc_buf
|
||||||
+ ifc->ifc_len
|
+ ifc->ifc_len - sizeof (struct ifreq))
|
||||||
- sizeof (struct ifreq))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (! strncmp (bp, "NdisWan", 7))
|
if (!strncmp (bp, "NdisWan", 7))
|
||||||
{
|
{
|
||||||
strcpy (ifr->ifr_name, "ppp");
|
strcpy (ifr->ifr_name, "ppp");
|
||||||
strcat (ifr->ifr_name, bp + 7);
|
strcat (ifr->ifr_name, bp + 7);
|
||||||
|
@ -1456,7 +1543,8 @@ get_nt_ifconf (struct ifconf *ifc, int what)
|
||||||
case SIOCGIFCONF:
|
case SIOCGIFCONF:
|
||||||
case SIOCGIFADDR:
|
case SIOCGIFADDR:
|
||||||
sa = (struct sockaddr_in *) &ifr->ifr_addr;
|
sa = (struct sockaddr_in *) &ifr->ifr_addr;
|
||||||
sa->sin_addr.s_addr = cygwin_inet_addr (dhcpaddress);
|
sa->sin_addr.s_addr =
|
||||||
|
cygwin_inet_addr (dhcpaddress);
|
||||||
sa->sin_family = AF_INET;
|
sa->sin_family = AF_INET;
|
||||||
sa->sin_port = 0;
|
sa->sin_port = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -1591,8 +1679,7 @@ get_95_ifconf (struct ifconf *ifc, int what)
|
||||||
char adapter[256], ip[256], np[256];
|
char adapter[256], ip[256], np[256];
|
||||||
|
|
||||||
if (res != ERROR_SUCCESS
|
if (res != ERROR_SUCCESS
|
||||||
|| RegOpenKeyEx (key, ifname, 0,
|
|| RegOpenKeyEx (key, ifname, 0, KEY_READ, &ifkey) != ERROR_SUCCESS)
|
||||||
KEY_READ, &ifkey) != ERROR_SUCCESS)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (RegQueryValueEx (ifkey, "Driver", 0,
|
if (RegQueryValueEx (ifkey, "Driver", 0,
|
||||||
|
@ -1619,9 +1706,8 @@ get_95_ifconf (struct ifconf *ifc, int what)
|
||||||
NULL, (unsigned char *) np,
|
NULL, (unsigned char *) np,
|
||||||
(size = sizeof np, &size)) == ERROR_SUCCESS)
|
(size = sizeof np, &size)) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
if ((caddr_t)++ifr > ifc->ifc_buf
|
if ((caddr_t)++ ifr > ifc->ifc_buf
|
||||||
+ ifc->ifc_len
|
+ ifc->ifc_len - sizeof (struct ifreq))
|
||||||
- sizeof (struct ifreq))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
switch (what)
|
switch (what)
|
||||||
|
@ -1766,6 +1852,7 @@ get_ifconf (struct ifconf *ifc, int what)
|
||||||
}
|
}
|
||||||
|
|
||||||
OSVERSIONINFO os_version_info;
|
OSVERSIONINFO os_version_info;
|
||||||
|
|
||||||
memset (&os_version_info, 0, sizeof os_version_info);
|
memset (&os_version_info, 0, sizeof os_version_info);
|
||||||
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
||||||
GetVersionEx (&os_version_info);
|
GetVersionEx (&os_version_info);
|
||||||
|
@ -1794,12 +1881,14 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
|
||||||
return (int) INVALID_SOCKET;
|
return (int) INVALID_SOCKET;
|
||||||
|
|
||||||
cygheap_fdnew res_fd;
|
cygheap_fdnew res_fd;
|
||||||
|
|
||||||
if (res_fd < 0)
|
if (res_fd < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (fd2p)
|
if (fd2p)
|
||||||
{
|
{
|
||||||
cygheap_fdnew newfd (res_fd, false);
|
cygheap_fdnew newfd (res_fd, false);
|
||||||
|
|
||||||
if (*fd2p < 0)
|
if (*fd2p < 0)
|
||||||
goto done;
|
goto done;
|
||||||
*fd2p = newfd;
|
*fd2p = newfd;
|
||||||
|
@ -1833,6 +1922,7 @@ cygwin_rresvport (int *port)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cygheap_fdnew res_fd;
|
cygheap_fdnew res_fd;
|
||||||
|
|
||||||
if (res_fd < 0)
|
if (res_fd < 0)
|
||||||
res = -1;
|
res = -1;
|
||||||
else
|
else
|
||||||
|
@ -1866,11 +1956,13 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
|
||||||
return (int) INVALID_SOCKET;
|
return (int) INVALID_SOCKET;
|
||||||
|
|
||||||
cygheap_fdnew res_fd;
|
cygheap_fdnew res_fd;
|
||||||
|
|
||||||
if (res_fd < 0)
|
if (res_fd < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (fd2p)
|
if (fd2p)
|
||||||
{
|
{
|
||||||
cygheap_fdnew newfd (res_fd);
|
cygheap_fdnew newfd (res_fd);
|
||||||
|
|
||||||
if (newfd < 0)
|
if (newfd < 0)
|
||||||
goto done;
|
goto done;
|
||||||
*fd2p = newfd;
|
*fd2p = newfd;
|
||||||
|
@ -1929,6 +2021,7 @@ socketpair (int family, int type, int protocol, int *sb)
|
||||||
{
|
{
|
||||||
sb[0] = sb0;
|
sb[0] = sb0;
|
||||||
cygheap_fdnew sb1 (sb0, false);
|
cygheap_fdnew sb1 (sb0, false);
|
||||||
|
|
||||||
if (sb1 < 0)
|
if (sb1 < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -2009,8 +2102,7 @@ socketpair (int family, int type, int protocol, int *sb)
|
||||||
sock_out.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
|
sock_out.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
|
||||||
|
|
||||||
/* Do a connect */
|
/* Do a connect */
|
||||||
if (connect (outsock, (struct sockaddr *) &sock_in,
|
if (connect (outsock, (struct sockaddr *) &sock_in, sizeof (sock_in)) < 0)
|
||||||
sizeof (sock_in)) < 0)
|
|
||||||
{
|
{
|
||||||
debug_printf ("connect error");
|
debug_printf ("connect error");
|
||||||
set_winsock_errno ();
|
set_winsock_errno ();
|
||||||
|
|
Loading…
Reference in New Issue