gpt4 book ai didi

c 查询txt记录

转载 作者:行者123 更新时间:2023-11-30 17:59:12 25 4
gpt4 key购买 nike

各位,我已经编写了读取dns txt记录的程序,但是它有一些问题,谁能告诉我为什么?以下是我的源代码

char blockItem[512];
bzero(blockItem,512);
/*Temp Save the txt record value*/
int responseLength;
/*The Length of response*/
int i;
/*For Loop Controller*/
ns_msg query_parse_msg;
/*List of response message
* For txt record , It sould only one response!
* */
ns_rr query_parse_rr;
/*One response message*/
u_char responseByte[512];
/*Variable that for storage query answer.*/
bzero(responseByte,512);
/*Clear variable*/
if ((responseLength = res_query(host,C_IN,T_TXT,responseByte,512)) < 0)
{
/*Query DNS Server*/
return HOSTNOTFIND;
}
else
{
if (ns_initparse(responseByte,responseLength,&query_parse_msg) < 0)
{
/*Pass the answer to ns_msg(May be it mean cut the dns header)*/
printf("%s\n","Cannot Read response Message");
return NOTSUCCESSFUL;
}
else
{
for (i =0;i < ns_msg_count(query_parse_msg,ns_s_an);i++)
{
/*Count the toolly response*/
if (ns_parserr(&query_parse_msg,ns_s_an,i,&query_parse_rr))
{
/*Pass the msg list to rr.*/
printf("%s\n","Parse failed!");
return NOTSUCCESSFUL;
}
else
{
u_char const *rdata = (u_char*)(ns_rr_rdata(query_parse_rr) );
char *blockItem;
blockItem=(char*)rdata;
blockItem[strlen((char*)rdata)-2] = '\0';
/*Pass the ns_rr to char data type.*/
printf("Normal:%s\n",(u_char *)blockItem);
}
}
}

输出:Fv=spf1 redirect=_spf.google.com

但原始txt记录应该是v=spf1redirect=_spf.google.com

我的问题是u_char const *rdata = (u_char*)(ns_rr_rdata(query_parse_rr) )

如果我将其更改为u_char const *rdata = (u_char*)(ns_rr_rdata(query_parse_rr) +1)

输出将更改为:v=spf1 redirect=_spf.google.com

另外,我引用了如何查询MX记录,我发现有+2,有谁可以告诉我为什么吗?

最佳答案

TXT记录RDATA格式为

length, 1 byte
string, <length bytes>
length2, 1 byte
string2, <length2 bytes>
etc.

MX记录RDATA格式为

priority, 2 bytes
domain name, the rest of the message

(RFC 1035,第 3.3.14 和 3.3.9 段)

关于c 查询txt记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11645020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com