Advertisement
Guest User

Untitled

a guest
Mar 19th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. diff --git a/lib/sockopt.c b/lib/sockopt.c
  2. index be22827..97592bb 100644
  3. --- lib/sockopt.c
  4. +++ lib/sockopt.c
  5. @@ -339,6 +339,45 @@ setsockopt_ipv4_multicast_if(int sock,
  6. m.s_addr = htonl(ifindex);
  7.  
  8. return setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (void *)&m, sizeof(m));
  9. +#elif defined(SUNOS_5)
  10. + struct lifnum lifn;
  11. + struct lifconf lifc;
  12. + struct lifreq *lifr;
  13. +
  14. + lifn.lifn_family = AF_INET;
  15. + lifn.lifn_flags = 0;
  16. + if (ioctl(sock,SIOCGLIFNUM,&lifn) == -1) {
  17. + return -1;
  18. + }
  19. + lifc.lifc_family = AF_INET;
  20. + lifc.lifc_len = lifn.lifn_count * sizeof(struct lifreq);
  21. + lifc.lifc_buf = malloc(lifc.lifc_len);
  22. +
  23. + if (lifc.lifc_buf == NULL) {
  24. + return -1; // failed to allocate memory: return different res?
  25. + }
  26. + /* the following ioctl should fail if the system has grown additonal
  27. + interfaces since we called ioctl(SIOCGLIFNUM) */
  28. + int res;
  29. + if ((res = ioctl(sock,SIOCGLIFCONF,&lifc)) >= 0) {
  30. + lifr = lifc.lifc_req;
  31. + res = -1;
  32. + int n;
  33. + struct in_addr a;
  34. + /* using lifc.lifc_len, just in case some interfaces disappeared
  35. + since ioctl(SIOCGLIFNUM) */
  36. + for (n = lifc.lifc_len / sizeof(struct lifreq); n > 0; n--) {
  37. + a=((struct sockaddr_in *)&lifr->lifr_addr)->sin_addr;
  38. + ioctl(sock,SIOCGLIFINDEX,lifr);
  39. + if (lifr->lifr_index == ifindex) {
  40. + res = ioctl(sock,IPPROTO_IP,IP_MULTICAST_IF,&a,sizeof(a));
  41. + break;
  42. + }
  43. + lifr++;
  44. + }
  45. + }
  46. + free(lifc.lifc_buf);
  47. + return res;
  48. #else
  49. #error "Unsupported multicast API"
  50. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement