Mail Archives: cygwin-developers/1998/11/02/16:18:57
The following patch would allow, to get your hostname from the
winsock library, if it's installed. The result could be different
from the now only used 'GetComputerName()', because this function
takes the windows computer name, instead of the tcp/ip hostname.
The following patch checks, if it's possible, to get the hostname
from winsock, else it uses GetComputerName. The (possible) use of
winsock implies the move of `gethostname()' from `syscalls.cc' to
`net.cc'.
Regards,
Corinna
ChangeLog:
Mon Nov 2 23:53:00 Corinna Vinschen <corinna DOT vinschen AT cityweb DOT de>
* syscall.cc (gethostname): function deleted
* net.cc (gethostname): new function 'gethostname' which
first calls wsock32::gethostname and only if it fails,
calls GetComputerNameA as suggested by Chris Faylor.
---- snip ----
--- syscalls.cc.orig Mon Nov 02 23:35:54 1998
+++ syscalls.cc Mon Nov 02 23:36:25 1998
@@ -1534,21 +1534,6 @@ getdtablesize ()
}
extern "C"
-int
-gethostname (char *name, size_t len)
-{
- DWORD local_len = len;
-
- if (!GetComputerNameA (name, &local_len))
- {
- __seterrno ();
- return -1;
- }
-
- return 0;
-}
-
-extern "C"
size_t
getpagesize ()
{
--- net.cc.orig Mon Nov 02 23:35:59 1998
+++ net.cc Mon Nov 02 23:52:27 1998
@@ -46,6 +46,7 @@ SOCKET (*i_accept) (SOCKET s, struct soc
int (*i_bind) (SOCKET s, const struct sockaddr *addr, int namelen)
NO_COPY PASCAL;
int (*i_closesocket) (SOCKET s) NO_COPY PASCAL;
int (*i_connect) (SOCKET s, const struct sockaddr *name, int namelen)
NO_COPY PASCAL;
+int (*i_gethostname) (char * name, size_t len) NO_COPY PASCAL;
struct hostent * (*i_gethostbyaddr) (const char * addr, int, int)
NO_COPY PASCAL;
struct hostent * (*i_gethostbyname) (const char * name) NO_COPY PASCAL;
int (*i_getpeername) (SOCKET s, struct sockaddr *name, int * namelen)
NO_COPY PASCAL;
@@ -107,6 +108,7 @@ winsock_init ()
LOAD (bind)
LOAD (closesocket)
LOAD (connect)
+ LOAD (gethostname)
LOAD (gethostbyaddr)
LOAD (gethostbyname)
LOAD (getpeername)
@@ -755,6 +757,33 @@ cygwin_getservbyport (int port, const ch
syscall_printf ("%x = getservbyport (%d, %s)", p, port, proto);
out ("getservbyport");
return p;
+}
+
+extern "C"
+int
+gethostname (char *name, size_t len)
+{
+ MARK ();
+ if (NOTSTATE (myself, PID_SOCKETS_USED))
+ // CV: This makes it possible to use GetComputerName(),
+ // if wsock dll doesn't exist.
+ if ((wsock32 = LoadLibrary ("wsock32.dll")) != NULL)
+ winsock_init ();
+
+ in ("gethostname");
+ if (i_gethostname == NULL
+ || (*i_gethostname) (name, len) == SOCKET_ERROR)
+ {
+ DWORD local_len = len;
+
+ if (!GetComputerNameA (name, &local_len))
+ {
+ set_winsock_errno ();
+ return -1;
+ }
+ }
+ debug_printf ("name %s\n", name);
+ h_errno = 0;
+ out ("gethostname");
+ return 0;
}
/* exported as gethostbyname: standards? */
- Raw text -