View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.server.dns.io.encoder;
22  
23  
24  import java.net.InetAddress;
25  import java.net.UnknownHostException;
26  
27  import org.apache.directory.server.dns.messages.ResourceRecord;
28  import org.apache.directory.server.dns.store.DnsAttribute;
29  import org.apache.mina.common.ByteBuffer;
30  
31  
32  /**
33   * 3.4.1. A RDATA format
34   * 
35   *  +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
36   *  |                    ADDRESS                    |
37   *  +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
38   * 
39   * where:
40   * 
41   * ADDRESS         A 32 bit Internet address.
42   * 
43   * Hosts that have multiple Internet addresses will have multiple A
44   * records.
45   * 
46   * A records cause no additional section processing.  The RDATA section of
47   * an A line in a master file is an Internet address expressed as four
48   * decimal numbers separated by dots without any imbedded spaces (e.g.,
49   * "10.2.0.52" or "192.0.5.6").
50   * 
51   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
52   * @version $Rev: 501531 $, $Date: 2007-01-30 20:51:18 +0100 (Di, 30 Jan 2007) $
53   */
54  public class AddressRecordEncoder extends ResourceRecordEncoder
55  {
56      protected void putResourceRecordData( ByteBuffer byteBuffer, ResourceRecord record )
57      {
58          String ipAddress = record.get( DnsAttribute.IP_ADDRESS );
59  
60          try
61          {
62              byteBuffer.put( InetAddress.getByName( ipAddress ).getAddress() );
63          }
64          catch ( UnknownHostException uhe )
65          {
66          }
67      }
68  }