reSIProcate/rutil  9694
DnsHostRecord.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include <stdlib.h>
00006 
00007 #include "AresCompat.hxx"
00008 
00009 #ifndef __CYGWIN__
00010 #ifndef RRFIXEDSZ
00011 #define RRFIXEDSZ 10
00012 #endif
00013 #ifndef NS_RRFIXEDSZ
00014 #define NS_RRFIXEDSZ 10
00015 #endif
00016 #endif
00017 
00018 #include "rutil/Data.hxx"
00019 #include "rutil/DnsUtil.hxx"
00020 #include "rutil/BaseException.hxx"
00021 #include "RROverlay.hxx"
00022 #include "DnsResourceRecord.hxx"
00023 #include "DnsHostRecord.hxx"
00024 
00025 using namespace resip;
00026 
00027 DnsHostRecord::DnsHostRecord(const RROverlay& overlay)
00028 {
00029    char* name = 0;
00030    long len = 0;
00031    int status = ares_expand_name(overlay.data()-overlay.nameLength()-RRFIXEDSZ, overlay.msg(), overlay.msgLength(), &name, &len);
00032    (void)status;
00033    assert(status == ARES_SUCCESS);      // .kw. what should we do if bad?
00034    mName = name;
00035    free(name);
00036    memcpy(&mAddr, overlay.data(), sizeof(in_addr));
00037 }
00038 
00039 Data DnsHostRecord::host() const
00040 {
00041    return Data(inet_ntoa(mAddr));
00042 }
00043 
00044 bool DnsHostRecord::isSameValue(const Data& value) const
00045 {
00046    return DnsUtil::inet_ntop(mAddr) == value;
00047 }
00048 
00049 EncodeStream&
00050 DnsHostRecord::dump(EncodeStream& strm) const
00051 {
00052    strm << mName << "(A)--> " << DnsUtil::inet_ntop(mAddr);
00053    return strm;
00054 }
00055 
00056 /* ====================================================================
00057  * The Vovida Software License, Version 1.0 
00058  * 
00059  * Copyright (c) 2000-2005 Vovida Networks, Inc.  All rights reserved.
00060  * 
00061  * Redistribution and use in source and binary forms, with or without
00062  * modification, are permitted provided that the following conditions
00063  * are met:
00064  * 
00065  * 1. Redistributions of source code must retain the above copyright
00066  *    notice, this list of conditions and the following disclaimer.
00067  * 
00068  * 2. Redistributions in binary form must reproduce the above copyright
00069  *    notice, this list of conditions and the following disclaimer in
00070  *    the documentation and/or other materials provided with the
00071  *    distribution.
00072  * 
00073  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00074  *    and "Vovida Open Communication Application Library (VOCAL)" must
00075  *    not be used to endorse or promote products derived from this
00076  *    software without prior written permission. For written
00077  *    permission, please contact vocal@vovida.org.
00078  *
00079  * 4. Products derived from this software may not be called "VOCAL", nor
00080  *    may "VOCAL" appear in their name, without prior written
00081  *    permission of Vovida Networks, Inc.
00082  * 
00083  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00084  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00085  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00086  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00087  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00088  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00089  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00090  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00091  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00092  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00093  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00094  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00095  * DAMAGE.
00096  * 
00097  * ====================================================================
00098  * 
00099  * This software consists of voluntary contributions made by Vovida
00100  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00101  * Inc.  For more information on Vovida Networks, Inc., please see
00102  * <http://www.vovida.org/>.
00103  *
00104  */
00105