Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / gethost.c
blob069f77621e7a2cfba41a91d967efaa4a2efc97c4
1 /*
2 * Copyright (C) 1993-2005 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include "ipf.h"
14 int gethost(name, hostp, use_inet6)
15 char *name;
16 i6addr_t *hostp;
17 int use_inet6;
19 struct addrinfo hints, *ai;
20 struct netent *n;
21 int error;
23 if (!strcmp(name, "test.host.dots")) {
24 hostp->in4.s_addr = htonl(0xfedcba98);
25 return 0;
28 if (!strcmp(name, "<thishost>"))
29 name = thishost;
31 bzero(&hints, sizeof (hints));
32 if (use_inet6 == 0)
33 hints.ai_family = AF_INET;
34 else
35 hints.ai_family = AF_INET6;
37 error = getaddrinfo(name, NULL, &hints, &ai);
39 if ((error == 0) && (ai != NULL) && (ai->ai_addr != NULL)) {
40 switch (ai->ai_family)
42 case AF_INET:
43 hostp->in4 = ((struct sockaddr_in *)
44 ai->ai_addr)->sin_addr;
45 break;
46 case AF_INET6:
47 hostp->in6 = ((struct sockaddr_in6 *)
48 ai->ai_addr)->sin6_addr;
49 break;
50 default:
51 break;
53 freeaddrinfo(ai);
54 return 0;
57 if (ai != NULL)
58 freeaddrinfo(ai);
60 if (use_inet6 == 0) {
61 n = getnetbyname(name);
62 if (n != NULL) {
63 hostp->in4.s_addr = htonl(n->n_net);
64 return 0;
67 return -1;