#include "soc.h"

/* the include file un.h defines sockaddr_um as :
struct sockaddr_un {
   short sun_family;
   char sun_path[108];
   };
*/

#define NAME "NODE1"

/* This program creates a UNIX domain datagram, binds a name to it, 
then reads from the socket */  

main () {
 int sock, length;
 struct sockaddr_un name;
 char buf[1024];

 /* create socket from which to read */
 sock = socket(AF_UNIX, SOCK_DGRAM, 0);
 if (sock < 0)  {
  perror("opening datagram socket");
  exit(1); }

 /* create name */
 name.sun_family = AF_UNIX;
 strcpy(name.sun_path, NAME);
 if ( bind(sock, (struct sockaddr *)&name, strlen(NAME)+3) < 0) { 
    perror("binding name to datagram socket");
    exit (1);
  }
  printf("socket ==> %s\n",NAME);
  /* read from socket */
  if (read(sock, buf, 1024) < 0)
    perror("receiving datagram packet");
  
printf("This is message received from NODE 0:\n");
  printf("==>%s\n", buf);

  close(sock);
  unlink(NAME); 
  exit(0);
}

