Annotation of 43BSDReno/usr.bin/talk/look_up.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)look_up.c  5.6 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include "talk_ctl.h"
                     25: 
                     26: /*
                     27:  * See if the local daemon has an invitation for us.
                     28:  */
                     29: check_local()
                     30: {
                     31:        CTL_RESPONSE response;
                     32:        register CTL_RESPONSE *rp = &response;
                     33: 
                     34:        /* the rest of msg was set up in get_names */
                     35: #ifdef MSG_EOR
                     36:        /* copy new style sockaddr to old, swap family (short in old) */
                     37:        msg.ctl_addr = *(struct osockaddr *)&ctl_addr;
                     38:        msg.ctl_addr.sa_family = htons(ctl_addr.sin_family);
                     39: #else
                     40:        msg.ctl_addr = *(struct sockaddr *)&ctl_addr;
                     41: #endif
                     42:        /* must be initiating a talk */
                     43:        if (!look_for_invite(rp))
                     44:                return (0);
                     45:        /*
                     46:         * There was an invitation waiting for us, 
                     47:         * so connect with the other (hopefully waiting) party 
                     48:         */
                     49:        current_state = "Waiting to connect with caller";
                     50:        do {
                     51:                if (rp->addr.sa_family != AF_INET)
                     52:                        p_error("Response uses invalid network address");
                     53:                errno = 0;
                     54:                if (connect(sockt, &rp->addr, sizeof (rp->addr)) != -1)
                     55:                        return (1);
                     56:        } while (errno == EINTR);
                     57:        if (errno == ECONNREFUSED) {
                     58:                /*
                     59:                 * The caller gave up, but his invitation somehow
                     60:                 * was not cleared. Clear it and initiate an 
                     61:                 * invitation. (We know there are no newer invitations,
                     62:                 * the talkd works LIFO.)
                     63:                 */
                     64:                ctl_transact(his_machine_addr, msg, DELETE, rp);
                     65:                close(sockt);
                     66:                open_sockt();
                     67:                return (0);
                     68:        }
                     69:        p_error("Unable to connect with initiator");
                     70:        /*NOTREACHED*/
                     71: }
                     72: 
                     73: /*
                     74:  * Look for an invitation on 'machine'
                     75:  */
                     76: look_for_invite(rp)
                     77:        CTL_RESPONSE *rp;
                     78: {
                     79:        struct in_addr machine_addr;
                     80: 
                     81:        current_state = "Checking for invitation on caller's machine";
                     82:        ctl_transact(his_machine_addr, msg, LOOK_UP, rp);
                     83:        /* the switch is for later options, such as multiple invitations */
                     84:        switch (rp->answer) {
                     85: 
                     86:        case SUCCESS:
                     87:                msg.id_num = htonl(rp->id_num);
                     88:                return (1);
                     89: 
                     90:        default:
                     91:                /* there wasn't an invitation waiting for us */
                     92:                return (0);
                     93:        }
                     94: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.