From 70ec417f72c6e451f11a3d553ba4db0714d0cb60 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:04:52 +0000 Subject: Utilisateur : Fcolin Date : 29/06/00 Heure : 15:59 Archivé dans $/Ivy Commentaire: Version multicast (vss 3) --- Bus/Ivy/ThreadedSocket.cxx | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'Bus') diff --git a/Bus/Ivy/ThreadedSocket.cxx b/Bus/Ivy/ThreadedSocket.cxx index 64df41e..1e20e8e 100644 --- a/Bus/Ivy/ThreadedSocket.cxx +++ b/Bus/Ivy/ThreadedSocket.cxx @@ -242,7 +242,7 @@ void CThreadedSocket::Send(const void* lpBuf, int nBufLen, int nFlags) void CThreadedSocket::SendTo(const void* lpBuf, int nBufLen, UINT nHostPort, const char * lpszHostAddress, int nFlags) { SOCKADDR_IN sockAddr; - + memset(&sockAddr,0,sizeof(sockAddr)); sockAddr.sin_family = AF_INET; @@ -266,11 +266,44 @@ void CThreadedSocket::SendTo(const void* lpBuf, int nBufLen, UINT nHostPort, con } } } - + sockAddr.sin_port = htons((u_short)nHostPort); SendTo(lpBuf, nBufLen, (SOCKADDR*)&sockAddr, sizeof(sockAddr), nFlags); } +void CThreadedSocket::AddMember( const char * lpszHostAddress ) +{ + int multicast_ttl = 64; // region + struct ip_mreq imr; + + TRACE("CThreadedSocket::AddMember adding %s\n", lpszHostAddress ); + imr.imr_multiaddr.s_addr = INADDR_ANY; + imr.imr_interface.s_addr = INADDR_ANY; + + if (lpszHostAddress ) + { + imr.imr_multiaddr.s_addr = inet_addr(lpszHostAddress); + if (imr.imr_multiaddr.s_addr == INADDR_NONE) + { + LPHOSTENT lphost; + lphost = gethostbyname(lpszHostAddress); + if (lphost != NULL) + imr.imr_multiaddr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr; + else + { + WSASetLastError(WSAEINVAL); + throw( new CThreadedSocketException( "AddMenber" )); + return; + } + } + } + if ( IN_CLASSD( htonl(imr.imr_multiaddr.s_addr) ) ) + { + SetSockOpt( IP_MULTICAST_TTL, &multicast_ttl, sizeof( multicast_ttl ), IPPROTO_IP ); + SetSockOpt( IP_ADD_MEMBERSHIP, &imr, sizeof( imr ), IPPROTO_IP ); + } + +} void CThreadedSocket::AsyncSelect(long lEvent) { assert(m_hSocket != INVALID_SOCKET); -- cgit v1.1