1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
13
14 /*
15 * Program: Operating-system dependent routines -- MS-DOS (PC-NFS) version
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 11 April 1989
26 * Last Edited: 30 August 2006
27 */
28
29 /* Private function prototypes */
30
31 #include "tcp_dos.h" /* must be before osdep includes tcp.h */
32 #include "mail.h"
33 #include "osdep.h"
34 #include <time.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <sys\stat.h>
38 #include <sys\timeb.h>
39 #include <sys\nfs_time.h>
40 #include <sys\tk_types.h>
41 #include <sys\socket.h>
42 #include <netinet\in.h>
43 #include <tk_errno.h>
44 #include <sys\uio.h>
45 #include <netdb.h>
46 #include "misc.h"
47
48
49 #include "fs_dos.c"
50 #include "ftl_dos.c"
51 #include "nl_dos.c"
52 #include "env_dos.c"
53 #undef write
54 #include "tcp_dos.c"
55
56
57 /* Return my local host name
58 * Returns: my local host name
59 */
60
mylocalhost(void)61 char *mylocalhost (void)
62 {
63 if (!myLocalHost) { /* known yet? */
64 char *s,tmp[MAILTMPLEN];
65 unsigned long myip;
66 /* see if known host name */
67 if (!gethostname (tmp,MAILTMPLEN-1)) s = tmp;
68 /* no, try host address */
69 else if (get_myipaddr ((char *) &myip))
70 sprintf (s = tmp,"[%s]",inet_ntoa (myip));
71 else s = "random-pc"; /* say what? */
72 myLocalHost = cpystr (s); /* record for subsequent use */
73 }
74 return myLocalHost;
75 }
76
77
78 /* Look up host address
79 * Accepts: pointer to pointer to host name
80 * socket address block
81 * Returns: non-zero with host address in socket, official host name in host;
82 * else NIL
83 */
84
lookuphost(char ** host,struct sockaddr_in * sin)85 long lookuphost (char **host,struct sockaddr_in *sin)
86 {
87 long ret = -1;
88 char tmp[MAILTMPLEN];
89 struct hostent *hn = gethostbyname (lcase (strcpy (tmp,*host)));
90 if (!hn) return NIL; /* got a host name? */
91 *host = cpystr (hn->h_name); /* set official name */
92 /* copy host addresses */
93 memcpy (&sin->sin_addr,hn->h_addr,hn->h_length);
94 return T;
95 }
96