From owner-freebsd-net@FreeBSD.ORG Thu Mar 18 04:48:43 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CABB116A4CE for ; Thu, 18 Mar 2004 04:48:43 -0800 (PST) Received: from smtp.netli.com (ip2-pal-focal.netli.com [66.243.52.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB59343D1D for ; Thu, 18 Mar 2004 04:48:43 -0800 (PST) (envelope-from vlm@netli.com) Received: (qmail 23851 invoked by uid 84); 18 Mar 2004 12:48:16 -0000 Received: from vlm@netli.com by l3-1 with qmail-scanner-0.96 (uvscan: v4.1.40/v4121. . Clean. Processed in 0.17947 secs); 18 Mar 2004 12:48:16 -0000 Received: from unknown (HELO netli.com) (172.17.1.12) by mx01-pal-lan.netli.lan with SMTP; 18 Mar 2004 12:48:16 -0000 Message-ID: <40599ACA.1040506@netli.com> Date: Thu, 18 Mar 2004 04:49:14 -0800 From: Lev Walkin Organization: Netli, Inc. User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6) Gecko/20040307 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: Fuhua Yin References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-net@freebsd.org cc: yin@helios.iihe.ac.be Subject: Re: Multicast IPv6, socket, X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2004 12:48:43 -0000 never check the error codes. it is a bad practice to check for error codes from system calls and library functions. please remove all checks for the error conditions from your code and try again. these checks slow down the execution and mask real problems. P.S. man assert, and use it everywhere if you're lazy to implement an adequate error checking. Fuhua Yin wrote: > Dear , > > I am trying to work on IPv6 multicast. I just wrote a small programme to > test but get stuck somewhere. I wonder if someone could be of help. > > > Many thanks in advance!! > fuhua > > This is a client to send data from keyboard to group ff3e::2222/1234. > ------- > #include > #include > #include > #include > #include > int main(int argc, char **argv){ > > int mysock; > struct sockaddr_in6 servaddr6, cliaddr6; > struct ipv6_mreq mreq6; > > int loop=0; > int hops=127; > int ifindex; > > int servlen; > int n; > char sendline[1024], recvline[1025]; > > mysock=socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); > ifindex=if_nametoindex("eth0"); > > bzero(&servaddr6, sizeof(servaddr6)); > servaddr6.sin6_family=AF_INET6; > servaddr6.sin6_port=htons(1234); > inet_pton(AF_INET6, "ff3e::2222", &servaddr6.sin6_addr); > > if(!IN6_IS_ADDR_MULTICAST(&servaddr6.sin6_addr)){ > int main(int argc, char **argv){ > > int mysock; > struct sockaddr_in6 servaddr6, cliaddr6; > struct ipv6_mreq mreq6; > > int loop=0; > int hops=127; > int ifindex; > > int servlen; > int servlen; > int n; > char sendline[1024], recvline[1025]; > > mysock=socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); > ifindex=if_nametoindex("eth0"); > > bzero(&servaddr6, sizeof(servaddr6)); > servaddr6.sin6_family=AF_INET6; > servaddr6.sin6_port=htons(1234); > inet_pton(AF_INET6, "ff3e::2222", &servaddr6.sin6_addr); > > if(!IN6_IS_ADDR_MULTICAST(&servaddr6.sin6_addr)){ > > printf(" is not multicast ip6 address \n"); > exit(1); > } > > > bzero(&cliaddr6, sizeof(cliaddr6)); > cliaddr6.sin6_family=AF_INET6; > cliaddr6.sin6_port=htons(0); > inet_pton(AF_INET6, "2001:6a8:1080:102:203:47ff:fe69:ab93", > &cliaddr6.sin6_addr); > > bind(mysock, (struct sockaddr*)& cliaddr6,sizeof(cliaddr6)); > > setsockopt(mysock, IPPROTO_IPV6, IPV6_MULTICAST_IF, > &ifindex,sizeof(ifindex)); > setsockopt(mysock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, > sizeof(loop)); > setsockopt(mysock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, > sizeof(hops)); > > while (fgets(sendline, 1024,stdin)!=NULL){ > > sendto(mysock, sendline, strlen(sendline),0, (struct > sockaddr*)&servaddr6,sizeof(servaddr6)); > printf("fuhua check\n"); > fputs(sendline,stdout); > > } > return 0; > > } > ----------------------- > > This is the server to receive the message and print on screen. > > -- > #include > #include > #include > #include > #include > #include > #include > #include > #include > int main(int argc, char **argv){ > > int mysock; > struct sockaddr_in6 myaddr, cliaddr; > char msgbuf[1024]; > int clilen; > int msglen; > mysock=socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); > memset(&myaddr,0, sizeof(myaddr)); > myaddr.sin6_family=AF_INET6; > myaddr.sin6_port=htons(1234); > inet_pton(AF_INET6,"2001:6a8:1080:102::d",&myaddr.sin6_addr); > > printf("ssss \n"); > mysock=socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); > bind(mysock, (struct sockaddr*) &myaddr, sizeof(myaddr)); > for ( ; ; ) > { > > printf("fuhua yin----ssss \n"); > clilen=sizeof(cliaddr); > msglen=recvfrom(mysock, msgbuf, 1024, 0, (struct > sockaddr*)&cliaddr, &clilen); > > printf("how many bytes I receive from client %d",msglen); > sendto(mysock, msgbuf,msglen, 0, (struct sockaddr*)&cliaddr, > clilen); > > } > > return 0; > > _________________________________________________________________ > > > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" -- Lev Walkin vlm@netli.com