1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.dns;
21
22
23 import java.io.IOException;
24 import java.net.InetSocketAddress;
25
26 import org.apache.directory.server.dns.protocol.DnsProtocolHandler;
27 import org.apache.directory.server.dns.store.RecordStore;
28 import org.apache.directory.server.dns.store.jndi.JndiRecordStoreImpl;
29 import org.apache.directory.server.protocol.shared.DirectoryBackedService;
30 import org.apache.mina.transport.socket.nio.DatagramAcceptorConfig;
31 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
32
33
34
35
36
37
38
39
40
41
42 public class DnsServer extends DirectoryBackedService
43 {
44 private static final long serialVersionUID = 6943138644427163149L;
45
46
47 private static final int IP_PORT_DEFAULT = 53;
48
49
50 private static final String SERVICE_PID_DEFAULT = "org.apache.directory.server.dns";
51
52
53 private static final String SERVICE_NAME_DEFAULT = "ApacheDS DNS Service";
54
55
56
57
58
59 public DnsServer()
60 {
61 super.setIpPort( IP_PORT_DEFAULT );
62 super.setServiceId( SERVICE_PID_DEFAULT );
63 super.setServiceName( SERVICE_NAME_DEFAULT );
64 }
65
66
67
68
69
70 public void start() throws IOException
71 {
72 RecordStore store = new JndiRecordStoreImpl( getSearchBaseDn(), getSearchBaseDn(), getDirectoryService() );
73
74 if ( getDatagramAcceptor() != null )
75 {
76 DatagramAcceptorConfig udpConfig = new DatagramAcceptorConfig();
77 getDatagramAcceptor().bind( new InetSocketAddress( getIpPort() ), new DnsProtocolHandler( this, store ), udpConfig );
78 }
79
80 if ( getSocketAcceptor() != null )
81 {
82 SocketAcceptorConfig tcpConfig = new SocketAcceptorConfig();
83 tcpConfig.setDisconnectOnUnbind( false );
84 tcpConfig.setReuseAddress( true );
85 getSocketAcceptor().bind( new InetSocketAddress( getIpPort() ), new DnsProtocolHandler( this, store ), tcpConfig );
86 }
87 }
88
89
90 public void stop() {
91 if ( getDatagramAcceptor() != null )
92 {
93 getDatagramAcceptor().unbind( new InetSocketAddress( getIpPort() ));
94 }
95 if ( getSocketAcceptor() != null )
96 {
97 getSocketAcceptor().unbind( new InetSocketAddress( getIpPort() ));
98 }
99 }
100 }