static struct rr *aaaa_parse(char *name, long ttl, int type, char *s) { struct rr_aaaa *rr = getmem(sizeof(*rr)); if (extract_ipv6(&s, "IPv6 address", &rr->address) <= 0) return NULL; if (*s) { return bitch("garbage after valid AAAA data"); } return store_record(type, name, ttl, rr); }
extern int str2sock(n2n_sock_t *out, const n2n_sock_str_t str_orig) { int retval; char *last_colon_pos = NULL; n2n_sock_str_t str; memcpy(str, str_orig, sizeof(n2n_sock_str_t)); last_colon_pos = strrchr(str, ':'); if (strchr(str, ':') == last_colon_pos) { if (last_colon_pos) //TODO { *last_colon_pos = '\0'; out->port = atoi(last_colon_pos + 1); out->port = htons(out->port); } out->family = AF_INET; retval = extract_ipv4(out, str); } else { char *from_pos = strchr(str, '['); if (from_pos) { char *to_pos = strchr(str, ']'); if (!to_pos) return -1;//TODO if (to_pos < last_colon_pos) //TODO { //*last_colon_pos = '\0'; out->port = atoi(last_colon_pos + 1); out->port = htons(out->port); } from_pos += 1; *to_pos = 0; } else from_pos = str; out->family = AF_INET6; retval = extract_ipv6(out, from_pos); } return retval; }
static struct rr *ipseckey_parse(char *name, long ttl, int type, char *s) { struct rr_ipseckey *rr = getmem(sizeof(*rr)); int i; rr->precedence = i = extract_integer(&s, "precedence", NULL); if (i < 0) return NULL; if (i >= 256) return bitch("precedence range is not valid"); rr->gateway_type = i = extract_integer(&s, "gateway type", NULL); if (i < 0) return NULL; if (i > 3) return bitch("gateway type is not valid"); rr->algorithm = i = extract_integer(&s, "algorithm", NULL); if (i < 0) return NULL; if (i > 2) return bitch("algorithm is not valid"); switch (rr->gateway_type) { case 0: rr->gateway.gateway_none = extract_name(&s, "gateway/.", KEEP_CAPITALIZATION); if (!rr->gateway.gateway_none) return NULL; if (strcmp(rr->gateway.gateway_none, ".") != 0) return bitch("gateway must be \".\" for gateway type 0"); break; case 1: if (extract_ipv4(&s, "gateway/IPv4", &rr->gateway.gateway_ipv4) <= 0) return NULL; break; case 2: if (extract_ipv6(&s, "gateway/IPv6", &rr->gateway.gateway_ipv6) <= 0) return NULL; break; case 3: rr->gateway.gateway_name = extract_name(&s, "gateway/name", KEEP_CAPITALIZATION); if (!rr->gateway.gateway_name) return NULL; break; default: croakx(7, "assertion failed: gateway type %d not within range", rr->gateway_type); } /* My reading of http://tools.ietf.org/html/rfc4025 is fuzzy on: * * - whether it is possible to have algorithm 0 and non-empty key; * - whether it is possible to have empty key and algorithm != 0. * * Here I assume "not possible" for both. */ switch (rr->algorithm) { case 0: break; case 1: /* DSA key */ rr->public_key = extract_base64_binary_data(&s, "public key"); if (rr->public_key.length < 0) return NULL; break; case 2: /* RSA key */ rr->public_key = extract_base64_binary_data(&s, "public key"); if (rr->public_key.length < 0) return NULL; break; default: croakx(7, "assertion failed: algorithm %d not within range", rr->algorithm); } if (*s) { return bitch("garbage after valid IPSECKEY data"); } return store_record(type, name, ttl, rr); }