17 #ifdef HAVE_SYS_SOCKET_H
18 #include <sys/socket.h>
20 #ifdef HAVE_ARPA_INET_H
21 #include <arpa/inet.h>
31 #ifdef HAVE_SYS_PARAM_H
32 #include <sys/param.h>
43 *r = htons((uint16_t)strtol((
char *)shortstr, &end, 10));
69 memset(&tm, 0,
sizeof(tm));
71 if (strlen(time) == 14 &&
72 sscanf(time,
"%4d%2d%2d%2d%2d%2d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 6
77 if (tm.tm_year < 70) {
80 if (tm.tm_mon < 0 || tm.tm_mon > 11) {
83 if (tm.tm_mday < 1 || tm.tm_mday > 31) {
87 if (tm.tm_hour < 0 || tm.tm_hour > 23) {
91 if (tm.tm_min < 0 || tm.tm_min > 59) {
95 if (tm.tm_sec < 0 || tm.tm_sec > 59) {
100 memcpy(r, &l,
sizeof(uint32_t));
107 l = htonl((uint32_t)strtol((
char*)time, &end, 10));
112 memcpy(r, &l,
sizeof(uint32_t));
138 salt_length_str = (int)strlen(salt_str);
139 if (salt_length_str == 1 && salt_str[0] ==
'-') {
141 }
else if (salt_length_str % 2 != 0) {
144 if (salt_length_str > 512) {
152 for (c = 0; c < salt_length_str; c += 2) {
153 if (isxdigit((
int) salt_str[c]) && isxdigit((
int) salt_str[c+1])) {
161 salt_length = (uint8_t) (salt_length_str / 2);
168 data[0] = salt_length;
169 memcpy(&data[1], salt, salt_length);
189 p = (uint32_t) htonl(p);
208 l = htonl((uint32_t)strtol((
char*)longstr, &end, 10));
209 else l = htonl((uint32_t)strtoul((
char*)longstr, &end, 10));
215 if (errno == ERANGE) {
219 memcpy(r, &l,
sizeof(uint32_t));
236 *r = (uint8_t)strtol((
char*)bytestr, &end, 10);
261 parse_escape(uint8_t *s, uint8_t *q) {
263 if (strlen((
char *)s) > 3 &&
264 isdigit((
int) s[1]) &&
265 isdigit((
int) s[2]) &&
266 isdigit((
int) s[3])) {
279 if (*s ==
'\0' || isdigit((
int) *s)) {
301 uint8_t *s, *q, *pq, label_len;
305 len = strlen((
char*)str);
315 if (1 == len && *str ==
'.') {
331 for (s = (uint8_t *)str; *s; s++, q++) {
341 if (label_len == 0) {
344 len += label_len + 1;
351 esc = parse_escape(s, q);
373 if (label_len == 0) {
376 len += label_len + 1;
390 if (inet_pton(AF_INET, (
char*)str, &address) != 1) {
404 if (inet_pton(AF_INET6, (
char*)str, address) != 1) {
417 size_t i, str_i, esc_i;
419 if (strlen(str) > 255) {
427 for (str_i = 0; str_i < strlen(str); str_i++) {
428 if (str[str_i] ==
'\\') {
430 esc_i = (size_t) parse_escape((uint8_t*) &str[str_i], (uint8_t*) &data[i]);
437 data[i] = (uint8_t) str[str_i];
451 const char *my_str = str;
458 uint8_t afdlength = 0;
467 if (strlen(my_str) < 2
468 || strchr(my_str,
':') == NULL
469 || strchr(my_str,
'/') == NULL
470 || strchr(my_str,
':') > strchr(my_str,
'/')) {
474 if (my_str[0] ==
'!') {
481 family = (uint16_t) atoi(my_str);
483 my_str = strchr(my_str,
':') + 1;
486 ip_str_len = (size_t) (strchr(my_str,
'/') - my_str);
489 strncpy(my_ip_str, my_str, ip_str_len + 1);
490 my_ip_str[ip_str_len] =
'\0';
499 if (inet_pton(AF_INET, my_ip_str, afdpart) == 0) {
504 for (i = 0; i < 4; i++) {
505 if (afdpart[i] != 0) {
509 }
else if (family == 2) {
516 if (inet_pton(AF_INET6, my_ip_str, afdpart) == 0) {
521 for (i = 0; i < 16; i++) {
522 if (afdpart[i] != 0) {
532 my_str = strchr(my_str,
'/') + 1;
533 prefix = (uint8_t) atoi(my_str);
541 ldns_write_uint16(data, family);
546 data[3] = data[3] | 0x80;
549 memcpy(data + 4, afdpart, afdlength);
565 buffer =
LDNS_XMALLOC(uint8_t, ldns_b64_ntop_calculate_size(strlen(str)));
571 ldns_b64_ntop_calculate_size(strlen(str)));
590 uint8_t len = ldns_b32_pton_calculate_size(strlen(str));
598 ldns_b32_ntop_calculate_size(strlen(str)));
631 if (isspace((
int) *str)) {
634 for (i = 16; i >= 1; i -= 15) {
635 while (*str && isspace((
int) *str)) { str++; }
637 if (isxdigit((
int) *str)) {
650 (
size_t) (t - t_orig),
660 const char *delimiters =
"\n\t ";
665 size_t type_count = 0;
686 if(type_count >=
sizeof(type_list)) {
692 type_list[type_count] = cur_type;
740 ldns_write_uint16(idd, (uint16_t) lt->
id);
812 loc_parse_cm(
char* my_str,
char** endstr, uint8_t* m, uint8_t* e)
816 uint32_t meters = 0, cm = 0, val;
817 while (isblank(*my_str)) {
820 meters = (uint32_t)strtol(my_str, &my_str, 10);
821 if (*my_str ==
'.') {
823 cm = (uint32_t)strtol(my_str, &my_str, 10);
840 if (*my_str ==
'm' || *my_str ==
'M') {
850 uint32_t latitude = 0;
851 uint32_t longitude = 0;
852 uint32_t altitude = 0;
855 uint32_t equator = (uint32_t) ldns_power(2, 31);
859 uint8_t size_b = 1, size_e = 2;
860 uint8_t horiz_pre_b = 1, horiz_pre_e = 6;
861 uint8_t vert_pre_b = 1, vert_pre_e = 3;
867 char *my_str = (
char *) str;
870 if (isdigit((
int) *my_str)) {
871 h = (uint32_t) strtol(my_str, &my_str, 10);
876 while (isblank((
int) *my_str)) {
880 if (isdigit((
int) *my_str)) {
881 m = (uint32_t) strtol(my_str, &my_str, 10);
882 }
else if (*my_str ==
'N' || *my_str ==
'S') {
888 while (isblank((
int) *my_str)) {
892 if (isdigit((
int) *my_str)) {
893 s = strtod(my_str, &my_str);
896 while (isblank((
int) *my_str)) {
900 if (*my_str ==
'N') {
902 }
else if (*my_str ==
'S') {
914 latitude = (uint32_t) s;
915 latitude += 1000 * 60 * m;
916 latitude += 1000 * 60 * 60 * h;
918 latitude = equator + latitude;
920 latitude = equator - latitude;
922 while (isblank(*my_str)) {
926 if (isdigit((
int) *my_str)) {
927 h = (uint32_t) strtol(my_str, &my_str, 10);
932 while (isblank((
int) *my_str)) {
936 if (isdigit((
int) *my_str)) {
937 m = (uint32_t) strtol(my_str, &my_str, 10);
938 }
else if (*my_str ==
'E' || *my_str ==
'W') {
944 while (isblank(*my_str)) {
948 if (isdigit((
int) *my_str)) {
949 s = strtod(my_str, &my_str);
953 while (isblank(*my_str)) {
957 if (*my_str ==
'E') {
959 }
else if (*my_str ==
'W') {
971 longitude = (uint32_t) s;
972 longitude += 1000 * 60 * m;
973 longitude += 1000 * 60 * 60 * h;
976 longitude += equator;
978 longitude = equator - longitude;
981 altitude = (uint32_t)(strtod(my_str, &my_str)*100.0 +
983 if (*my_str ==
'm' || *my_str ==
'M') {
987 if (strlen(my_str) > 0) {
988 if(!loc_parse_cm(my_str, &my_str, &size_b, &size_e))
992 if (strlen(my_str) > 0) {
993 if(!loc_parse_cm(my_str, &my_str, &horiz_pre_b, &horiz_pre_e))
997 if (strlen(my_str) > 0) {
998 if(!loc_parse_cm(my_str, &my_str, &vert_pre_b, &vert_pre_e))
1008 data[1] = ((size_b << 4) & 0xf0) | (size_e & 0x0f);
1009 data[2] = ((horiz_pre_b << 4) & 0xf0) | (horiz_pre_e & 0x0f);
1010 data[3] = ((vert_pre_b << 4) & 0xf0) | (vert_pre_e & 0x0f);
1011 ldns_write_uint32(data + 4, latitude);
1012 ldns_write_uint32(data + 8, longitude);
1013 ldns_write_uint32(data + 12, altitude);
1025 uint8_t *bitmap = NULL;
1029 struct protoent *proto = NULL;
1030 struct servent *serv = NULL;
1035 char *proto_str = NULL;
1037 if(strlen(str) == 0)
1053 proto_str = strdup(token);
1061 serv = getservbyname(token, proto_str);
1063 serv_port = (int) ntohs((uint16_t) serv->s_port);
1065 serv_port = atoi(token);
1067 if (serv_port / 8 >= bm_len) {
1068 uint8_t *b2 =
LDNS_XREALLOC(bitmap, uint8_t, (serv_port / 8) + 1);
1078 for (; bm_len <= serv_port / 8; bm_len++) {
1082 ldns_set_bit(bitmap + (serv_port / 8), 7 - (serv_port % 8),
true);
1086 if (!proto_str || !bitmap) {
1103 proto = getprotobyname(proto_str);
1105 data[0] = (uint8_t) proto->p_proto;
1106 }
else if (proto_str) {
1107 data[0] = (uint8_t) atoi(proto_str);
1109 memcpy(data + 1, bitmap, (
size_t) bm_len);
1118 #ifdef HAVE_ENDSERVENT
1121 #ifdef HAVE_ENDPROTOENT
1134 char* nsap_str = (
char*) str;
1137 if (str[0] !=
'0' || str[1] !=
'x') {
1141 for (i=0; i < len; i++) {
1142 if (nsap_str[i] ==
'.')
1153 char* atma_str = (
char*) str;
1158 for (i=0; i < len; i++) {
1159 if (atma_str[i] ==
'.')
1172 uint8_t precedence = 0;
1173 uint8_t gateway_type = 0;
1174 uint8_t algorithm = 0;
1175 char* gateway = NULL;
1176 char* publickey = NULL;
1180 int token_count = 0;
1181 int ipseckey_len = 0;
1186 if(strlen(str) == 0)
1200 switch (token_count) {
1202 precedence = (uint8_t)atoi(token);
1205 gateway_type = (uint8_t)atoi(token);
1208 algorithm = (uint8_t)atoi(token);
1211 gateway = strdup(token);
1212 if (!gateway || (gateway_type == 0 &&
1213 (token[0] !=
'.' || token[1] !=
'\0'))) {
1221 publickey = strdup(token);
1232 if (!gateway || !publickey) {
1242 if (gateway_type == 1) {
1244 }
else if (gateway_type == 2) {
1246 }
else if (gateway_type == 3) {
1292 data[0] = precedence;
1293 data[1] = gateway_type;
1294 data[2] = algorithm;