#include <cstdlib>
#include <sys/types.h>
#include <string>
-#include <errno.h>
+#include <cerrno>
#include "dnsrecords.hh"
-static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
- 1000000,10000000,100000000,1000000000};
+const static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+ 1000000,10000000,100000000,1000000000};
/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer.*/
static uint8_t precsize_aton(const char **strptr)
while (isdigit(*cp))
deg = deg * 10 + (*cp++ - '0');
-
+
while (isspace(*cp))
cp++;
-
+
if (!(isdigit(*cp)))
goto fndhemi;
-
+
while (isdigit(*cp))
min = min * 10 + (*cp++ - '0');
-
+
while (isspace(*cp))
cp++;
-
+
if (*cp && !(isdigit(*cp)))
goto fndhemi;
-
+
while (isdigit(*cp))
secs = secs * 10 + (*cp++ - '0');
}
}
}
-
+
while (*cp && !isspace(*cp)) /* if any trailing garbage */
cp++;
-
+
while (isspace(*cp))
cp++;
-
+
fndhemi:
switch (*cp) {
case 'N': case 'n':
retval = 0; /* invalid value -- indicates error */
break;
}
-
+
switch (*cp) {
case 'N': case 'n':
case 'S': case 's':
return 0;
cp++; /* skip the hemisphere */
-
+
while (*cp && !isspace(*cp)) /* if any trailing garbage */
cp++;
-
+
while (isspace(*cp)) /* move to next field */
cp++;
-
+
*latlonstrptr = cp;
-
+
return (retval);
}
}
-void LOCRecordContent::toPacket(DNSPacketWriter& pw)
+void LOCRecordContent::toPacket(DNSPacketWriter& pw) const
{
pw.xfr8BitInt(d_version);
pw.xfr8BitInt(d_size);
pw.xfr32BitInt(d_altitude);
}
-std::shared_ptr<LOCRecordContent::DNSRecordContent> LOCRecordContent::make(const DNSRecord &dr, PacketReader& pr)
+std::shared_ptr<LOCRecordContent::DNSRecordContent> LOCRecordContent::make(const DNSRecord& /* dr */, PacketReader& pr)
{
auto ret=std::make_shared<LOCRecordContent>();
pr.xfr8BitInt(ret->d_version);
pr.xfr32BitInt(ret->d_latitude);
pr.xfr32BitInt(ret->d_longitude);
pr.xfr32BitInt(ret->d_altitude);
-
+
return ret;
}
-LOCRecordContent::LOCRecordContent(const string& content, const string& zone)
+LOCRecordContent::LOCRecordContent(const string& content, const string& /* zone */)
{
// 51 59 00.000 N 5 55 00.000 E 4.00m 1.00m 10000.00m 10.00m
// convert this to d_version, d_size, d_horiz/vertpre, d_latitude, d_longitude, d_altitude
d_version = 0;
const char *cp, *maxcp;
-
+
uint32_t lltemp1 = 0, lltemp2 = 0;
int altmeters = 0, altfrac = 0, altsign = 1;
d_horizpre = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
if (*cp == '+')
cp++;
-
+
while (isdigit(*cp))
altmeters = altmeters * 10 + (*cp++ - '0');
-
+
if (*cp == '.') { /* decimal meters */
cp++;
if (isdigit(*cp)) {
}
}
}
-
+
d_altitude = (10000000 + (altsign * (altmeters * 100 + altfrac)));
-
+
while (!isspace(*cp) && (cp < maxcp))
/* if trailing garbage or m */
cp++;
-
+
while (isspace(*cp) && (cp < maxcp))
cp++;
-
-
+
+
if (cp >= maxcp)
goto defaults;
-
+
d_size = precsize_aton(&cp);
-
+
while (!isspace(*cp) && (cp < maxcp))/*if trailing garbage or m*/
cp++;
-
+
while (isspace(*cp) && (cp < maxcp))
cp++;
-
+
if (cp >= maxcp)
goto defaults;
-
+
d_horizpre = precsize_aton(&cp);
-
+
while (!isspace(*cp) && (cp < maxcp))/*if trailing garbage or m*/
cp++;
-
+
while (isspace(*cp) && (cp < maxcp))
cp++;
-
+
if (cp >= maxcp)
goto defaults;
-
+
d_vertpre = precsize_aton(&cp);
-
+
defaults:
;
}
-string LOCRecordContent::getZoneRepresentation(bool noDot) const
+string LOCRecordContent::getZoneRepresentation(bool /* noDot */) const
{
// convert d_version, d_size, d_horiz/vertpre, d_latitude, d_longitude, d_altitude to:
// 51 59 00.000 N 5 55 00.000 E 4.00m 1.00m 10000.00m 10.00m
double latitude= ((int32_t)((uint32_t)d_latitude - ((uint32_t)1<<31)))/3600000.0;
double longitude=((int32_t)((uint32_t)d_longitude - ((uint32_t)1<<31)))/3600000.0;
double altitude= ((int32_t)d_altitude )/100.0 - 100000;
-
+
double size=0.01*((d_size>>4)&0xf);
int count=d_size & 0xf;
while(count--)