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 (Novell) 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\socket.h>
40 #include <netinet\in.h>
41 #include <netdb.h>
42 #include "misc.h"
43
44
45 #include "fs_dos.c"
46 #include "ftl_dos.c"
47 #include "nl_dos.c"
48 #include "env_dos.c"
49 #undef write
50 #define read soread
51 #define write sowrite
52 #define close soclose
53 #include "tcp_dos.c"
54
55
56 /* Return my local host name
57 * Returns: my local host name
58 */
59
mylocalhost(void)60 char *mylocalhost (void)
61 {
62 if (!myLocalHost) { /* known yet? */
63 char *s,tmp[MAILTMPLEN];
64 struct hostent *he;
65 struct in_addr in;
66 /* could we get local id? */
67 if ((in.s_addr = getmyipaddr ()) != -1) {
68 if (he = gethostbyaddr ((char *) &in.s_addr,4,PF_INET)) s = he->h_name;
69 else sprintf (s = tmp,"[%s]",inet_ntoa (in));
70 }
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 char *s = *host; /* in case of error */
88 sin->sin_addr.s_addr = rhost (host);
89 if (sin->sin_addr.s_addr == -1) {
90 *host = s; /* error, restore old host name */
91 return NIL;
92 }
93 *host = cpystr (*host); /* make permanent copy of name */
94 return T; /* success */
95 }
96