⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multicast.c

📁 unix网络编程卷1:套接口API的全书源码
💻 C
字号:
/* * Copyright (c) 1993 W. Richard Stevens.  All rights reserved. * Permission to use or modify this software and its documentation only for * educational purposes and without fee is hereby granted, provided that * the above copyright notice appear in all copies.  The author makes no * representations about the suitability of this software for any purpose. * It is provided "as is" without express or implied warranty. */#include	"sock.h"voidjoin_mcast(int fd, struct sockaddr_in *sin){#ifdef	IP_ADD_MEMBERSHIP	/* only include if host supports mcasting */	u_long			inaddr;	struct ip_mreq	mreq;	inaddr = sin->sin_addr.s_addr;	if (IN_MULTICAST(inaddr) == 0)		return;			/* not a multicast address */	mreq.imr_multiaddr.s_addr = inaddr;	mreq.imr_interface.s_addr = htonl(INADDR_ANY);	/* need way to change */	if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,												sizeof(mreq)) == -1 )		err_sys("IP_ADD_MEMBERSHIP error");	if (verbose)			fprintf(stderr, "multicast group joined\n");#endif	/* IP_ADD_MEMBERSHIP */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -