1
/* ========================================================================
2
* Copyright 1988-2006 University of Washington
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
11
* ========================================================================
15
* Program: Operating-system dependent routines -- MS-DOS (PC/TCP) version
17
* Author: Mark Crispin
18
* Networks and Distributed Computing
19
* Computing & Communications
20
* University of Washington
21
* Administration Building, AG-44
23
* Internet: MRC@CAC.Washington.EDU
26
* Last Edited: 30 August 2006
29
/* Private function prototypes */
31
#include "tcp_dos.h" /* must be before osdep includes tcp.h */
38
#include <sys\timeb.h>
40
#include <sys\socket.h>
42
#include <arpa\inet.h>
43
#include <netinet\in.h>
56
/* Return my local host name
57
* Returns: my local host name
60
char *mylocalhost (void)
62
if (!myLocalHost) { /* known yet */
63
char *s,tmp[MAILTMPLEN];
65
/* see if known host name */
66
if (!gethostname (tmp,MAILTMPLEN-1)) s = tmp;
67
/* no, try IP address */
68
else if (myip = gethostid ()) {
71
sprintf (s = tmp,"[%s]",inet_ntoa (in));
73
/* older kernel, look harder. */
74
else if (getconf ("ifcust","ip-address",tmp+1,MAILTMPLEN-2)) {
75
*(s = tmp) = '['; /* wrap the brackets around it */
78
else s = "random-pc"; /* say what? */
79
myLocalHost = cpystr (s); /* record for subsequent use */
85
/* Look up host address
86
* Accepts: pointer to pointer to host name
87
* socket address block
88
* Returns: non-zero with host address in socket, official host name in host;
92
long lookuphost (char **host,struct sockaddr_in *sin)
96
struct hostent *hn = gethostbyname (lcase (strcpy (tmp,*host)));
97
if (!hn) return NIL; /* got a host name? */
98
*host = cpystr (hn->h_name); /* set official name */
99
/* copy host addresses */
100
memcpy (&sin->sin_addr,hn->h_addr,hn->h_length);