在我的 portscanner 程序中,我希望成功写入端口号、扫描方式和服务名称的输出。所以对于每个端口号、scannedby 和服务名称,我调用下面的 parseall 例程。
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);
}
Run Code Online (Sandbox Code Playgroud)
代码编译成功,但是当我扫描多个端口时,它给出了一个“重新定义的 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
Run Code Online (Sandbox Code Playgroud)
对于单个端口,它运行良好,提供:
<ports protocol="tcp" portid="22"><state state="open" reason="vanilla-scan"/><scannedby scannedby="bt"/><service name="ftp"/></ports></DPScanner>
Run Code Online (Sandbox Code Playgroud)
您正在生成无效的 XML。同一个标签上不能有两个同名的属性。
请参阅规范,在Start-Tags、End-Tags 和 Empty-Element Tags 中:
格式良好的约束:Unique Att Spec
属性名称不能在同一个开始标签或空元素标签中出现多次。