From: michael DOT mauch AT gmx DOT de (Michael Mauch) Newsgroups: comp.os.msdos.djgpp Subject: How should gethostname() work? Date: Wed, 25 Mar 1998 13:27:32 +0100 Organization: Gerhard-Mercator-Universitaet -GH- Duisburg Lines: 66 Message-ID: <6fat7h$2jh$1@news-hrz.uni-duisburg.de> NNTP-Posting-Host: ppp95.uni-duisburg.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi, gethostname() gets the name of the host the program is executing on by calling Int 21h, function 5E00h (in the first place). This works find on Windows 95 with TCP/IP and/or DUN installed: it retrieves the "computer name" entered in the "Identification" tab of the networking control panel (converted to uppercase). But the name delivered by the above function is blank padded, so gethostname() will give "MY_HOST " instead of "MY_HOST". Wouldn't it be better if gethostname() stripped the trailing blanks? Or should that be handled by the users of gethostname()? How is it done on Unix? Also, I see that gethostname() retrieves only up to 16 characters of the host name. Shouldn't that be MAXGETHOSTNAME (==128)? Regards... Michael *** gethostn.c0 Tue Jun 13 08:58:54 1995 --- gethostn.c Wed Mar 25 11:01:06 1998 *************** *** 6,18 **** #include #include #include static char pc_n[]= "pc"; int gethostname (char *buf, int size) { ! char *h, dosbuf[16]; int len; __dpmi_regs r; --- 6,19 ---- #include #include #include + #include static char pc_n[]= "pc"; int gethostname (char *buf, int size) { ! char *h, dosbuf[MAXGETHOSTNAME], *p; int len; __dpmi_regs r; *************** *** 36,41 **** --- 37,45 ---- } len = strlen (h); + for (p = h + len - 1; p>=h; p--) + if (' ' == *p) + *p = '\0', len--; if (len + 1 > size) { errno = ERANGE;