4 * Copyright (C) 2006 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
23 #include "wine/debug.h"
27 #include <sys/types.h>
29 #ifdef HAVE_NETINET_IN_H
30 # include <netinet/in.h>
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
50 WINE_DEFAULT_DEBUG_CHANNEL(dnsapi
);
54 static CRITICAL_SECTION resolver_cs
;
55 static CRITICAL_SECTION_DEBUG resolver_cs_debug
=
58 { &resolver_cs_debug
.ProcessLocksList
,
59 &resolver_cs_debug
.ProcessLocksList
},
60 0, 0, { (DWORD_PTR
)(__FILE__
": resolver_cs") }
62 static CRITICAL_SECTION resolver_cs
= { &resolver_cs_debug
, -1, 0, 0, 0, 0 };
64 #define LOCK_RESOLVER() do { EnterCriticalSection( &resolver_cs ); } while (0)
65 #define UNLOCK_RESOLVER() do { LeaveCriticalSection( &resolver_cs ); } while (0)
68 /* the resolver lock must be held and res_init() must have been
69 * called before calling this function.
71 static DNS_STATUS
dns_get_serverlist( PIP4_ARRAY addrs
, PDWORD len
)
75 size
= sizeof(IP4_ARRAY
) + sizeof(IP4_ADDRESS
) * (_res
.nscount
- 1);
76 if (!addrs
|| *len
< size
)
79 return ERROR_INSUFFICIENT_BUFFER
;
82 addrs
->AddrCount
= _res
.nscount
;
84 for (i
= 0; i
< _res
.nscount
; i
++)
85 addrs
->AddrArray
[i
] = _res
.nsaddr_list
[i
].sin_addr
.s_addr
;
90 #endif /* HAVE_RESOLV */
92 static DNS_STATUS
dns_get_hostname_a( COMPUTER_NAME_FORMAT format
,
93 LPSTR buffer
, PDWORD len
)
96 DWORD size
= sizeof(name
);
98 if (!GetComputerNameExA( format
, name
, &size
))
99 return DNS_ERROR_NAME_DOES_NOT_EXIST
;
101 if (!buffer
|| (size
= lstrlenA( name
) + 1) > *len
)
104 return ERROR_INSUFFICIENT_BUFFER
;
107 lstrcpyA( buffer
, name
);
108 return ERROR_SUCCESS
;
111 static DNS_STATUS
dns_get_hostname_w( COMPUTER_NAME_FORMAT format
,
112 LPWSTR buffer
, PDWORD len
)
115 DWORD size
= sizeof(name
);
117 if (!GetComputerNameExW( format
, name
, &size
))
118 return DNS_ERROR_NAME_DOES_NOT_EXIST
;
120 if (!buffer
|| (size
= lstrlenW( name
) + 1) > *len
)
123 return ERROR_INSUFFICIENT_BUFFER
;
126 lstrcpyW( buffer
, name
);
127 return ERROR_SUCCESS
;
130 /******************************************************************************
131 * DnsQueryConfig [DNSAPI.@]
134 DNS_STATUS WINAPI
DnsQueryConfig( DNS_CONFIG_TYPE config
, DWORD flag
, PWSTR adapter
,
135 PVOID reserved
, PVOID buffer
, PDWORD len
)
137 DNS_STATUS ret
= ERROR_INVALID_PARAMETER
;
139 TRACE( "(%d,0x%08lx,%s,%p,%p,%p)\n", config
, flag
, debugstr_w(adapter
),
140 reserved
, buffer
, len
);
142 if (!len
) return ERROR_INVALID_PARAMETER
;
146 case DnsConfigDnsServerList
:
152 ret
= dns_get_serverlist( (IP4_ARRAY
*)buffer
, len
);
157 WARN( "compiled without resolver support\n" );
161 case DnsConfigHostName_A
:
162 case DnsConfigHostName_UTF8
:
163 return dns_get_hostname_a( ComputerNameDnsHostname
, buffer
, len
);
165 case DnsConfigFullHostName_A
:
166 case DnsConfigFullHostName_UTF8
:
167 return dns_get_hostname_a( ComputerNameDnsFullyQualified
, buffer
, len
);
169 case DnsConfigPrimaryDomainName_A
:
170 case DnsConfigPrimaryDomainName_UTF8
:
171 return dns_get_hostname_a( ComputerNameDnsDomain
, buffer
, len
);
173 case DnsConfigHostName_W
:
174 return dns_get_hostname_w( ComputerNameDnsHostname
, buffer
, len
);
176 case DnsConfigFullHostName_W
:
177 return dns_get_hostname_w( ComputerNameDnsFullyQualified
, buffer
, len
);
179 case DnsConfigPrimaryDomainName_W
:
180 return dns_get_hostname_w( ComputerNameDnsDomain
, buffer
, len
);
182 case DnsConfigAdapterDomainName_A
:
183 case DnsConfigAdapterDomainName_W
:
184 case DnsConfigAdapterDomainName_UTF8
:
185 case DnsConfigSearchList
:
186 case DnsConfigAdapterInfo
:
187 case DnsConfigPrimaryHostNameRegistrationEnabled
:
188 case DnsConfigAdapterHostNameRegistrationEnabled
:
189 case DnsConfigAddressRegistrationMaxCount
:
190 FIXME( "unimplemented config type %d\n", config
);
194 WARN( "unknown config type: %d\n", config
);