当前位置:   article > 正文

C实现SSDP协议的设备发现及设备搜索_ssdp c实现

ssdp c实现
  1. /*
  2. * ===========================================================================
  3. *
  4. * Filename: ssdpServer.c
  5. * Description: 设备发现服务(自实现ssdp协议,获取USERNAME进行绑定)
  6. * Version: 1.0
  7. * Created: 08/29/2017 07:20:10 PM
  8. * Revision: none
  9. * Compiler: gcc
  10. * Author: (syc),
  11. * Company: xxxx
  12. *
  13. * ===========================================================================
  14. */
  15. #include <sys/types.h>
  16. #include <sys/select.h>
  17. #include <sys/time.h>
  18. #include <sys/socket.h>
  19. #include <netinet/in.h>
  20. #include <arpa/inet.h>
  21. #include <net/if.h>
  22. #include <unistd.h>
  23. #include <pthread.h>
  24. #include <fcntl.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include "utils/queue.h"
  29. #include "utils/log.h"
  30. #include "Discovery/ssdpServer.h"
  31. #define SSDP_MCAST_ADDR ("239.255.255.250")
  32. #define SSDP_PORT (1900)
  33. #define M1_PORT (8200)
  34. #define OS_VERSION "3.4.72-rt89"
  35. #define SERVER_NAME "MiniDLNA"
  36. #define MINIDLNA_VERSION "1.1.0"
  37. #define MINIDLNA_SERVER_STRING OS_VERSION " DLNADOC/1.50 UPnP/1.0 " SERVER_NAME "/" MINIDLNA_VERSION
  38. #define ROOTDESC_PATH "/rootDesc.xml"
  39. #define MAC_ADDR_LEN (16)
  40. #define IP_ADDR_LEN (16)
  41. #define MAXSIZE (1024)
  42. queue_t *handle_queue = NULL;
  43. pthread_t handle_ThreadID;
  44. pthread_t handle_ThreadID1;
  45. typedef struct _packet_{
  46. char data[MAXSIZE];
  47. int len;
  48. int type;
  49. }msg_packet_t;
  50. eq_discovery_cb_t callback = {0};
  51. //全局变量
  52. struct sockaddr_in addrin ;
  53. struct timeval rtime ;
  54. int ssdp_sock ;
  55. int peer_listen ;
  56. int peer_sock ;
  57. socklen_t addrlen ;
  58. fd_set fds ;
  59. int maxfdp ;
  60. char buf[1024] ;
  61. //这两个参数根据业务需要而定
  62. char UUID[32] = {0};//D的唯一标识(MAC地址)
  63. char M1_IP[32] = {0}; //D的eth0.2的IP地址
  64. static const char * const known_service_types[] =
  65. {
  66. "uuid:00000000-0000-0000-0000-000000000000",
  67. "upnp:rootdevice",
  68. "urn:schemas-upnp-org:device:MediaServer:",
  69. "urn:schemas-upnp-org:service:ContentDirectory:",
  70. "urn:schemas-upnp-org:service:ConnectionManager:",
  71. "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:",
  72. 0
  73. };
  74. //获取IP地址
  75. int get_lan_ip(unsigned char *ipaddr)
  76. {
  77. struct sockaddr_in *addr;
  78. struct ifreq ifr;
  79. int sockfd;
  80. //char *name = "br-lan";
  81. char *name = "eth0.2";//eth0.2的IP地址
  82. if( strlen(name) >= IFNAMSIZ)
  83. return -1;
  84. strcpy( ifr.ifr_name, name);
  85. sockfd = socket(AF_INET,SOCK_DGRAM,0);
  86. //get ipaddr
  87. if(ioctl(sockfd, SIOCGIFADD
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/475119
推荐阅读
相关标签
  

闽ICP备14008679号