26#define PHP_DNS_NUM_TYPES 12
28#define PHP_DNS_A 0x00000001
29#define PHP_DNS_NS 0x00000002
30#define PHP_DNS_CNAME 0x00000010
31#define PHP_DNS_SOA 0x00000020
32#define PHP_DNS_PTR 0x00000800
33#define PHP_DNS_HINFO 0x00001000
34#define PHP_DNS_MX 0x00004000
35#define PHP_DNS_TXT 0x00008000
36#define PHP_DNS_A6 0x01000000
37#define PHP_DNS_SRV 0x02000000
38#define PHP_DNS_NAPTR 0x04000000
39#define PHP_DNS_AAAA 0x08000000
40#define PHP_DNS_ANY 0x10000000
41#define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA)
75 DNS_SRV_DATA *srv = &
pRec->Data.Srv;
77 if (
pRec->wType != DNS_TYPE_MX) {
101 int type = DNS_TYPE_MX;
145static void php_parserr(PDNS_RECORD
pRec,
int type_to_fetch,
int store,
bool raw,
zval *subarray)
155 if (type_to_fetch != DNS_TYPE_ANY &&
type != type_to_fetch) {
165 add_assoc_string(subarray,
"host",
pRec->pName);
166 add_assoc_string(subarray,
"class",
"IN");
167 add_assoc_long(subarray,
"ttl", ttl);
170 add_assoc_long(subarray,
"type",
type);
171 add_assoc_stringl(subarray,
"data", (
char*) &
pRec->Data, (uint32_t)
pRec->wDataLength);
178 char ip[INET_ADDRSTRLEN];
179 ipaddr.S_un.S_addr = (
pRec->Data.A.IpAddress);
183 add_assoc_string(subarray,
"type",
"A");
184 add_assoc_string(subarray,
"ip", ip);
190 add_assoc_string(subarray,
"type",
"MX");
191 add_assoc_long(subarray,
"pri",
pRec->Data.Srv.wPriority);
195 if (
type == DNS_TYPE_CNAME) {
196 add_assoc_string(subarray,
"type",
"CNAME");
201 if (
type == DNS_TYPE_NS) {
202 add_assoc_string(subarray,
"type",
"NS");
207 if (
type == DNS_TYPE_PTR) {
208 add_assoc_string(subarray,
"type",
"PTR");
210 add_assoc_string(subarray,
"target",
pRec->Data.MX.pNameExchange);
218 DNS_TXT_DATA *data_txt = &
pRec->Data.TXT;
225 add_assoc_string(subarray,
"type",
"TXT");
229 for (i = 0; i <
count; i++) {
230 txt_len +=
strlen(data_txt->pStringArray[i]);
233 txt = zend_string_alloc(txt_len, 0);
235 for (i = 0; i <
count; i++) {
236 size_t len =
strlen(data_txt->pStringArray[i]);
237 memcpy(txt_dst, data_txt->pStringArray[i],
len);
242 add_assoc_str(subarray,
"txt", txt);
243 add_assoc_zval(subarray,
"entries", &entries);
249 DNS_SOA_DATA *data_soa = &
pRec->Data.Soa;
251 add_assoc_string(subarray,
"type",
"SOA");
253 add_assoc_string(subarray,
"mname", data_soa->pNamePrimaryServer);
254 add_assoc_string(subarray,
"rname", data_soa->pNameAdministrator);
255 add_assoc_long(subarray,
"serial", data_soa->dwSerialNo);
256 add_assoc_long(subarray,
"refresh", data_soa->dwRefresh);
257 add_assoc_long(subarray,
"retry", data_soa->dwRetry);
258 add_assoc_long(subarray,
"expire", data_soa->dwExpire);
259 add_assoc_long(subarray,
"minimum-ttl", data_soa->dwDefaultTtl);
265 DNS_AAAA_DATA *data_aaaa = &
pRec->Data.AAAA;
266 char buf[
sizeof(
"AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA")];
269 unsigned short out[8];
270 int have_v6_break = 0, in_v6_break = 0;
272 for (i = 0; i < 4; ++i) {
273 DWORD chunk = data_aaaa->Ip6Address.IP6Dword[i];
274 out[i * 2] = htons(LOWORD(chunk));
275 out[i * 2 + 1] = htons(HIWORD(chunk));
278 for(i=0; i < 8; i++) {
280 if (tp > (uint8_t *)
buf) {
287 if (!have_v6_break) {
292 }
else if (!in_v6_break) {
301 if (have_v6_break && in_v6_break) {
307 add_assoc_string(subarray,
"type",
"AAAA");
308 add_assoc_string(subarray,
"ipv6",
buf);
320 DNS_SRV_DATA *data_srv = &
pRec->Data.Srv;
322 add_assoc_string(subarray,
"type",
"SRV");
323 add_assoc_long(subarray,
"pri", data_srv->wPriority);
324 add_assoc_long(subarray,
"weight", data_srv->wWeight);
325 add_assoc_long(subarray,
"port", data_srv->wPort);
326 add_assoc_string(subarray,
"target", data_srv->pNameTarget);
332 DNS_NAPTR_DATA * data_naptr = &
pRec->Data.Naptr;
334 add_assoc_string(subarray,
"type",
"NAPTR");
335 add_assoc_long(subarray,
"order", data_naptr->wOrder);
336 add_assoc_long(subarray,
"pref", data_naptr->wPreference);
337 add_assoc_string(subarray,
"flags", data_naptr->pFlags);
338 add_assoc_string(subarray,
"services", data_naptr->pService);
339 add_assoc_string(subarray,
"regex", data_naptr->pRegularExpression);
340 add_assoc_string(subarray,
"replacement", data_naptr->pReplacement);
360 int type, type_to_fetch, first_query = 1, store_results = 1;
369 authns = zend_try_array_init(authns);
375 addtl = zend_try_array_init(addtl);
387 if ((type_param < 1) || (type_param > 0xFFFF)) {
414 type_to_fetch = type_param;
419 type_to_fetch = type_param&
PHP_DNS_A ? DNS_TYPE_A : 0;
422 type_to_fetch = type_param&
PHP_DNS_NS ? DNS_TYPE_NS : 0;
425 type_to_fetch = type_param&
PHP_DNS_CNAME ? DNS_TYPE_CNAME : 0;
428 type_to_fetch = type_param&
PHP_DNS_SOA ? DNS_TYPE_SOA : 0;
431 type_to_fetch = type_param&
PHP_DNS_PTR ? DNS_TYPE_PTR : 0;
434 type_to_fetch = type_param&
PHP_DNS_HINFO ? DNS_TYPE_HINFO : 0;
437 type_to_fetch = type_param&
PHP_DNS_MX ? DNS_TYPE_MX : 0;
440 type_to_fetch = type_param&
PHP_DNS_TXT ? DNS_TYPE_TEXT : 0;
443 type_to_fetch = type_param&
PHP_DNS_AAAA ? DNS_TYPE_AAAA : 0;
446 type_to_fetch = type_param&
PHP_DNS_SRV ? DNS_TYPE_SRV : 0;
449 type_to_fetch = type_param&
PHP_DNS_NAPTR ? DNS_TYPE_NAPTR : 0;
452 type_to_fetch = type_param&
PHP_DNS_A6 ? DNS_TYPE_A6 : 0;
459 type_to_fetch = DNS_TYPE_ANY;
467 if (
status == DNS_INFO_NO_RECORDS ||
status == DNS_ERROR_RCODE_NAME_ERROR) {
479 if (
pRec->Flags.S.Section == DnsSectionAnswer) {
480 php_parserr(
pRec, type_to_fetch, store_results, raw, &
retval);
486 if (authns &&
pRec->Flags.S.Section == DnsSectionAuthority) {
488 php_parserr(
pRec, type_to_fetch, 1, raw, &
retval);
490 add_next_index_zval(authns, &
retval);
495#ifndef DnsSectionAdditional
496# ifdef DnsSectionAddtional
497# define DnsSectionAdditional DnsSectionAddtional
499# define DnsSectionAdditional 3
503 php_parserr(
pRec, type_to_fetch, 1, raw, &
retval);
505 add_next_index_zval(addtl, &
retval);
dns_get_mx(string $hostname, &$hosts, &$weights=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
dns_check_record(string $hostname, string $type="MX")
dns_get_record(string $hostname, int $type=DNS_ANY, &$authoritative_name_servers=null, &$additional_records=null, bool $raw=false)
cleanup DnsFreeRecordListDeep
#define PHP_DNS_NUM_TYPES
#define DnsSectionAdditional
zend_ffi_ctype_name_buf buf
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str))
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API zend_result add_next_index_string(zval *arg, const char *str)
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
struct _zend_string zend_string
#define zend_string_equals_literal_ci(str, c)