imapext-2007

view src/osdep/dos/os_dpc.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
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 */
14 /*
15 * Program: Operating-system dependent routines -- MS-DOS (PC/TCP) 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 */
29 /* Private function prototypes */
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 <4bsddefs.h>
40 #include <sys\socket.h>
41 #include <errno.h>
42 #include <arpa\inet.h>
43 #include <netinet\in.h>
44 #include <netdb.h>
45 #include "misc.h"
48 #include "fs_dos.c"
49 #include "ftl_dos.c"
50 #include "nl_dos.c"
51 #include "env_dos.c"
52 #undef write
53 #include "tcp_dos.c"
56 /* Return my local host name
57 * Returns: my local host name
58 */
60 char *mylocalhost (void)
61 {
62 if (!myLocalHost) { /* known yet */
63 char *s,tmp[MAILTMPLEN];
64 long myip;
65 /* see if known host name */
66 if (!gethostname (tmp,MAILTMPLEN-1)) s = tmp;
67 /* no, try IP address */
68 else if (myip = gethostid ()) {
69 struct in_addr in;
70 in.s_addr = myip;
71 sprintf (s = tmp,"[%s]",inet_ntoa (in));
72 }
73 /* older kernel, look harder. */
74 else if (getconf ("ifcust","ip-address",tmp+1,MAILTMPLEN-2)) {
75 *(s = tmp) = '['; /* wrap the brackets around it */
76 strcat (tmp,"]");
77 }
78 else s = "random-pc"; /* say what? */
79 myLocalHost = cpystr (s); /* record for subsequent use */
80 }
81 return myLocalHost;
82 }
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;
89 * else NIL
90 */
92 long lookuphost (char **host,struct sockaddr_in *sin)
93 {
94 long ret = -1;
95 char tmp[MAILTMPLEN];
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);
101 return T;
102 }

UW-IMAP'd extensions by yuuji