1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: canonicl.c 764 2007-10-23 23:44:49Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2018 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "../../c-client/mail.h"
20 extern unsigned char *lcase(unsigned char *);
23 /* wingdi.h uses ERROR (!) and we aren't using the c-client ERROR so... */
32 /*----------------------------------------------------------------------
33 Return canonical form of host name ala c-client (UNIX version).
35 Args: host -- The host name
37 Result: Canonical form, or input argument (worst case)
39 You can call it twice without worrying about copying
40 the results, but not more than twice.
43 canonical_name(char *host
)
47 static int whichbuf
= 0;
48 static char buf
[2][NETMAXHOST
+1];
51 whichbuf
= (whichbuf
+ 1) % 2;
54 /* domain literal is easy */
55 if (host
[0] == '[' && host
[(strlen (host
))-1] == ']')
56 strncpy(b
, host
, NETMAXHOST
);
58 strncpy(tmp
, host
, sizeof(tmp
)-1);
59 tmp
[sizeof(tmp
)-1] = '\0';
61 hent
= gethostbyname((char *) lcase((unsigned char *) tmp
));
62 if(hent
&& hent
->h_name
)
63 strncpy(b
, hent
->h_name
, NETMAXHOST
);
65 strncpy(b
, host
, NETMAXHOST
);