1825eb42bSJan Lentfer /** 2825eb42bSJan Lentfer * str2host.h - conversion from str to the host fmt 3825eb42bSJan Lentfer * 4825eb42bSJan Lentfer * a Net::DNS like library for C 5825eb42bSJan Lentfer * 6825eb42bSJan Lentfer * (c) NLnet Labs, 2005-2006 7825eb42bSJan Lentfer * 8825eb42bSJan Lentfer * See the file LICENSE for the license 9825eb42bSJan Lentfer */ 10825eb42bSJan Lentfer 11825eb42bSJan Lentfer #ifndef LDNS_2HOST_H 12825eb42bSJan Lentfer #define LDNS_2HOST_H 13825eb42bSJan Lentfer 14825eb42bSJan Lentfer #include <ldns/common.h> 15825eb42bSJan Lentfer #include <ldns/error.h> 16825eb42bSJan Lentfer #include <ldns/rr.h> 17825eb42bSJan Lentfer #include <ldns/rdata.h> 18825eb42bSJan Lentfer #include <ldns/packet.h> 19825eb42bSJan Lentfer #include <ldns/buffer.h> 20825eb42bSJan Lentfer #include <ctype.h> 21825eb42bSJan Lentfer 22ac996e71SJan Lentfer #ifdef __cplusplus 23ac996e71SJan Lentfer extern "C" { 24ac996e71SJan Lentfer #endif 25ac996e71SJan Lentfer 26825eb42bSJan Lentfer /** 27825eb42bSJan Lentfer * \file 28825eb42bSJan Lentfer * 29825eb42bSJan Lentfer * Defines functions to convert dns data in presentation format or text files 30825eb42bSJan Lentfer * to internal structures. 31825eb42bSJan Lentfer */ 32825eb42bSJan Lentfer 33825eb42bSJan Lentfer /** 34825eb42bSJan Lentfer * convert a byte into wireformat 35*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 36825eb42bSJan Lentfer * \param[in] bytestr the string to be converted 37825eb42bSJan Lentfer * \return ldns_status 38825eb42bSJan Lentfer */ 39825eb42bSJan Lentfer ldns_status ldns_str2rdf_int8(ldns_rdf **rd, const char *bytestr); 40825eb42bSJan Lentfer 41825eb42bSJan Lentfer /** 42825eb42bSJan Lentfer * convert a string to a int16 in wireformat 43*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 44825eb42bSJan Lentfer * \param[in] shortstr the string to be converted 45825eb42bSJan Lentfer * \return ldns_status 46825eb42bSJan Lentfer */ 47825eb42bSJan Lentfer ldns_status ldns_str2rdf_int16(ldns_rdf **rd, const char *shortstr); 48825eb42bSJan Lentfer 49825eb42bSJan Lentfer /** 50825eb42bSJan Lentfer * convert a strings into a 4 byte int in wireformat 51*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 52825eb42bSJan Lentfer * \param[in] longstr the string to be converted 53825eb42bSJan Lentfer * \return ldns_status 54825eb42bSJan Lentfer */ 55825eb42bSJan Lentfer ldns_status ldns_str2rdf_int32(ldns_rdf **rd, const char *longstr); 56825eb42bSJan Lentfer 57825eb42bSJan Lentfer /** 58825eb42bSJan Lentfer * convert a time string to a time value in wireformat 59*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 60825eb42bSJan Lentfer * \param[in] time the string to be converted 61825eb42bSJan Lentfer * \return ldns_status 62825eb42bSJan Lentfer */ 63825eb42bSJan Lentfer ldns_status ldns_str2rdf_time(ldns_rdf **rd, const char *time); 64825eb42bSJan Lentfer 65825eb42bSJan Lentfer /* convert string with NSEC3 salt to wireformat) 66*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 67825eb42bSJan Lentfer * \param[in] str the string to be converted 68825eb42bSJan Lentfer * return ldns_status 69825eb42bSJan Lentfer */ 70825eb42bSJan Lentfer ldns_status ldns_str2rdf_nsec3_salt(ldns_rdf **rd, const char *nsec3_salt); 71825eb42bSJan Lentfer 72825eb42bSJan Lentfer /* convert a time period (think TTL's) to wireformat) 73*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 74825eb42bSJan Lentfer * \param[in] str the string to be converted 75825eb42bSJan Lentfer * return ldns_status 76825eb42bSJan Lentfer */ 77825eb42bSJan Lentfer ldns_status ldns_str2rdf_period(ldns_rdf **rd, const char *str); 78825eb42bSJan Lentfer 79825eb42bSJan Lentfer /** 80825eb42bSJan Lentfer * convert str with an A record into wireformat 81*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 82825eb42bSJan Lentfer * \param[in] str the string to be converted 83825eb42bSJan Lentfer * \return ldns_status 84825eb42bSJan Lentfer */ 85825eb42bSJan Lentfer ldns_status ldns_str2rdf_a(ldns_rdf **rd, const char *str); 86825eb42bSJan Lentfer 87825eb42bSJan Lentfer /** 88825eb42bSJan Lentfer * convert the str with an AAAA record into wireformat 89*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 90825eb42bSJan Lentfer * \param[in] str the string to be converted 91825eb42bSJan Lentfer * \return ldns_status 92825eb42bSJan Lentfer */ 93825eb42bSJan Lentfer ldns_status ldns_str2rdf_aaaa(ldns_rdf **rd, const char *str); 94825eb42bSJan Lentfer 95825eb42bSJan Lentfer /** 96825eb42bSJan Lentfer * convert a string into wireformat (think txt record) 97*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 98825eb42bSJan Lentfer * \param[in] str the string to be converted (NULL terminated) 99825eb42bSJan Lentfer * \return ldns_status 100825eb42bSJan Lentfer */ 101825eb42bSJan Lentfer ldns_status ldns_str2rdf_str(ldns_rdf **rd, const char *str); 102825eb42bSJan Lentfer 103825eb42bSJan Lentfer /** 104825eb42bSJan Lentfer * convert str with the apl record into wireformat 105*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 106825eb42bSJan Lentfer * \param[in] str the string to be converted 107825eb42bSJan Lentfer * \return ldns_status 108825eb42bSJan Lentfer */ 109825eb42bSJan Lentfer ldns_status ldns_str2rdf_apl(ldns_rdf **rd, const char *str); 110825eb42bSJan Lentfer 111825eb42bSJan Lentfer /** 112825eb42bSJan Lentfer * convert the string with the b64 data into wireformat 113*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 114825eb42bSJan Lentfer * \param[in] str the string to be converted 115825eb42bSJan Lentfer * \return ldns_status 116825eb42bSJan Lentfer */ 117825eb42bSJan Lentfer ldns_status ldns_str2rdf_b64(ldns_rdf **rd, const char *str); 118825eb42bSJan Lentfer 119825eb42bSJan Lentfer /** 120825eb42bSJan Lentfer * convert the string with the b32 ext hex data into wireformat 121*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 122825eb42bSJan Lentfer * \param[in] str the string to be converted 123825eb42bSJan Lentfer * \return ldns_status 124825eb42bSJan Lentfer */ 125825eb42bSJan Lentfer ldns_status ldns_str2rdf_b32_ext(ldns_rdf **rd, const char *str); 126825eb42bSJan Lentfer 127825eb42bSJan Lentfer /** 128825eb42bSJan Lentfer * convert a hex value into wireformat 129*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 130825eb42bSJan Lentfer * \param[in] str the string to be converted 131825eb42bSJan Lentfer * \return ldns_status 132825eb42bSJan Lentfer */ 133825eb42bSJan Lentfer ldns_status ldns_str2rdf_hex(ldns_rdf **rd, const char *str); 134825eb42bSJan Lentfer 135825eb42bSJan Lentfer /** 136825eb42bSJan Lentfer * convert string with nsec into wireformat 137*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 138825eb42bSJan Lentfer * \param[in] str the string to be converted 139825eb42bSJan Lentfer * \return ldns_status 140825eb42bSJan Lentfer */ 141825eb42bSJan Lentfer ldns_status ldns_str2rdf_nsec(ldns_rdf **rd, const char *str); 142825eb42bSJan Lentfer 143825eb42bSJan Lentfer /** 144825eb42bSJan Lentfer * convert a rrtype into wireformat 145*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 146825eb42bSJan Lentfer * \param[in] str the string to be converted 147825eb42bSJan Lentfer * \return ldns_status 148825eb42bSJan Lentfer */ 149825eb42bSJan Lentfer ldns_status ldns_str2rdf_type(ldns_rdf **rd, const char *str); 150825eb42bSJan Lentfer 151825eb42bSJan Lentfer /** 152825eb42bSJan Lentfer * convert string with a classname into wireformat 153*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 154825eb42bSJan Lentfer * \param[in] str the string to be converted 155825eb42bSJan Lentfer * \return ldns_status 156825eb42bSJan Lentfer */ 157825eb42bSJan Lentfer ldns_status ldns_str2rdf_class(ldns_rdf **rd, const char *str); 158825eb42bSJan Lentfer 159825eb42bSJan Lentfer /** 160825eb42bSJan Lentfer * convert an certificate algorithm value into wireformat 161*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 162825eb42bSJan Lentfer * \param[in] str the string to be converted 163825eb42bSJan Lentfer * \return ldns_status 164825eb42bSJan Lentfer */ 165825eb42bSJan Lentfer ldns_status ldns_str2rdf_cert_alg(ldns_rdf **rd, const char *str); 166825eb42bSJan Lentfer 167825eb42bSJan Lentfer /** 1685340022aSzrj * convert an algorithm value into wireformat 169*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 170825eb42bSJan Lentfer * \param[in] str the string to be converted 171825eb42bSJan Lentfer * \return ldns_status 172825eb42bSJan Lentfer */ 173825eb42bSJan Lentfer ldns_status ldns_str2rdf_alg(ldns_rdf **rd, const char *str); 174825eb42bSJan Lentfer 175825eb42bSJan Lentfer /** 1765340022aSzrj * convert a tlsa certificate usage value into wireformat 177*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 1785340022aSzrj * \param[in] str the string to be converted 1795340022aSzrj * \return ldns_status 1805340022aSzrj */ 1815340022aSzrj ldns_status ldns_str2rdf_certificate_usage(ldns_rdf **rd, const char *str); 1825340022aSzrj 1835340022aSzrj /** 1845340022aSzrj * convert a tlsa selector value into wireformat 185*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 1865340022aSzrj * \param[in] str the string to be converted 1875340022aSzrj * \return ldns_status 1885340022aSzrj */ 1895340022aSzrj ldns_status ldns_str2rdf_selector(ldns_rdf **rd, const char *str); 1905340022aSzrj 1915340022aSzrj /** 1925340022aSzrj * convert a tlsa matching type value into wireformat 193*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 1945340022aSzrj * \param[in] str the string to be converted 1955340022aSzrj * \return ldns_status 1965340022aSzrj */ 1975340022aSzrj ldns_status ldns_str2rdf_matching_type(ldns_rdf **rd, const char *str); 1985340022aSzrj 1995340022aSzrj /** 200825eb42bSJan Lentfer * convert a string with a unknown RR into wireformat 201*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 202825eb42bSJan Lentfer * \param[in] str the string to be converted 203825eb42bSJan Lentfer * \return ldns_status 204825eb42bSJan Lentfer */ 205825eb42bSJan Lentfer ldns_status ldns_str2rdf_unknown(ldns_rdf **rd, const char *str); 206825eb42bSJan Lentfer 207825eb42bSJan Lentfer /** 208825eb42bSJan Lentfer * convert string with a protocol service into wireformat 209*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 210825eb42bSJan Lentfer * \param[in] str the string to be converted 211825eb42bSJan Lentfer * \return ldns_status 212825eb42bSJan Lentfer */ 213825eb42bSJan Lentfer ldns_status ldns_str2rdf_service(ldns_rdf **rd, const char *str); 214825eb42bSJan Lentfer 215825eb42bSJan Lentfer /** 216825eb42bSJan Lentfer * convert a string with a LOC RR into wireformat 217*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 218825eb42bSJan Lentfer * \param[in] str the string to be converted 219825eb42bSJan Lentfer * \return ldns_status 220825eb42bSJan Lentfer */ 221825eb42bSJan Lentfer ldns_status ldns_str2rdf_loc(ldns_rdf **rd, const char *str); 222825eb42bSJan Lentfer 223825eb42bSJan Lentfer /** 224825eb42bSJan Lentfer * convert string with a WKS RR into wireformat 225*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 226825eb42bSJan Lentfer * \param[in] str the string to be converted 227825eb42bSJan Lentfer * \return ldns_status 228825eb42bSJan Lentfer */ 229825eb42bSJan Lentfer ldns_status ldns_str2rdf_wks(ldns_rdf **rd, const char *str); 230825eb42bSJan Lentfer 231825eb42bSJan Lentfer /** 232825eb42bSJan Lentfer * convert a str with a NSAP RR into wireformat 233*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 234825eb42bSJan Lentfer * \param[in] str the string to be converted 235825eb42bSJan Lentfer * \return ldns_status 236825eb42bSJan Lentfer */ 237825eb42bSJan Lentfer ldns_status ldns_str2rdf_nsap(ldns_rdf **rd, const char *str); 238825eb42bSJan Lentfer 239825eb42bSJan Lentfer /** 240825eb42bSJan Lentfer * convert a str with a ATMA RR into wireformat 241*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 242825eb42bSJan Lentfer * \param[in] str the string to be converted 243825eb42bSJan Lentfer * \return ldns_status 244825eb42bSJan Lentfer */ 245825eb42bSJan Lentfer ldns_status ldns_str2rdf_atma(ldns_rdf **rd, const char *str); 246825eb42bSJan Lentfer 247825eb42bSJan Lentfer /** 248825eb42bSJan Lentfer * convert a str with a IPSECKEY RR into wireformat 249*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 250825eb42bSJan Lentfer * \param[in] str the string to be converted 251825eb42bSJan Lentfer * \return ldns_status 252825eb42bSJan Lentfer */ 253825eb42bSJan Lentfer ldns_status ldns_str2rdf_ipseckey(ldns_rdf **rd, const char *str); 254825eb42bSJan Lentfer 255825eb42bSJan Lentfer /** 256825eb42bSJan Lentfer * convert a dname string into wireformat 257*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 258825eb42bSJan Lentfer * \param[in] str the string to be converted 259825eb42bSJan Lentfer * \return ldns_status 260825eb42bSJan Lentfer */ 261825eb42bSJan Lentfer ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str); 262825eb42bSJan Lentfer 2635340022aSzrj /** 2645340022aSzrj * convert 4 * 16bit hex separated by colons into wireformat 265*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 2665340022aSzrj * \param[in] str the string to be converted 2675340022aSzrj * \return ldns_status 2685340022aSzrj */ 2695340022aSzrj ldns_status ldns_str2rdf_ilnp64(ldns_rdf **rd, const char *str); 2705340022aSzrj 2715340022aSzrj /** 2725340022aSzrj * convert 6 hex bytes separated by dashes into wireformat 273*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 2745340022aSzrj * \param[in] str the string to be converted 2755340022aSzrj * \return ldns_status 2765340022aSzrj */ 2775340022aSzrj ldns_status ldns_str2rdf_eui48(ldns_rdf **rd, const char *str); 2785340022aSzrj 2795340022aSzrj /** 2805340022aSzrj * convert 8 hex bytes separated by dashes into wireformat 281*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 2825340022aSzrj * \param[in] str the string to be converted 2835340022aSzrj * \return ldns_status 2845340022aSzrj */ 2855340022aSzrj ldns_status ldns_str2rdf_eui64(ldns_rdf **rd, const char *str); 2865340022aSzrj 2875340022aSzrj /** 2885340022aSzrj * Convert a non-zero sequence of US-ASCII letters and numbers into wireformat 289*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 2905340022aSzrj * \param[in] str the string to be converted 2915340022aSzrj * \return ldns_status 2925340022aSzrj */ 2935340022aSzrj ldns_status ldns_str2rdf_tag(ldns_rdf **rd, const char *str); 2945340022aSzrj 2955340022aSzrj /** 2965340022aSzrj * Convert a <character-string> encoding of the value field as specified 2975340022aSzrj * [RFC1035], Section 5.1., encoded as one bug chunk of data. 298*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 2995340022aSzrj * \param[in] str the string to be converted 3005340022aSzrj * \return ldns_status 3015340022aSzrj */ 3025340022aSzrj ldns_status ldns_str2rdf_long_str(ldns_rdf **rd, const char *str); 3035340022aSzrj 3045340022aSzrj /** 3055340022aSzrj * Convert a "<algorithm> <hit> <pk>" encoding of the value field as specified 3065340022aSzrj * in Section 6. of [RFC5205], encoded as wireformat as specified in Section 5. 3075340022aSzrj * of [RFC5205]. 308*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 3095340022aSzrj * \param[in] str the string to be converted 3105340022aSzrj * \return ldns_status 3115340022aSzrj */ 3125340022aSzrj ldns_status ldns_str2rdf_hip(ldns_rdf **rd, const char *str); 3135340022aSzrj 314819dec71SDaniel Fojt /** 315*ee791febSAntonio Huete Jimenez * Convert a "<precedence> <D-bit> <type> <relay>" encoding 316819dec71SDaniel Fojt * of the value field as specified in Section 4.3.1 of 317819dec71SDaniel Fojt * [draft-ietf-mboned-driad-amt-discovery], encoded as wireformat as specified in 318*ee791febSAntonio Huete Jimenez * Section 4.2 of [draft-ietf-mboned-driad-amt-discovery] 319*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 320819dec71SDaniel Fojt * \param[in] str the string to be converted 321819dec71SDaniel Fojt * \return ldns_status 322819dec71SDaniel Fojt */ 323819dec71SDaniel Fojt ldns_status ldns_str2rdf_amtrelay(ldns_rdf **rd, const char *str); 3245340022aSzrj 325*ee791febSAntonio Huete Jimenez /** 326*ee791febSAntonio Huete Jimenez * Convert a series of "key[=<value>]" encodings to wireformat as described in 327*ee791febSAntonio Huete Jimenez * [draft-ietf-dnsop-svcb-https]. 328*ee791febSAntonio Huete Jimenez * \param[out] rd the rdf where to put the data 329*ee791febSAntonio Huete Jimenez * \param[in] str the string to be converted 330*ee791febSAntonio Huete Jimenez * \return ldns_status 331*ee791febSAntonio Huete Jimenez */ 332*ee791febSAntonio Huete Jimenez ldns_status ldns_str2rdf_svcparams(ldns_rdf **rd, const char *str); 333*ee791febSAntonio Huete Jimenez 334*ee791febSAntonio Huete Jimenez 335ac996e71SJan Lentfer #ifdef __cplusplus 336ac996e71SJan Lentfer } 337ac996e71SJan Lentfer #endif 338ac996e71SJan Lentfer 339825eb42bSJan Lentfer #endif /* LDNS_2HOST_H */ 340