首页 > 其他 > 详细

mcast_get_ttl函数

时间:2019-05-03 14:01:05      阅读:147      评论:0      收藏:0      [点我收藏+]
#include    <errno.h>
#include    <net/if.h>
#include    <sys/socket.h>
#include    <netinet/in.h>

int sockfd_to_family(int);

int mcast_get_ttl(int sockfd)
{
    switch (sockfd_to_family(sockfd)) {
        case AF_INET: {
            u_char        ttl;
            socklen_t    len;

            len = sizeof(ttl);
            if (getsockopt(sockfd, IPPROTO_IP, 
                IP_MULTICAST_TTL, &ttl, &len) < 0) {
                return(-1);
            }
            return (ttl);
        }

#ifdef    IPV6
        case AF_INET6: {
            int            hop;
            socklen_t    len;

            len = sizeof(hop);
            if (getsockopt(sockfd, IPPROTO_IPV6, 
                IPV6_MULTICAST_HOPS, &hop, &len) < 0) {
                return(-1);
            }
            return (hop);
        }
#endif
        default: {
            errno = EAFNOSUPPORT;
            return(-1);
        }
    }
}

 

mcast_get_ttl函数

原文:https://www.cnblogs.com/soldierback/p/10804855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!