@@ -353,10 +353,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
353
353
/* {{{ Check DNS records corresponding to a given Internet host name or IP address */
354
354
PHP_FUNCTION (dns_check_record )
355
355
{
356
- #ifndef MAXPACKET
357
- #define MAXPACKET 8192 /* max packet size used internally by BIND */
358
- #endif
359
- u_char ans [MAXPACKET ];
356
+ HEADER * hp ;
357
+ querybuf answer ;
360
358
char * hostname , * rectype = NULL ;
361
359
size_t hostname_len , rectype_len = 0 ;
362
360
int type = DNS_T_MX , i ;
@@ -414,14 +412,14 @@ PHP_FUNCTION(dns_check_record)
414
412
res_init ();
415
413
#endif
416
414
417
- RETVAL_TRUE ;
418
- i = php_dns_search (handle , hostname , C_IN , type , ans , sizeof ( ans ) );
415
+ i = php_dns_search ( handle , hostname , C_IN , type , answer . qb2 , sizeof answer ) ;
416
+ php_dns_free_handle (handle );
419
417
420
418
if (i < 0 ) {
421
- RETVAL_FALSE ;
419
+ RETURN_FALSE ;
422
420
}
423
-
424
- php_dns_free_handle ( handle );
421
+ hp = ( HEADER * ) & answer ;
422
+ RETURN_BOOL ( ntohs ( hp -> ancount ) != 0 );
425
423
}
426
424
/* }}} */
427
425
@@ -1039,7 +1037,7 @@ PHP_FUNCTION(dns_get_mx)
1039
1037
zval * mx_list , * weight_list = NULL ;
1040
1038
int count , qdc ;
1041
1039
u_short type , weight ;
1042
- u_char ans [ MAXPACKET ] ;
1040
+ querybuf answer ;
1043
1041
char buf [MAXHOSTNAMELEN ];
1044
1042
HEADER * hp ;
1045
1043
u_char * cp , * end ;
@@ -1086,16 +1084,14 @@ PHP_FUNCTION(dns_get_mx)
1086
1084
res_init ();
1087
1085
#endif
1088
1086
1089
- i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , ( u_char * ) & ans , sizeof ( ans ) );
1087
+ i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , answer . qb2 , sizeof answer );
1090
1088
if (i < 0 ) {
1089
+ php_dns_free_handle (handle );
1091
1090
RETURN_FALSE ;
1092
1091
}
1093
- if (i > (int )sizeof (ans )) {
1094
- i = sizeof (ans );
1095
- }
1096
- hp = (HEADER * )& ans ;
1097
- cp = (u_char * )& ans + HFIXEDSZ ;
1098
- end = (u_char * )& ans + i ;
1092
+ hp = (HEADER * )& answer ;
1093
+ cp = answer .qb2 + HFIXEDSZ ;
1094
+ end = answer .qb2 + i ;
1099
1095
for (qdc = ntohs ((unsigned short )hp -> qdcount ); qdc -- ; cp += i + QFIXEDSZ ) {
1100
1096
if ((i = dn_skipname (cp , end )) < 0 ) {
1101
1097
php_dns_free_handle (handle );
@@ -1117,7 +1113,7 @@ PHP_FUNCTION(dns_get_mx)
1117
1113
continue ;
1118
1114
}
1119
1115
GETSHORT (weight , cp );
1120
- if ((i = dn_expand (ans , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1116
+ if ((i = dn_expand (answer . qb2 , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1121
1117
php_dns_free_handle (handle );
1122
1118
RETURN_FALSE ;
1123
1119
}
0 commit comments