1994-09-30 15:50:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
|
|
|
|
* For copying and distribution information, please see the file
|
|
|
|
* <Copyright.MIT>.
|
|
|
|
*
|
|
|
|
* from: k_gethostname.c,v 4.1 88/12/01 14:04:42 jtkohl Exp $
|
1995-08-26 00:52:32 +02:00
|
|
|
* $Id: k_gethostname.c,v 1.3 1995/07/18 16:38:51 mark Exp $
|
1994-09-30 15:50:09 +01:00
|
|
|
*/
|
|
|
|
|
1995-08-26 00:52:32 +02:00
|
|
|
#if 0
|
1994-09-30 15:50:09 +01:00
|
|
|
#ifndef lint
|
|
|
|
static char rcsid[] =
|
1995-08-26 00:52:32 +02:00
|
|
|
"$Id: k_gethostname.c,v 1.3 1995/07/18 16:38:51 mark Exp $";
|
1994-09-30 15:50:09 +01:00
|
|
|
#endif /* lint */
|
1995-08-26 00:52:32 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <unistd.h>
|
1994-09-30 15:50:09 +01:00
|
|
|
|
|
|
|
#ifndef PC
|
|
|
|
#ifndef BSD42
|
|
|
|
/* teach me how to k_gethostname for your system here */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PC
|
|
|
|
#include <stdio.h>
|
|
|
|
typedef long in_name;
|
|
|
|
#include "custom.h" /* where is this file? */
|
|
|
|
extern get_custom();
|
|
|
|
#define LEN 64 /* just a guess */
|
|
|
|
#endif /* PC */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the local host's name in "name", up to "namelen" characters.
|
|
|
|
* "name" will be null-terminated if "namelen" is big enough.
|
|
|
|
* The return code is 0 on success, -1 on failure. (The calling
|
|
|
|
* interface is identical to gethostname(2).)
|
|
|
|
*
|
|
|
|
* Currently defined for BSD 4.2 and PC. The BSD version just calls
|
|
|
|
* gethostname(); the PC code was taken from "kinit.c", and may or may
|
|
|
|
* not work.
|
|
|
|
*/
|
|
|
|
|
1995-09-07 23:39:00 +02:00
|
|
|
int
|
|
|
|
k_gethostname(name, namelen)
|
|
|
|
char *name;
|
|
|
|
int namelen;
|
1994-09-30 15:50:09 +01:00
|
|
|
{
|
|
|
|
#ifdef BSD42
|
|
|
|
return gethostname(name, namelen);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PC
|
|
|
|
char buf[LEN];
|
|
|
|
char b1, b2, b3, b4;
|
|
|
|
register char *ptr;
|
|
|
|
|
|
|
|
get_custom(); /* should check for errors,
|
|
|
|
* return -1 on failure */
|
|
|
|
ptr = (char *) &(custom.c_me);
|
|
|
|
b1 = *ptr++;
|
|
|
|
b2 = *ptr++;
|
|
|
|
b3 = *ptr++;
|
|
|
|
b4 = *ptr;
|
|
|
|
(void) sprintf(buf,"PC address %d.%d.%d.%d",b1,b2,b3,b4);
|
|
|
|
if (strlen(buf) > namelen)
|
|
|
|
fprintf(stderr, "gethostname: namelen too small; truncating");
|
|
|
|
strnpcy(name, buf, namelen);
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|