gSOAP版本:2.8.17r
现象:
我运行我编译出来的服务端以后,我在测试工具上面点击discovery devices的时候一个也没有找到,我通过wireshark可以看到广播的包在onvif test tool 的windows系统里面有出现,地址和端口都没有问题。
但是,我在onvif测试工具的右边填写device IP,然后,probe的时候,scopes,type等等信息都可以显示也是我代码里面写的,左边也可以看到设备的信息了。
BTW:我没有双网卡,我可以确定网络环境没有问题,我可以抓包看到,我对onvif还不是很熟悉;
问题:
1.discovery devices这个按钮点击以后找到设备还需要那些步骤,我参考的教程在这里:http://blog.csdn.net/ghostyu/article/details/8182516
感谢告知!
代码直接通过wsdl2h和soapcpp2生成,然后添加了下面的服务端代码;
int bind_server_udp(int server_s, char *server_ip)
{
struct sockaddr_in server_sockaddr;
memset(&server_sockaddr, 0, sizeof server_sockaddr);
server_sockaddr.sin_family = AF_INET;
if (server_ip != NULL)
{
inet_aton(server_ip, &server_sockaddr.sin_addr);
}
else
{
server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
}
server_sockaddr.sin_port = htons(ONVIF_BIND_SERVER_UDP_PORT);
return bind(server_s, (struct sockaddr *) &server_sockaddr, sizeof (server_sockaddr));
}
static int create_server_socket_udp(void)
{
int server_udp;
unsigned char one = 1;
int sock_opt = 1;
server_udp = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (server_udp == -1)
{
printf("unable to create socket");
}
/* server socket is nonblocking */
if (set_nonblock_fd(server_udp) == -1)
{
printf("fcntl: unable to set server socket to nonblocking");
}
/* close server socket on exec so cgi's can't write to it */
if (fcntl(server_udp, F_SETFD, 1) == -1)
{
printf("can't set close-on-exec on server socket!");
}
/* reuse socket addr */
if ((setsockopt(server_udp, SOL_SOCKET, SO_REUSEADDR, (void *) &sock_opt, sizeof (sock_opt))) == -1)
{
printf("setsockopt");
}
if ((setsockopt(server_udp, IPPROTO_IP, IP_MULTICAST_LOOP, &one, sizeof (unsigned char))) == -1)
{
printf("setsockopt");
}
/* internet family-specific code encapsulated in bind_server() */
if (bind_server_udp(server_udp, NULL) == -1)
{
printf("unable to bind");
}
return server_udp;
}
int main()
{
int server_udp;
int retval;
struct soap *soap_udp;
int fault_flag = 0;
server_udp = create_server_socket_udp();
printf("server_udp = %d\n", server_udp);
while(1)
{
soap_udp=soap_new();
soap_init1(soap_udp, SOAP_IO_UDP);
soap_udp->master = server_udp;
soap_udp->socket = server_udp;
soap_udp->errmode = 0;
soap_udp->bind_flags = 1;
if (!soap_valid_socket(soap_bind(soap_udp, NULL, ONVIF_BIND_SERVER_UDP_PORT, 100)))
{
soap_print_fault(soap_udp, stderr);
}
printf("soap_serve start ...\n");
retval = soap_serve(soap_udp);
printf("retval result = %d\n", retval);
if(retval && !(fault_flag))
{
fault_flag = 1;
}
else if(!retval)
{
fault_flag = 0;
}
soap_destroy(soap_udp);
soap_end(soap_udp);
soap_done(soap_udp);
free(soap_udp);
}
return 0;
}
SOAP_FMAC5 int SOAP_FMAC6 soap_send___wsdd__ProbeMatches(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct wsdd__ProbeMatchesType *wsdd__ProbeMatches)
{
struct __wsdd__ProbeMatches soap_tmp___wsdd__ProbeMatches;
if (soap_action == NULL)
soap_action = "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/ProbeMatches";
soap_begin(soap);
soap->encodingStyle = NULL;
soap_tmp___wsdd__ProbeMatches.wsdd__ProbeMatches = wsdd__ProbeMatches;
soap_serializeheader(soap);
soap_serialize___wsdd__ProbeMatches(soap, &soap_tmp___wsdd__ProbeMatches);
if (soap_begin_count(soap))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___wsdd__ProbeMatches(soap, &soap_tmp___wsdd__ProbeMatches, "-wsdd:ProbeMatches", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap->error;
}
if (soap_end_count(soap))
return soap->error;
if (soap_connect(soap, soap_url(soap, soap_endpoint, NULL), soap_action)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___wsdd__ProbeMatches(soap, &soap_tmp___wsdd__ProbeMatches, "-wsdd:ProbeMatches", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap)
|| soap_end_send(soap))
return soap_closesock(soap);
return SOAP_OK;
}
int __wsdd__Probe(struct soap *soap, struct wsdd__ProbeType *wsdd__Probe)
{
char macaddr[6];
char _IPAddr[INFO_LENGTH];
char _HwId[1024];
printf("__wsdd__Probe\n");
wsdd__ProbeMatchesType ProbeMatches;
ProbeMatches.ProbeMatch = (struct wsdd__ProbeMatchType *)soap_malloc(soap, sizeof(struct wsdd__ProbeMatchType));
ProbeMatches.ProbeMatch->XAddrs = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);
ProbeMatches.ProbeMatch->Types = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);
ProbeMatches.ProbeMatch->Scopes = (struct wsdd__ScopesType*)soap_malloc(soap,sizeof(struct wsdd__ScopesType));
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties = (struct wsa__ReferencePropertiesType*)soap_malloc(soap,sizeof(struct wsa__ReferencePropertiesType));
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters = (struct wsa__ReferenceParametersType*)soap_malloc(soap,sizeof(struct wsa__ReferenceParametersType));
ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName = (struct wsa__ServiceNameType*)soap_malloc(soap,sizeof(struct wsa__ServiceNameType));
ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType = (char **)soap_malloc(soap, sizeof(char *) * SMALL_INFO_LENGTH);
ProbeMatches.ProbeMatch->wsa__EndpointReference.__any = (char **)soap_malloc(soap, sizeof(char*) * SMALL_INFO_LENGTH);
ProbeMatches.ProbeMatch->wsa__EndpointReference.__anyAttribute = (char *)soap_malloc(soap, sizeof(char) * SMALL_INFO_LENGTH);
ProbeMatches.ProbeMatch->wsa__EndpointReference.Address = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);
net_get_hwaddr(ETH_NAME, macaddr);
sprintf(_HwId,"uuid:1419d68a-1dd2-11b2-a105-%02X%02X%02X%02X%02X%02X",macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
sprintf(_IPAddr, "http://%s/onvif/device_service", ONVIF_LOCAL_IP_ADDR);
ProbeMatches.__sizeProbeMatch = 1;
ProbeMatches.ProbeMatch->Scopes->__item =(char *)soap_malloc(soap, 1024);
memset(ProbeMatches.ProbeMatch->Scopes->__item,0,sizeof(ProbeMatches.ProbeMatch->Scopes->__item));
//Scopes MUST BE
strcat(ProbeMatches.ProbeMatch->Scopes->__item, "onvif://www.onvif.org/type/NetworkVideoTransmitter");
ProbeMatches.ProbeMatch->Scopes->MatchBy = NULL;
strcpy(ProbeMatches.ProbeMatch->XAddrs, _IPAddr);
strcpy(ProbeMatches.ProbeMatch->Types, wsdd__Probe->Types);
printf("wsdd__Probe->Types=%s\n",wsdd__Probe->Types);
ProbeMatches.ProbeMatch->MetadataVersion = 1;
//ws-discovery
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties->__size = 0;
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties->__any = NULL;
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters->__size = 0;
ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters->__any = NULL;
ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType[0] = (char *)soap_malloc(soap, sizeof(char) * SMALL_INFO_LENGTH);
//ws-discovery
strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType[0], "ttl");
ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->__item = NULL;
ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->PortName = NULL;
ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->__anyAttribute = NULL;
ProbeMatches.ProbeMatch->wsa__EndpointReference.__any[0] = (char *)soap_malloc(soap, sizeof(char) * SMALL_INFO_LENGTH);
strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.__any[0], "Any");
strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.__anyAttribute, "Attribute");
ProbeMatches.ProbeMatch->wsa__EndpointReference.__size = 0;
strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.Address, _HwId);
soap->header->wsa__To = "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous";
soap->header->wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches";
soap->header->wsa__RelatesTo = (struct wsa__Relationship*)soap_malloc(soap, sizeof(struct wsa__Relationship));
//it's here
soap->header->wsa__RelatesTo->__item = soap->header->wsa__MessageID;
soap->header->wsa__RelatesTo->RelationshipType = NULL;
soap->header->wsa__RelatesTo->__anyAttribute = NULL;
soap->header->wsa__MessageID =(char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);
strcpy(soap->header->wsa__MessageID,_HwId+4);
/* send over current socket as HTTP OK response: */
soap_send___wsdd__ProbeMatches(soap, "http://", NULL, &ProbeMatches);
return SOAP_OK;
}
10 个解决方案
#1
我顶你一下。。。。不懂
#2
谢谢!
#3
Probe应该是设备端程序启动后主动发送。我也看了那个程序,__wsdd__Proble没被调用。求交流, 569493867
#4
求一个测试工具的新版安装包
onvif device test tool version 13.12
onvif device test tool version 13.12
#5
加QQ群:7622995,一起交流.已经很多人都做这个在这个群里面.
#6
我上传了你要的版本,要一分,意思一下,我也是忽然发现我自己没有分了.
http://download.csdn.net/detail/kenchowcn/6990403
#7
很久以前搞过onvif,我记得那时的问题是使用的soap命名空间版本不对造成的。其实就是nsmap文件里面的地址。
现在不太记得,要找找代码才行。
现在不太记得,要找找代码才行。
#8
多谢!
#9
这个问题是由于socket的属性设置在bind之前做了,我把广播属性设置相关的动作放到bind之后就好了。
#10
你好,你的问题我也遇到了,可以加你qq和你交流一下吗
#1
我顶你一下。。。。不懂
#2
我顶你一下。。。。不懂
谢谢!
#3
Probe应该是设备端程序启动后主动发送。我也看了那个程序,__wsdd__Proble没被调用。求交流, 569493867
#4
求一个测试工具的新版安装包
onvif device test tool version 13.12
onvif device test tool version 13.12
#5
Probe应该是设备端程序启动后主动发送。我也看了那个程序,__wsdd__Proble没被调用。求交流, 569493867
加QQ群:7622995,一起交流.已经很多人都做这个在这个群里面.
#6
求一个测试工具的新版安装包
onvif device test tool version 13.12
我上传了你要的版本,要一分,意思一下,我也是忽然发现我自己没有分了.
http://download.csdn.net/detail/kenchowcn/6990403
#7
很久以前搞过onvif,我记得那时的问题是使用的soap命名空间版本不对造成的。其实就是nsmap文件里面的地址。
现在不太记得,要找找代码才行。
现在不太记得,要找找代码才行。
#8
求一个测试工具的新版安装包
onvif device test tool version 13.12
我上传了你要的版本,要一分,意思一下,我也是忽然发现我自己没有分了.
http://download.csdn.net/detail/kenchowcn/6990403
多谢!
#9
这个问题是由于socket的属性设置在bind之前做了,我把广播属性设置相关的动作放到bind之后就好了。
#10
你好,你的问题我也遇到了,可以加你qq和你交流一下吗