[PD-cvs] externals/OSCx/src htmsocket.c, 1.7, 1.8 htmsocket.h, 1.4, 1.5 sendOSC.c, 1.8, 1.9

Hans-Christoph Steiner eighthave at users.sourceforge.net
Thu Jun 14 17:05:15 CEST 2007


Update of /cvsroot/pure-data/externals/OSCx/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19313

Modified Files:
	htmsocket.c htmsocket.h sendOSC.c 
Log Message:
checked in patch from tracker 1656382 to fix TTL for non-multicast

Index: htmsocket.h
===================================================================
RCS file: /cvsroot/pure-data/externals/OSCx/src/htmsocket.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** htmsocket.h	2 Jan 2007 01:38:20 -0000	1.4
--- htmsocket.h	14 Jun 2007 15:05:13 -0000	1.5
***************
*** 39,43 ****
  /* open a socket for HTM communication to given  host on given portnumber */
  /* if host is 0 then UNIX protocol is used (i.e. local communication) */
! void *OpenHTMSocket(char *host, int portnumber, unsigned char multicast_TTL);
  
  /* send a buffer of data over htm socket, returns TRUE on success.
--- 39,43 ----
  /* open a socket for HTM communication to given  host on given portnumber */
  /* if host is 0 then UNIX protocol is used (i.e. local communication) */
! void *OpenHTMSocket(char *host, int portnumber, short *multicast_TTL);
  
  /* send a buffer of data over htm socket, returns TRUE on success.

Index: htmsocket.c
===================================================================
RCS file: /cvsroot/pure-data/externals/OSCx/src/htmsocket.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** htmsocket.c	17 Jan 2007 15:38:05 -0000	1.7
--- htmsocket.c	14 Jun 2007 15:05:13 -0000	1.8
***************
*** 104,110 ****
  } desc;
  
  /* open a socket for HTM communication to given  host on given portnumber */
  /* if host is 0 then UNIX protocol is used (i.e. local communication */
! void *OpenHTMSocket(char *host, int portnumber, unsigned char multicast_TTL)
  {
  	struct sockaddr_in  cl_addr;
--- 104,130 ----
  } desc;
  
+ int IsAddressMulticast(unsigned long address)
+ {
+     unsigned long adr = ntohl(address);
+     unsigned char A = (unsigned char)((adr & 0xFF000000) >> 24);
+     unsigned char B = (unsigned char)((adr & 0xFF0000) >> 16);
+     unsigned char C = (unsigned char)((adr & 0xFF00) >> 8);
+ 
+     if (A==224 && B==0 && C==0) {
+         // This multicast group range is reserved for routing
+         // information and not meant to be used by applications.
+         return -1;
+     }
+ 
+     // This is the multicast group IP range
+     if (A>=224 && A<=239)
+         return 1;
+ 
+     return 0;
+ }
+ 
  /* open a socket for HTM communication to given  host on given portnumber */
  /* if host is 0 then UNIX protocol is used (i.e. local communication */
! void *OpenHTMSocket(char *host, int portnumber, short *multicast_TTL)
  {
  	struct sockaddr_in  cl_addr;
***************
*** 234,247 ****
  				}
  
! 				// set multicast Time-To-Live: ss
! 				if(setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_TTL, sizeof(multicast_TTL)) == -1) {
! 				  perror("setsockopt TTL");
! 				}
  
! 				if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
! 					perror("could not bind\n");
! 					closesocket(sockfd);
! 					sockfd = -1;
! 				}
  			}
  			else { perror("unable to make socket\n");}
--- 254,288 ----
  				}
  
!                 // check if specified address is a multicast group: ss 2007
!                 int multicast = IsAddressMulticast(o->serv_addr.sin_addr.s_addr);
  
!                 if (multicast == -1) {
!                     perror("Multicast group range 224.0.0.[0-255] is reserved.\n");
!                     *multicast_TTL = -2;
!                     close(sockfd);
!                     sockfd = -1;
!                 }
!                 else {
!                     // set TTL according to whether we have a multicast group or not
!                     if (multicast) {
!                         if (*multicast_TTL<0)
!                             *multicast_TTL = 1;
!                     } else
!                         *multicast_TTL = -1;
! 
!                     // set multicast Time-To-Live only if it is a multicast group: ss 2007
!                     if(*multicast_TTL>=0) {
!                         unsigned char ttl = (unsigned char)*multicast_TTL;
!                         if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
!                                        &ttl, sizeof(ttl)) == -1)
!                             perror("setsockopt TTL");
!                     }
! 
!                     if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
!                         perror("could not bind\n");
!                         closesocket(sockfd);
!                         sockfd = -1;
!                     }
!                 }
  			}
  			else { perror("unable to make socket\n");}
