@@ -349,10 +349,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
349
349
Check DNS records corresponding to a given Internet host name or IP address */
350
350
PHP_FUNCTION (dns_check_record )
351
351
{
352
- #ifndef MAXPACKET
353
- #define MAXPACKET 8192 /* max packet size used internally by BIND */
354
- #endif
355
- u_char ans [MAXPACKET ];
352
+ HEADER * hp ;
353
+ querybuf answer ;
356
354
char * hostname , * rectype = NULL ;
357
355
size_t hostname_len , rectype_len = 0 ;
358
356
int type = T_MX , i ;
@@ -410,14 +408,14 @@ PHP_FUNCTION(dns_check_record)
410
408
res_init ();
411
409
#endif
412
410
413
- RETVAL_TRUE ;
414
- i = php_dns_search (handle , hostname , C_IN , type , ans , sizeof ( ans ) );
411
+ i = php_dns_search ( handle , hostname , C_IN , type , answer . qb2 , sizeof answer ) ;
412
+ php_dns_free_handle (handle );
415
413
416
414
if (i < 0 ) {
417
- RETVAL_FALSE ;
415
+ RETURN_FALSE ;
418
416
}
419
-
420
- php_dns_free_handle ( handle );
417
+ hp = ( HEADER * ) & answer ;
418
+ RETURN_BOOL ( ntohs ( hp -> ancount ) != 0 );
421
419
}
422
420
/* }}} */
423
421
@@ -1033,7 +1031,7 @@ PHP_FUNCTION(dns_get_mx)
1033
1031
zval * mx_list , * weight_list = NULL ;
1034
1032
int count , qdc ;
1035
1033
u_short type , weight ;
1036
- u_char ans [ MAXPACKET ] ;
1034
+ querybuf answer ;
1037
1035
char buf [MAXHOSTNAMELEN ];
1038
1036
HEADER * hp ;
1039
1037
u_char * cp , * end ;
@@ -1076,16 +1074,14 @@ PHP_FUNCTION(dns_get_mx)
1076
1074
res_init ();
1077
1075
#endif
1078
1076
1079
- i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , ( u_char * ) & ans , sizeof ( ans ) );
1077
+ i = php_dns_search (handle , hostname , C_IN , DNS_T_MX , answer . qb2 , sizeof answer );
1080
1078
if (i < 0 ) {
1079
+ php_dns_free_handle (handle );
1081
1080
RETURN_FALSE ;
1082
1081
}
1083
- if (i > (int )sizeof (ans )) {
1084
- i = sizeof (ans );
1085
- }
1086
- hp = (HEADER * )& ans ;
1087
- cp = (u_char * )& ans + HFIXEDSZ ;
1088
- end = (u_char * )& ans + i ;
1082
+ hp = (HEADER * )& answer ;
1083
+ cp = answer .qb2 + HFIXEDSZ ;
1084
+ end = answer .qb2 + i ;
1089
1085
for (qdc = ntohs ((unsigned short )hp -> qdcount ); qdc -- ; cp += i + QFIXEDSZ ) {
1090
1086
if ((i = dn_skipname (cp , end )) < 0 ) {
1091
1087
php_dns_free_handle (handle );
@@ -1107,7 +1103,7 @@ PHP_FUNCTION(dns_get_mx)
1107
1103
continue ;
1108
1104
}
1109
1105
GETSHORT (weight , cp );
1110
- if ((i = dn_expand (ans , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1106
+ if ((i = dn_expand (answer . qb2 , end , cp , buf , sizeof (buf )- 1 )) < 0 ) {
1111
1107
php_dns_free_handle (handle );
1112
1108
RETURN_FALSE ;
1113
1109
}
0 commit comments