Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/sockopt.c b/lib/sockopt.c
- index be22827..97592bb 100644
- --- lib/sockopt.c
- +++ lib/sockopt.c
- @@ -339,6 +339,45 @@ setsockopt_ipv4_multicast_if(int sock,
- m.s_addr = htonl(ifindex);
- return setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (void *)&m, sizeof(m));
- +#elif defined(SUNOS_5)
- + struct lifnum lifn;
- + struct lifconf lifc;
- + struct lifreq *lifr;
- +
- + lifn.lifn_family = AF_INET;
- + lifn.lifn_flags = 0;
- + if (ioctl(sock,SIOCGLIFNUM,&lifn) == -1) {
- + return -1;
- + }
- + lifc.lifc_family = AF_INET;
- + lifc.lifc_len = lifn.lifn_count * sizeof(struct lifreq);
- + lifc.lifc_buf = malloc(lifc.lifc_len);
- +
- + if (lifc.lifc_buf == NULL) {
- + return -1; // failed to allocate memory: return different res?
- + }
- + /* the following ioctl should fail if the system has grown additonal
- + interfaces since we called ioctl(SIOCGLIFNUM) */
- + int res;
- + if ((res = ioctl(sock,SIOCGLIFCONF,&lifc)) >= 0) {
- + lifr = lifc.lifc_req;
- + res = -1;
- + int n;
- + struct in_addr a;
- + /* using lifc.lifc_len, just in case some interfaces disappeared
- + since ioctl(SIOCGLIFNUM) */
- + for (n = lifc.lifc_len / sizeof(struct lifreq); n > 0; n--) {
- + a=((struct sockaddr_in *)&lifr->lifr_addr)->sin_addr;
- + ioctl(sock,SIOCGLIFINDEX,lifr);
- + if (lifr->lifr_index == ifindex) {
- + res = ioctl(sock,IPPROTO_IP,IP_MULTICAST_IF,&a,sizeof(a));
- + break;
- + }
- + lifr++;
- + }
- + }
- + free(lifc.lifc_buf);
- + return res;
- #else
- #error "Unsupported multicast API"
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement