Date: Thu, 18 Mar 2004 04:49:14 -0800 From: Lev Walkin <vlm@netli.com> To: Fuhua Yin <fuhuayin@hotmail.com> Cc: yin@helios.iihe.ac.be Subject: Re: Multicast IPv6, socket, Message-ID: <40599ACA.1040506@netli.com> In-Reply-To: <BAY16-F67kxJ5zHQE7m00017300@hotmail.com> References: <BAY16-F67kxJ5zHQE7m00017300@hotmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <netinet/in.h> > #include <unistd.h> > #include <stdio.h> > #include <string.h> > #include <stdlib.h> > 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 <sys/types.h> > #include <sys/socket.h> > #include <netdb.h> > #include <netinet/in.h> > #include <unistd.h> > #include <stdio.h> > #include <stdio.h> > #include <string.h> > #include <stdlib.h> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40599ACA.1040506>