comp.lang.ada
 help / color / mirror / Atom feed
From: sarge!sarge!svh@uunet.uu.net  (Steven Hovater)
Subject: Re: SunAda question
Date: 21 Jul 93 11:37:11 GMT	[thread overview]
Message-ID: <svh.743254631@sarge> (raw)

kanderso@mabillon.ICS.UCI.EDU (Kenneth Anderson) writes:

>Hello.  I am using the sunada-1.1 compiler and it came with a package
>unix defined in its standard library.  One of the subprograms defined
>in the package unix is

>        function gethostname(name: address; namelen: integer)
>                return status_code;

>As defined this function seems very useless.  It will only tell you whether
>or not the call to gethostname was successful.  It will not tell you,
>despite its name, what the hostname is.

>Two questions:

>  1. Anyone know why such a useless function would be included in
>     this package?

>  2. What is a good portable way of finding out the name of the machine
>     your program is running on?

>Thanks in advance,

>Ken Anderson

Hi Ken - not speaking officially here for Verdix, but for myself :)

Note that the function has an argument that's an address - that's the
key here. Some might argue that it's bad form to putz around modifying 
what are considered in many circles to be "in" only parameters, and I
won't get into that any further, but a quick answer to your question is
that the function (if successful) will return a nice status code in the
return value, and the name parameter (I did it very dirty below) gets modified
to contain the hostname. 

This is fairly portable, IMHO - since it's a pragma interface to the unix funct
ion of
the same name.

-----cut here----
with unix;
with text_io;

procedure gethost is 
        namelen : integer := 20;
        hostname : string (1..namelen);
        stat : unix.status_code;
begin

        stat := unix.gethostname(hostname'address,namelen);

        text_io.put_line ("Hostname is " & hostname);

end gethost;

--- cut here---

While this may not be the cleanest code, it gets the point across.
--
Steven V. Hovater                      (703)318-5839
Senior CASE Engineer                   
Verdix Corporation                     EMAIL: svh@verdix.com
-- 
Steven V. Hovater                      (703)318-5839
Senior CASE Engineer                   
Verdix Corporation                     EMAIL: svh@verdix.com

             reply	other threads:[~1993-07-21 11:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-07-21 11:37 Steven Hovater [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-07-22 10:49 SunAda question Steven Hovater
1993-07-21 20:52 Esther Lumsdon
1993-07-21 18:50 David Emery
1993-07-21 16:07 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!darwin.s
1993-07-21 15:39 Robert I. Eachus
1993-07-21 13:25 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!news.cac.ps
1993-07-21 12:07 Chris Elliott
1993-07-20 20:38 Kenneth Anderson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox