home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_07 / 1n07036b < prev    next >
Text File  |  1990-10-31  |  898b  |  31 lines

  1.  
  2. LISTING 5
  3. /*
  4.  * respond_to_msg() - respond to message just sent to this node.
  5.  */
  6.  
  7. unsigned respond_to_msg(int nd, int event)
  8. {
  9.     char    read_buf[128];    /* A buffer for the data */
  10.     char    send_buf[128];    /* A buffer to send back */
  11.     static    int error_flag = 0;  /* Asynch upcall puts neterrno here */
  12.     int    len;              /* Length of the data in packet */
  13.     struct    addr reply_to;    /* IP address message came from */
  14.  
  15. /*
  16. * Get data from queue and find out who we have to reply to.
  17. */
  18.     if ((len = net_read(nd, read_buf, sizeof(read_buf),
  19.               (struct addr *) &reply_to, 0)) == -1) {
  20.         error_flag = neterrno;
  21.                 return;
  22.     }
  23.  
  24.     /* Send same the response back to the source host. */
  25.     strcpy(send_buf,read_buf);
  26.       if (net_writeto(nd, send_buf, sizeof(send_buf), &reply_to, 0) == -1) {
  27.           error_flag = neterrno;
  28.     return;                    /*  & return to the kernel */
  29. }
  30.  
  31.