r18019: Fix a C++ warnings: Don't use void * in libads/ for LDAPMessage anymore.
[Samba/gebeck_regimport.git] / source / utils / net_dns.c
blobcb83b000ca2fe9508e68b47aebed7de48bae33be
2 /*
3 Samba Unix/Linux Dynamic DNS Update
4 net ads commands
6 Copyright (C) Krishna Ganugapati (krishnag@centeris.com) 2006
7 Copyright (C) Gerald Carter 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
25 #include "utils/net.h"
26 #include "dns.h"
28 #if defined(WITH_DNS_UPDATES)
30 /*********************************************************************
31 *********************************************************************/
33 int DoDNSUpdate( char *pszServerName, const char *pszDomainName,
34 char *pszHostName, struct in_addr *iplist, int num_addrs )
36 int32 dwError = 0;
37 DNS_ERROR dns_status;
38 HANDLE hDNSServer = ( HANDLE ) NULL;
39 int32 dwResponseCode = 0;
40 DNS_UPDATE_RESPONSE *pDNSUpdateResponse = NULL;
41 #if 0
42 DNS_UPDATE_RESPONSE *pDNSSecureUpdateResponse = NULL;
43 #endif
45 if ( (num_addrs <= 0) || !iplist ) {
46 return -1;
49 dns_status = DNSOpen( pszServerName, DNS_TCP, &hDNSServer );
50 BAIL_ON_DNS_ERROR( dns_status );
52 dwError = DNSSendUpdate( hDNSServer, pszDomainName, pszHostName,
53 iplist, num_addrs, &pDNSUpdateResponse );
54 BAIL_ON_ERROR( dwError );
56 dwError = DNSUpdateGetResponseCode( pDNSUpdateResponse,
57 &dwResponseCode );
58 if ( dwResponseCode == DNS_REFUSED ) {
59 dwError = -1;
61 BAIL_ON_ERROR( dwError );
63 cleanup:
64 return dwError;
66 error:
67 goto cleanup;
70 /*********************************************************************
71 *********************************************************************/
73 int get_my_ip_address( struct in_addr **ips )
75 struct iface_struct nics[MAX_INTERFACES];
76 int i, n;
77 struct in_addr loopback_ip = *interpret_addr2("127.0.0.1");
78 struct in_addr *list;
79 int count = 0;
81 /* find the first non-loopback address from our list of interfaces */
83 n = get_interfaces(nics, MAX_INTERFACES);
85 if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) {
86 return -1;
89 for ( i=0; i<n; i++ ) {
90 if ( nics[i].ip.s_addr != loopback_ip.s_addr ) {
91 memcpy( &list[count++], &nics[i].ip, sizeof( struct in_addr ) );
94 *ips = list;
96 return count;
99 #endif /* defined(WITH_DNS_UPDATES) */