@@ -362,10 +362,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
362
362
Check DNS records corresponding to a given Internet host name or IP address */
363
363
PHP_FUNCTION (dns_check_record )
364
364
{
365
- #ifndef MAXPACKET
366
- #define MAXPACKET 8192 /* max packet size used internally by BIND */
367
- #endif
368
- u_char ans [MAXPACKET ];
365
+ HEADER * hp ;
366
+ querybuf answer ;
369
367
char * hostname , * rectype = NULL ;
370
368
size_t hostname_len , rectype_len = 0 ;
371
369
int type = DNS_T_MX , i ;
@@ -423,14 +421,14 @@ PHP_FUNCTION(dns_check_record)
423
421
res_init ();
424
422
#endif
425
423
426
- RETVAL_TRUE ;
427
- i = php_dns_search (handle , hostname , C_IN , type , ans , sizeof ( ans ) );
424
+ i = php_dns_search ( handle , hostname , C_IN , type , answer . qb2 , sizeof answer ) ;
425
+ php_dns_free_handle (handle );
428
426
429
427
if (i < 0 ) {
430
- RETVAL_FALSE ;
428
+ RETURN_FALSE ;
431
429
}
432
-
433
- php_dns_free_handle ( handle );
430
+ hp = ( HEADER * ) & answer ;
431
+ RETURN_BOOL ( ntohs ( hp -> ancount ) != 0 );
434
432
}
435
433
/* }}} */
436
434
@@ -1050,7 +1048,7 @@ PHP_FUNCTION(dns_get_mx)
1050
1048
zval * mx_list , * weight_list = NULL ;
1051
1049
int count , qdc ;
1052
1050
u_short type , weight ;
1053
- u_char ans [ MAXPACKET ] ;
1051
+ querybuf answer ;
1054
1052
char buf [MAXHOSTNAMELEN ];
1055
1053
HEADER * hp ;
1056
1054
u_char * cp , * end ;
@@ -1097,16 +1095,14 @@ PHP_FUNCTION(dns_get_mx)
1097
1095
res_init ();
1098
1096
#endif
1099
1097
1100
- i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , ( u_char * ) & ans , sizeof ( ans ) );
1098
+ i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , answer . qb2 , sizeof answer );
1101
1099
if (i < 0 ) {
1100
+ php_dns_free_handle (handle );
1102
1101
RETURN_FALSE ;
1103
1102
}
1104
- if (i > (int )sizeof (ans )) {
1105
- i = sizeof (ans );
1106
- }
1107
- hp = (HEADER * )& ans ;
1108
- cp = (u_char * )& ans + HFIXEDSZ ;
1109
- end = (u_char * )& ans + i ;
1103
+ hp = (HEADER * )& answer ;
1104
+ cp = answer .qb2 + HFIXEDSZ ;
1105
+ end = answer .qb2 + i ;
1110
1106
for (qdc = ntohs ((unsigned short )hp -> qdcount ); qdc -- ; cp += i + QFIXEDSZ ) {
1111
1107
if ((i = dn_skipname (cp , end )) < 0 ) {
1112
1108
php_dns_free_handle (handle );
@@ -1128,7 +1124,7 @@ PHP_FUNCTION(dns_get_mx)
1128
1124
continue ;
1129
1125
}
1130
1126
GETSHORT (weight , cp );
1131
- if ((i = dn_expand (ans , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1127
+ if ((i = dn_expand (answer . qb2 , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1132
1128
php_dns_free_handle (handle );
1133
1129
RETURN_FALSE ;
1134
1130
}
0 commit comments