From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fee84,37ed75ba8ea46b5f,start X-Google-Attributes: gidfee84,public From: pacr99@my-deja.com Subject: Multicast problem using virtual addresses Date: 1999/06/02 Message-ID: <7j36nr$hus$1@nnrp1.deja.com>#1/1 X-Deja-AN: 484822288 X-Http-Proxy: 1.1 x26.deja.com:80 (Squid/1.1.22) for client 131.115.49.150 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Wed Jun 02 12:06:23 1999 GMT Newsgroups: comp.unix.osf.osf1 X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Hi all! Problems regarding virual IP addressing combined with multicasting on Digital UNIX 4.0D First if we only have one network card with one IP address ifconfig �a returns the real ipaddress (e.g zzz.zzz.zzz.zzz) Using the shell command ifconfig as root in the following way permits two IP addresses on one network card: ifconfig tu0 alias xxx.xxx.xxx.xxx netmask yyy.yyy.yyy.yyy up It is then possible to ping or rlogin to the IP addresses xxx.xxx.xxx.xxx and zzz.zzz.zzz.zzz from another host. We now have two IP addresses: xxx.xxx.xxx.xxx (virtual) and zzz.zzz.zzz.zzz on one network card. The problem shows up trying to receive multicast messages on the IP addresses. Short description of the program: First we open a new socket: *UDPFD=socket(AF_INET,SOCK_DGRAM,0) Then we set a socket option allowing both IP addresses to listen on the same port: setsockopt(*UDPFD,SOL_SOCKET,SO_REUSEPORT,(const void*) &on, sizeof(on)) where on = 1 Then we initiate a socket structure: memset(&addr,0,sizeof(addr)) addr.sin_family = AF_INET; addr.sin_port = htons(20000); addr.sin_addr.s_addr = htonl(INADDR_ANY); And associate this structure with our file descriptor: bind(*UDPFD,(struct sockaddr *)&addr,sizeof(addr)) We now define our multicast address: mcastaddr.s_addr=inet_addr(�239.255.0.0�) Finally, we try to add the IP addresses to the multicast group using: mreq.imr_multiaddr=mcastaddr; mreq.imr_interface.s_addr = ipnumber; (ipnumber is a s_addr where xxx.xxx.xxx.xxx has been stored) setsockopt(*UDPFD,IPPROTO_IP,IP_ADD_MEMBERSHIP,((const void *) &mreq, sizeof(mreq)) The same is done for the other IP address, zzz.zzz.zzz.zzz (changing the content of s_addr to zzz.zzz.zzz.zzz) The problem is that the last setsockopt returns �1, e.g does not succeed. However, if one ignores the error return and tries to receive multicasts anyway (stubborn) it seems to work anyway� (strange). The drawback is that if one starts many threads all using the virtual IP addresses as described in the program above it seems to run slower comparing to using two network cards each having one IP address (also the setsockopt succeeds without any error if one uses two network cards instead). We have the following questions: 1. Are we doing anything wrong (missed something)? 2. Is this an error on the part of setsockopt? /Regards Paul Cronholm Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.