r18019: Fix a C++ warnings: Don't use void * in libads/ for LDAPMessage anymore.
[kai/samba.git] / source3 / utils / net_dns.c
1
2 /* 
3    Samba Unix/Linux Dynamic DNS Update
4    net ads commands
5
6    Copyright (C) Krishna Ganugapati (krishnag@centeris.com)         2006
7    Copyright (C) Gerald Carter                                      2006
8
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.
13    
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.
18    
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.  
22 */
23
24 #include "includes.h"
25 #include "utils/net.h"
26 #include "dns.h"
27
28 #if defined(WITH_DNS_UPDATES)
29
30 /*********************************************************************
31 *********************************************************************/
32
33 int DoDNSUpdate( char *pszServerName, const char *pszDomainName,
34                  char *pszHostName, struct in_addr *iplist, int num_addrs )
35 {
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
44
45         if ( (num_addrs <= 0) || !iplist ) {
46                 return -1;
47         }
48                 
49         dns_status = DNSOpen( pszServerName, DNS_TCP, &hDNSServer );
50         BAIL_ON_DNS_ERROR( dns_status );
51
52         dwError = DNSSendUpdate( hDNSServer, pszDomainName, pszHostName, 
53                                  iplist, num_addrs, &pDNSUpdateResponse );
54         BAIL_ON_ERROR( dwError );
55
56         dwError = DNSUpdateGetResponseCode( pDNSUpdateResponse,
57                                             &dwResponseCode );
58         if ( dwResponseCode == DNS_REFUSED ) {
59                 dwError = -1;
60         }
61         BAIL_ON_ERROR( dwError );
62
63 cleanup:
64         return dwError;
65
66 error:
67         goto cleanup;
68 }
69
70 /*********************************************************************
71 *********************************************************************/
72
73 int get_my_ip_address( struct in_addr **ips )
74 {
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;
80
81         /* find the first non-loopback address from our list of interfaces */
82
83         n = get_interfaces(nics, MAX_INTERFACES);
84         
85         if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) {
86                 return -1;
87         }
88
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 ) );
92                 }
93         }
94         *ips = list;
95
96         return count;
97 }
98
99 #endif  /* defined(WITH_DNS_UPDATES) */