ONVIF实现的第一步当然是discovery,但是实现discovery分为被发现和主动发现。
实现被发现,我参考的博客是,很完整,根据这个就可以实现。
http://blog.csdn.net/ghostyu/article/details/8182516
实现主动发现,代码如下:
#include "soapH.h" #include "wsdd.nsmap" #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #define __DEBUG #ifdef __DEBUG #define DBG(fmt,args...) fprintf(stdout, fmt, ##args) #else #define DBG(fmt,args...) #endif #define ERR(fmt,args...) fprintf(stderr, fmt, ##args) #define set_block_fd(fd) fcntl(fd, F_SETFL, 0) #define set_nonblock_fd(fd) fcntl(fd, F_SETFL, NOBLOCK) //char *server_ip="49.123.73.192"; #define SMALL_INFO_LENGTH 20 #define IP_LENGTH 20 #define INFO_LENGTH 100 int main(int argc, char **argv) { struct soap *soap; struct wsdd__ProbeType req; struct __wsdd__ProbeMatches resp; struct wsdd__ScopesType sScope; struct SOAP_ENV__Header header; int count = 0; int result = 0; char guid_string[100]; soap = soap_new(); if(soap==NULL) { return -1; } soap_set_namespaces(soap, namespaces); //soap->recv_timeout = 5; //超过5秒钟没有数据就退出 soap_default_SOAP_ENV__Header(soap, &header); header.wsa__MessageID = guid_string; header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery"; header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe"; soap->header = &header; soap_default_wsdd__ScopesType(soap, &sScope); sScope.__item = ""; soap_default_wsdd__ProbeType(soap, &req); req.Scopes = &sScope; req.Types = ""; result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req); do{ result = soap_recv___wsdd__ProbeMatches(soap, &resp); if (soap->error) { printf("soap error!\n"); result = soap->error; break; } else { printf("=================================\n"); printf("%d\n",resp.wsdd__ProbeMatches->__sizeProbeMatch); printf("%d\n",resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion); printf("%s\n",resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item); printf("QName:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->Types); printf("xsd:string:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address); //printf("xsd:QName:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType); //printf("wsa:ServiceNameType:%s\n"resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName); //printf("sequence of elements:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size); printf("xsd:anyType:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute); //printf("endpoint any:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any); printf("wsdd:UriListType:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->XAddrs); printf("============================\n"); } }while(1); soap_destroy(soap); soap_end(soap); soap_done(soap); return result; }
通过这个代码发现了大华的摄像头,我把完整的工程也传上来了,供大家参考。