1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)look_up.c	5.2 (Berkeley) 3/13/86";
   9: #endif not lint
  10: 
  11: #include "talk_ctl.h"
  12: 
  13: /*
  14:  * See if the local daemon has an invitation for us.
  15:  */
  16: check_local()
  17: {
  18:     CTL_RESPONSE response;
  19:     register CTL_RESPONSE *rp = &response;
  20: 
  21:     /* the rest of msg was set up in get_names */
  22:     msg.ctl_addr = *(struct sockaddr *)&ctl_addr;
  23:     msg.ctl_addr.sa_family = htons(msg.ctl_addr.sa_family);
  24:     /* must be initiating a talk */
  25:     if (!look_for_invite(rp))
  26:         return (0);
  27:     /*
  28: 	 * There was an invitation waiting for us,
  29: 	 * so connect with the other (hopefully waiting) party
  30: 	 */
  31:     current_state = "Waiting to connect with caller";
  32:     do {
  33:         if (rp->addr.sa_family != AF_INET)
  34:             p_error("Response uses invalid network address");
  35:         errno = 0;
  36:         if (connect(sockt, &rp->addr, sizeof (rp->addr)) != -1)
  37:             return (1);
  38:     } while (errno == EINTR);
  39:     if (errno == ECONNREFUSED) {
  40:         /*
  41: 		 * The caller gave up, but his invitation somehow
  42: 		 * was not cleared. Clear it and initiate an
  43: 		 * invitation. (We know there are no newer invitations,
  44: 		 * the talkd works LIFO.)
  45: 		 */
  46:         ctl_transact(his_machine_addr, msg, DELETE, rp);
  47:         close(sockt);
  48:         open_sockt();
  49:         return (0);
  50:     }
  51:     p_error("Unable to connect with initiator");
  52:     /*NOTREACHED*/
  53: }
  54: 
  55: /*
  56:  * Look for an invitation on 'machine'
  57:  */
  58: look_for_invite(rp)
  59:     CTL_RESPONSE *rp;
  60: {
  61:     struct in_addr machine_addr;
  62: 
  63:     current_state = "Checking for invitation on caller's machine";
  64:     ctl_transact(his_machine_addr, msg, LOOK_UP, rp);
  65:     /* the switch is for later options, such as multiple invitations */
  66:     switch (rp->answer) {
  67: 
  68:     case SUCCESS:
  69:         msg.id_num = htonl(rp->id_num);
  70:         return (1);
  71: 
  72:     default:
  73:         /* there wasn't an invitation waiting for us */
  74:         return (0);
  75:     }
  76: }

Defined functions

check_local defined in line 16; used 1 times
look_for_invite defined in line 58; used 1 times
  • in line 25

Defined variables

sccsid defined in line 8; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2715
Valid CSS Valid XHTML 1.0 Strict