setsockopt problem with IP_MULTICAST_TTL on b19/NT4

Luigi Rizzo luigi@labinfo.iet.unipi.it
Sun Jan 31 23:52:00 GMT 1999


Hi,

in porting a multicast app from FreeBSD/Linux i have a problem
using setsockopt() to set the TTL of multicast packets. The code
is below, function openssock().  The setsockopt returns with a "Bad
address" error msg. If i omit the setsockpt call the socket works
fine, except that packets are generated with a TTL of 1 (seen from
another machine on the same net running tcpdump).

Any idea ? I even tried to move the setsockopt() call after the
connect() but no success. Perhaps i should bind the socket to a multicast
address before calling the setsockopt ? (i know it does not make
any sense but perhaps the underlying implementation makes some checks
on the socket addresses before allowing multicast options to be used ?)

	thanks
	luigi

-----------------------------------+-------------------------------------
  Luigi RIZZO                      .
  EMAIL: luigi@iet.unipi.it        . Dip. di Ing. dell'Informazione
  HTTP://www.iet.unipi.it/~luigi/  . Universita` di Pisa
  TEL/FAX: +39-050-568.533/522     . via Diotisalvi 2, 56126 PISA (Italy)
-----------------------------------+-------------------------------------

int     
openssock(u_int32_t addr, u_int16_t port, int ttl, int unbound)
{       
    int fd;
    struct sockaddr_in sin;
        

    fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (fd < 0)
        return -1;
    if (nonblock(fd) < 0)
        return -1;
        
    if (IN_CLASSD(ntohl(addr))) {
	u_char t;
	t = (ttl > 255) ? 255 : (ttl < 0) ? 0 : ttl;
	if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
		(char*)&t, sizeof(t)) < 0) {
	}
    }
    memset((char *)&sin, 0, sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_port = port;
    sin.sin_addr.s_addr = addr;
    if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        return -1;
    }
    
    return fd ;
}   


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list