You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1KB

  1. #if defined(OS_WINDOWS)
  2. #include <Winsock2.h>
  3. #include <WS2tcpip.h>
  4. #include <ws2ipdef.h>
  5. #else
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <netinet/tcp.h>
  9. #include <arpa/inet.h>
  10. #include <netdb.h>
  11. #include <errno.h>
  12. #include <unistd.h>
  13. #endif
  14. #include <assert.h>
  15. #include <stdio.h>
  16. /// @return 1-multicast address, 0-don't multicast address
  17. int rtsp_addr_is_multicast(const char* ip)
  18. {
  19. int r;
  20. struct addrinfo *ai;
  21. r = getaddrinfo(ip, 0, NULL, &ai);
  22. if (0 != r)
  23. return 0;
  24. if (AF_INET == ai->ai_addr->sa_family)
  25. {
  26. const struct sockaddr_in* in = (const struct sockaddr_in*)ai->ai_addr;
  27. assert(sizeof(struct sockaddr_in) == ai->ai_addrlen);
  28. r = (ntohl(in->sin_addr.s_addr) & 0xf0000000) == 0xe0000000 ? 1 : 0;
  29. }
  30. else if (AF_INET6 == ai->ai_addr->sa_family)
  31. {
  32. const struct sockaddr_in6* in6 = (const struct sockaddr_in6*)ai->ai_addr;
  33. assert(sizeof(struct sockaddr_in6) == ai->ai_addrlen);
  34. r = in6->sin6_addr.s6_addr[0] == 0xff ? 1 : 0;
  35. }
  36. else
  37. {
  38. assert(0);
  39. r = 0;
  40. }
  41. freeaddrinfo(ai);
  42. return r;
  43. }