/* os9/gethostname.c */ /* 09-May-90 Modified by R. D. Russell */ /* GETHOSTNAME EMULATOR */ /* Compile with cc -r gethostname.c */ /* and link the resulting program with -l=/dd/lib/netdb.l */ #include #include /* Modified by M. Nakahata on 7-Jun-1991 */ /* #include */ #include #include #include #include /* Lance Device descriptor module */ typedef struct { struct modhcom _mh; /* common header info */ char * _mport; /* device port address */ unsigned char _mvector; /* trap vector number */ unsigned char _mirqlvl; /* irq interrupt level */ unsigned char _mpriority; /* irq polling priority */ unsigned char _mmode; /* device mode capabilities */ short _mfmgr; /* file manager name offset */ short _mpdev; /* device driver name offset */ short _mdevcon; /* device configuration offset */ unsigned short _mdscres[4]; /* (reserved) */ unsigned short _mopt; /* option table size */ unsigned char _mdtype; /* device type code */ unsigned char _mpad; /* spare */ unsigned _miname; /* offset to interface name */ short _mmtu, /* max transmission unit */ _miflgs, /* interface flags */ _msaddr; /* offset to sockaddr */ } mod_dev_lance; extern struct hostent *gethostbyaddr(); extern mod_dev_lance *modlink(); extern int errno; int my_gethostname(name, namelen) char *name; int namelen; {/* link to the device descriptor of le0 to get its address and then pick up the offset to the inet address (8) bytes. Use the second 4 bytes as the address of this station which is used to gethostbyaddr - the name is returned. */ mod_dev_lance *m; struct hostent *h; if( (m = modlink("le0", 0)) == (mod_dev_lance *)(-1)) return -1; if( (h = gethostbyaddr((char *)m + (m->_msaddr+4),4,AF_INET)) == 0 ) { *name='\0'; errno = E_PNNF; return -1; } if( strlen(h->h_name) < namelen ) strcpy(name, h->h_name); else strncpy(name, h->h_name, namelen); return 0; }