imapext-2007

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/osdep/dos/os_dpc.c	Mon Sep 14 15:17:45 2009 +0900
     1.3 @@ -0,0 +1,102 @@
     1.4 +/* ========================================================================
     1.5 + * Copyright 1988-2006 University of Washington
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * 
    1.14 + * ========================================================================
    1.15 + */
    1.16 +
    1.17 +/*
    1.18 + * Program:	Operating-system dependent routines -- MS-DOS (PC/TCP) version
    1.19 + *
    1.20 + * Author:	Mark Crispin
    1.21 + *		Networks and Distributed Computing
    1.22 + *		Computing & Communications
    1.23 + *		University of Washington
    1.24 + *		Administration Building, AG-44
    1.25 + *		Seattle, WA  98195
    1.26 + *		Internet: MRC@CAC.Washington.EDU
    1.27 + *
    1.28 + * Date:	11 April 1989
    1.29 + * Last Edited:	30 August 2006
    1.30 + */
    1.31 +
    1.32 +/* Private function prototypes */
    1.33 +
    1.34 +#include "tcp_dos.h"		/* must be before osdep includes tcp.h */
    1.35 +#include "mail.h"
    1.36 +#include "osdep.h"
    1.37 +#include <time.h>
    1.38 +#include <errno.h>
    1.39 +#include <fcntl.h>
    1.40 +#include <sys\stat.h>
    1.41 +#include <sys\timeb.h>
    1.42 +#include <4bsddefs.h>
    1.43 +#include <sys\socket.h>
    1.44 +#include <errno.h>
    1.45 +#include <arpa\inet.h>
    1.46 +#include <netinet\in.h>
    1.47 +#include <netdb.h>
    1.48 +#include "misc.h"
    1.49 +
    1.50 +
    1.51 +#include "fs_dos.c"
    1.52 +#include "ftl_dos.c"
    1.53 +#include "nl_dos.c"
    1.54 +#include "env_dos.c"
    1.55 +#undef write
    1.56 +#include "tcp_dos.c"
    1.57 +
    1.58 +
    1.59 +/* Return my local host name
    1.60 + * Returns: my local host name
    1.61 + */
    1.62 +
    1.63 +char *mylocalhost (void)
    1.64 +{
    1.65 +  if (!myLocalHost) {		/* known yet */
    1.66 +    char *s,tmp[MAILTMPLEN];
    1.67 +    long myip;
    1.68 +				/* see if known host name */
    1.69 +    if (!gethostname (tmp,MAILTMPLEN-1)) s = tmp;
    1.70 +				/* no, try IP address */
    1.71 +    else if (myip = gethostid ()) {
    1.72 +      struct in_addr in;
    1.73 +      in.s_addr = myip;
    1.74 +      sprintf (s = tmp,"[%s]",inet_ntoa (in));
    1.75 +    }
    1.76 +				/* older kernel, look harder. */
    1.77 +    else if (getconf ("ifcust","ip-address",tmp+1,MAILTMPLEN-2)) {
    1.78 +      *(s = tmp) = '[';		/* wrap the brackets around it */
    1.79 +      strcat (tmp,"]");
    1.80 +    }
    1.81 +    else s = "random-pc";	/* say what? */
    1.82 +    myLocalHost = cpystr (s);	/* record for subsequent use */
    1.83 +  }
    1.84 +  return myLocalHost;
    1.85 +}
    1.86 +
    1.87 +
    1.88 +/* Look up host address
    1.89 + * Accepts: pointer to pointer to host name
    1.90 + *	    socket address block
    1.91 + * Returns: non-zero with host address in socket, official host name in host;
    1.92 + *	    else NIL
    1.93 + */
    1.94 +
    1.95 +long lookuphost (char **host,struct sockaddr_in *sin)
    1.96 +{
    1.97 +  long ret = -1;
    1.98 +  char tmp[MAILTMPLEN];
    1.99 +  struct hostent *hn = gethostbyname (lcase (strcpy (tmp,*host)));
   1.100 +  if (!hn) return NIL;		/* got a host name? */
   1.101 +  *host = cpystr (hn->h_name);	/* set official name */
   1.102 +				/* copy host addresses */
   1.103 +  memcpy (&sin->sin_addr,hn->h_addr,hn->h_length);
   1.104 +  return T;
   1.105 +}

UW-IMAP'd extensions by yuuji