~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to imap/src/osdep/dos/os_dpc.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/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
 */
 
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 <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"
 
46
 
 
47
 
 
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"
 
54
 
 
55
 
 
56
/* Return my local host name
 
57
 * Returns: my local host name
 
58
 */
 
59
 
 
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
}
 
83
 
 
84
 
 
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
 */
 
91
 
 
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
}