DOG: diff for point-to-point communication

LTH network news server newsuser at lth.se
Wed Sep 20 01:19:24 AEST 1989


Here is a context diff to convert at least one version of SGI `dog'
to use a point-to-point channel instead of broadcast messages.

The file to update is called udpbrdcst.c.

The job was done by Per Andersson at Computer Enginnering, Lund Institute
of Technology, Lund, Sweden.  We are all most grateful for his contribution
to mankind.

Dag Michael Bruck
--
Department of Automatic Control		Internet:  dag at control.lth.se
Lund Institute of Technology
P. O. Box 118				Phone:	+46 46-108779
S-221 00 Lund, SWEDEN			Fax:    +46 46-138118

==============================================================================

*** udpbrdcst.old	Tue Sep 19 17:14:06 1989
--- udpbrdcst.c	Tue Sep 19 17:14:08 1989
***************
*** 1,3 ****
--- 1,9 ----
+ /*
+  * Hacked May 19, 1989 by Per Andersson to use point to point communication
+  * between two specific hosts instead of broadcasts. This was done so that
+  * machines on different subnets may participate in a dogfight.
+  */
+ 
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
***************
*** 22,27 ****
--- 28,36 ----
      struct sockaddr_in *addr;
  {
      struct servent *sp;
+     struct hostent *hp; /* Added (PA) */
+     char *thehost;  /* Added (PA) */
+ 
      int fd;
      int on = 1;
      int arg;
***************
*** 36,49 ****
  	perror("socket");
      	return (-1);
      }
      if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
! 	perror("setsockopt");
!     	close(fd);
!     	return (-1);
      }
      bzero(addr, sizeof(addr));
      addr->sin_family = AF_INET;
      addr->sin_port = sp->s_port;
      if (bind(fd, addr, sizeof(*addr)) < 0) {
  	perror("bind");
      	close(fd);
--- 45,81 ----
  	perror("socket");
      	return (-1);
      }
+ /********************************** Removed (PA) ***
      if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
!       perror("setsockopt");
!       close(fd);
!       return (-1);
      }
      bzero(addr, sizeof(addr));
      addr->sin_family = AF_INET;
      addr->sin_port = sp->s_port;
+ ******************************************************/
+ 
+ /* New stuff here (PA) */
+ 
+     bzero(addr, sizeof(addr));
+     thehost = getenv("ENEMY");
+     if (!thehost) {
+     	printf("Environment variable ENEMY not set\n");
+ 	close(fd);
+         return(-1);
+     }
+     hp = gethostbyname(thehost);
+     if (!hp) {
+     	printf("Can't find host to connect to %s\n", thehost);
+ 	close(fd);
+     	return(-1);
+     }
+     addr->sin_family = AF_INET;
+     addr->sin_port = sp->s_port;
+ 
+ /* End of new stuff (PA) */
+ 
      if (bind(fd, addr, sizeof(*addr)) < 0) {
  	perror("bind");
      	close(fd);
***************
*** 50,56 ****
      	return (-1);
      }
      
!     addr->sin_addr.s_addr = INADDR_BROADCAST;
  
      if (ioctl(fd, FIONBIO, &on) < 0) {	/* Turn on non-blocking I/O */
  	perror("ioctl");
--- 82,89 ----
      	return (-1);
      }
      
! /*    addr->sin_addr.s_addr = INADDR_BROADCAST; *** Removed (PA) */
!     bcopy(hp->h_addr, &addr->sin_addr, sizeof(addr->sin_addr)); /* New (PA) */
  
      if (ioctl(fd, FIONBIO, &on) < 0) {	/* Turn on non-blocking I/O */
  	perror("ioctl");
-- 
Department of Automatic Control		Internet:  dag at control.lth.se
Lund Institute of Technology
P. O. Box 118				Phone:	+46 46-108779
S-221 00 Lund, SWEDEN			Fax:    +46 46-138118



More information about the Comp.sys.sgi mailing list