***************
*** 260,273 ****
  				}
  
! 				// set multicast Time-To-Live: ss 2006
! 				if(setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_TTL, sizeof(multicast_TTL)) == -1) {
! 				  perror("setsockopt TTL");
! 				}
  
! 				if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
! 					perror("could not bind\n");
! 					close(sockfd);
! 					sockfd = -1;
! 				}
  			}
  			else { perror("unable to make socket\n");}
--- 301,335 ----
  				}
  
!                 // check if specified address is a multicast group: ss 2007
!                 int multicast = IsAddressMulticast(o->serv_addr.sin_addr.s_addr);
  
!                 if (multicast == -1) {
!                     perror("Multicast group range 224.0.0.[0-255] is reserved.\n");
!                     *multicast_TTL = -2;
!                     close(sockfd);
!                     sockfd = -1;
!                 }
!                 else {
!                     // check if specified address is a multicast group: ss 2007
!                     if (multicast) {
!                         if (*multicast_TTL<0)
!                             *multicast_TTL = 1;
!                     } else
!                         *multicast_TTL = -1;
! 
!                     // set multicast Time-To-Live only if it is a multicast group: ss 2007
!                     if(*multicast_TTL>=0) {
!                         unsigned char ttl = (unsigned char)*multicast_TTL;
!                         if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
!                                        &ttl, sizeof(ttl)) == -1)
!                             perror("setsockopt TTL");
!                     }
! 
!                     if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
!                         perror("could not bind\n");
!                         close(sockfd);
!                         sockfd = -1;
!                     }
!                 }
  			}
  			else { perror("unable to make socket\n");}

Index: sendOSC.c
===================================================================
RCS file: /cvsroot/pure-data/externals/OSCx/src/sendOSC.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** sendOSC.c	2 Jan 2007 01:38:20 -0000	1.8
--- sendOSC.c	14 Jun 2007 15:05:13 -0000	1.9
***************
*** 193,197 ****
    t_symbol *hostname;
    int portno = fportno;
!   unsigned char ttl=1;
    char *protocolStr;
    /* create a socket */
--- 193,197 ----
    t_symbol *hostname;
    int portno = fportno;
!   short ttl=-1;
    char *protocolStr;
    /* create a socket */
***************
*** 212,216 ****
    if (argc >= 3) {
  	  if (argv[2].a_type==A_FLOAT)
! 		  ttl = (unsigned char)argv[2].a_w.w_float;
  	  else
  		  return;
--- 212,216 ----
    if (argc >= 3) {
  	  if (argv[2].a_type==A_FLOAT)
! 		  ttl = (short)(unsigned char)argv[2].a_w.w_float;
  	  else
  		  return;
***************
*** 220,226 ****
    if(x->x_htmsocket == 0)
    {
! 		x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno, ttl);
! 		if (!x->x_htmsocket)
!       post("sendOSC: Couldn't open socket: ");
      else
  	{
--- 220,229 ----
    if(x->x_htmsocket == 0)
    {
! 		x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno, &ttl);
! 		if (!x->x_htmsocket) {
!             post("sendOSC: Couldn't open socket: ");
!             if (ttl==-2)
!                 post("sendOSC: Multicast group range 224.0.0.[0-255] is reserved.\n");
!         }
      else
  	{
***************
*** 237,246 ****
            break;
  	  }
!       post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s ttl = %d", 
!         hostname->s_name, portno, x->x_htmsocket, protocolStr, ttl);
! 			outlet_float(x->x_obj.ob_outlet, 1);
! 		}
! 	}
! 	else 
      perror("call to sendOSC_connect() against unavailable socket handle");
  }
--- 240,253 ----
            break;
  	  }
!       if (ttl>=0)
!           post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s ttl = %d", 
!                hostname->s_name, portno, x->x_htmsocket, protocolStr, ttl);
!       else
!           post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s", 
!                hostname->s_name, portno, x->x_htmsocket, protocolStr);
!       outlet_float(x->x_obj.ob_outlet, 1);
!     }
!   }
!   else 
      perror("call to sendOSC_connect() against unavailable socket handle");
  }





More information about the Pd-cvs mailing list