标签:multi errno.h err cas ast tin efault port socket
#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); } } }
标签:multi errno.h err cas ast tin efault port socket
原文地址:https://www.cnblogs.com/soldierback/p/10804855.html