在我的portscanner程序中,我希望成功写入端口号的输出,扫描和服务名称。 所以对于每个端口号,被扫描的和服务名称,我调用下面的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);
}
代码编译成功,但是当我扫描多个端口时,它会给出一个“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>
答案 0 :(得分:4)
您正在生成无效的XML。在同一个标记上不能有两个具有相同名称的属性。
请参阅Start-Tags, End-Tags, and Empty-Element Tags:
中的规范格式良好约束:独特的Att Spec
属性名称不得在同一个start-tag或empty-element标记中出现多次。