[comp.sys.apollo] gethostname

GBOPOLY1@NUSVM.BITNET (fclim) (09/15/88)

hi,
      it looks like i will be answering one of my questions in an
earlier inquiry.  previously, i wrote:

>     my program also needs to write to a file in /tmp.  i need the
>full absolute pathname of this file right from the network root //.
>so i use the unix system call, gethostname(host, strlen(host)).
>but this returns -1 and *host == NULL.
>
>     before adding the above code to my program, i used hostname(1).
>at a csh level, i issued
>           % hostname
>           wm
>so i expect gethostname(host, strlen(host)) to return 0 and put
>"wm" into host.
>
>     when we set up our network, we use the aegis commands like
>uctnode and ctnode.  we did not use hostname.

i fixed this by using name_$get_path().  suppose my filename is
in buf:
            char bar[256];
            sprintf(bar, "/tmp/lock-%s", pp->pw_name);
then the following
            char foo[256];
            short len;
            name_$get_path(bar, (short)strlen(bar), foo, len, status);
            printf("%sn", foo);
will produce
            //wm/sys/node_data/tmp/lock-fclim
(the output is actually in upper case; i'm too lazy here to shift.)
since we have crl /tmp `node_data/tmp on node //wm.


fclim          --- gbopoly1 % nusvm.bitnet @ cunyvm.cuny.edu
computer centre
singapore polytechnic
dover road
singapore 0513.

rees@MAILGW.CC.UMICH.EDU (Jim Rees) (09/16/88)

    >     my program also needs to write to a file in /tmp.  i need the
    >full absolute pathname of this file right from the network root //.
    >so i use the unix system call, gethostname(host, strlen(host)).
    >but this returns -1 and *host == NULL.

    i fixed this by using name_$get_path().  suppose my filename is
    in buf:
                char bar[256];
                sprintf(bar, "/tmp/lock-%s", pp->pw_name);
    then the following
                char foo[256];
                short len;
                name_$get_path(bar, (short)strlen(bar), foo, len, status);
                printf("%sn", foo);
    will produce
                //wm/sys/node_data/tmp/lock-fclim
    (the output is actually in upper case; i'm too lazy here to shift.)
    since we have crl /tmp `node_data/tmp on node //wm.

Here's how to do it case-correct:

#include "/sys/ins/base.ins.c"
#include "/sys/ins/name.ins.c"

main()
{
	name_$long_pname_t name;
	short namelen;
	status_$t st;

	name_$get_path_lc("/", 1, (short) sizeof name, name, namelen, st);
	name[namelen] = '\0';
	printf("%s\n", name);
}
-------

GBOPOLY1@NUSVM.BITNET (fclim) (09/21/88)

hi,
    earlier, i query with

>     my program also needs to write to a file in /tmp.  i need the
>full absolute pathname of this file right from the network root //.
>so i use the unix system call, gethostname(host, strlen(host)).
>but this returns -1 and *host == NULL.
>
>     before adding the above code to my program, i used hostname(1).
>at a csh level, i issued
>           % hostname
>           wm
>so i expect gethostname(host, strlen(host)) to return 0 and put
>"wm" into host.
>
>     when we set up our network, we use the aegis commands like
>uctnode and ctnode.  we did not use hostname.
>

well, silly old me had used strlen instead of the correct sizeof
operator.  the call gethostname(host, strlen(host)) misled
gethostname(2) to think that host is an array of zero size.
the correct call gethostname(host, sizeof host) pass the elemental
size of host.

my apologies to those who have considerable time trying
to solve my problem.


ps:  i found out that name_$get_path() does a better job of what
     i had in mind.

fclim          --- gbopoly1 % nusvm.bitnet @ cunyvm.cuny.edu
computer centre
singapore polytechnic
dover road
singapore 0513.