0
在我的portscanner程序中,我希望成功编写端口号的输出,扫描方式和服务名称。 因此对于每个端口号,被扫描的和服务名称,我调用下面的parseall例程。xml解析错误属性名称重新定义
void parseall(int pid, char *scannedby, char *service){ // routine to add port, scannedby and service to xmlfile
xmlDocPtr doc; // pointer to parse xml Document
xmlNodePtr cur = NULL;// node pointer. It interacts with individual node
xmlAttrPtr attr; char portid[10];
sprintf (portid,"%d",pid); // converted int to string
doc = xmlParseFile(xmlFileName); //parse filename
cur = xmlDocGetRootElement(doc); // get rootnode
addnewportinfotag(cur,doc); // this routine adds new portid, scannedby and servicename tags to the xmlfile created
cur = cur->xmlChildrenNode; //get pointer
parseport(doc, cur, portid); // routine to add port to xmlfile
while(cur!=NULL){
if ((!xmlStrcmp(cur->name, (const xmlChar *)"ports"))){
parsehost(doc, cur, scannedby); // routine to add scanned by to xmlfile
parseservice(doc, cur, service); //routine to add servicename to xmlfile
}
cur = cur->next;
}
xmlSaveFormatFile (xmlFileName, doc, 1);
return;
xmlFreeDoc(doc);
}
代码编译成功,但是当我扫描一个以上的端口,它提供了一个“XML解析错误属性重新定义名称 ”如下:
[ Port ] [ Scanned by] [ Status ] [Service]
79/tcp osus Open finger
80/tcp bt Open www
111/tcp osus Open sunrpc
xmloutput.xml:5: parser error : Attribute portid redefined
<ports protocol="tcp" portid="79" portid="80"><state state="open" reason="vanill
^
xmloutput.xml:5: parser error : Attribute scannedby redefined
e state="open" reason="vanilla-scan"/><scannedby scannedby="osus" scannedby="bt"
^
xmloutput.xml:5: parser error : Attribute name redefined
"/><scannedby scannedby="osus" scannedby="bt"/><service name="finger" name="www"
^
Segmentation fault
为它运作良好,单端口给出:
<ports protocol="tcp" portid="22"><state state="open" reason="vanilla-scan"/><scannedby scannedby="bt"/><service name="ftp"/></ports></DPScanner>
嗨马特,感谢您的快速响应。问题出在功能的某个位置,而不是创建新的标签并填充端口信息,它只是将下一个端口信息附加到下一个端口信息。请赞赏任何帮助 – Fahad
这是无效的。您不必在同一'ports'标签上使用'port =“...”'属性。您需要更改XML文件的结构,以便端口号是子元素,而不是属性。 – Mat