Annotation of 43BSDReno/games/hunt/NEW/faketalk.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *  Hunt
                      3:  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
                      4:  *  San Francisco, California
                      5:  *
                      6:  *  Copyright (c) 1985 Regents of the University of California.
                      7:  *  All rights reserved.  The Berkeley software License Agreement
                      8:  *  specifies the terms and conditions for redistribution.
                      9:  */
                     10: 
                     11: #include "bsd.h"
                     12: 
                     13: #if    defined(TALK_43) || defined(TALK_42)
                     14: 
                     15: # include      <stdio.h>
                     16: # include      <netdb.h>
                     17: # include      "talk_ctl.h"
                     18: # include      <ctype.h>
                     19: # include      <signal.h>
                     20: # include      <sys/time.h>
                     21: extern int     errno;
                     22: 
                     23: extern char    *index(), *rindex();
                     24: 
                     25: # define       TRUE            1
                     26: # define       FALSE           0
                     27: 
                     28: /* defines for fake talk message to announce start of game */
                     29: # ifdef TALK_43
                     30: # define       MASQUERADE      "\"Hunt Game\""
                     31: # else
                     32: # define       MASQUERADE      "HuntGame"
                     33: # endif
                     34: # define       RENDEZVOUS      "hunt-players"
                     35: # define       ARGV0           "HUNT-ANNOUNCE"
                     36: 
                     37: extern char            *my_machine_name;
                     38: extern char            *First_arg, *Last_arg;
                     39: 
                     40: /*
                     41:  *     exorcise - disspell zombies
                     42:  */
                     43: 
                     44: exorcise()
                     45: {
                     46:        (void) wait(0);
                     47: }
                     48: 
                     49: /*
                     50:  *     query the local SMTP daemon to expand the RENDEZVOUS mailing list
                     51:  *     and fake a talk request to each address thus found.
                     52:  */
                     53: 
                     54: faketalk()
                     55: {
                     56:        struct  servent         *sp;
                     57:        char                    buf[BUFSIZ];
                     58:        FILE                    *f;
                     59:        int                     service;        /* socket of service */
                     60:        struct  sockaddr_in     des;            /* address of destination */
                     61:        char                    *a, *b;
                     62:        extern  char            **environ;
                     63: 
                     64:        (void) signal(SIGCHLD, exorcise);
                     65: 
                     66:        if (fork() != 0)
                     67:                return;
                     68: 
                     69:        (void) signal(SIGINT, SIG_IGN);
                     70:        (void) signal(SIGPIPE, SIG_IGN);
                     71: 
                     72:        /*
                     73:         *      change argv so that a ps shows ARGV0
                     74:         */
                     75:        *environ = NULL;
                     76:        for (a = First_arg, b = ARGV0; a < Last_arg; a++) {
                     77:                if (*b)
                     78:                        *a = *b++;
                     79:                else
                     80:                        *a = ' ';
                     81:        }
                     82: 
                     83:        /*
                     84:         *      initialize "talk"
                     85:         */
                     86:        get_local_name(MASQUERADE);
                     87:        open_ctl();
                     88: 
                     89:        /*
                     90:         *      start fetching addresses
                     91:         */
                     92: 
                     93:        if ((sp = getservbyname("smtp", (char *) NULL)) == NULL) {
                     94: # ifdef LOG
                     95:                syslog(LOG_ERR, "faketalk: smtp protocol not supported\n");
                     96: # else LOG
                     97:                fprintf(stderr, "faketalk: stmp protocol not supported\n");
                     98: # endif LOG
                     99:                _exit(1);
                    100:        }
                    101: 
                    102:        bzero((char *) &des, sizeof (des));
                    103:        des.sin_family = AF_INET;
                    104:        des.sin_addr = my_machine_addr;
                    105:        des.sin_port = sp->s_port;
                    106: 
                    107:        if ((service = socket(des.sin_family, SOCK_STREAM, 0)) < 0) {
                    108: # ifdef LOG
                    109:                syslog(LOG_ERR, "falktalk:  socket");
                    110: # else LOG
                    111:                perror("falktalk:  socket");
                    112: # endif LOG
                    113:                _exit(-1);
                    114:        }
                    115: 
                    116:        if (connect(service, (struct sockaddr *) &des, sizeof(des)) != 0) {
                    117: # ifdef LOG
                    118:                syslog(LOG_ERR, "faketalk:  connect");
                    119: # else LOG
                    120:                perror("faketalk:  connect");
                    121: # endif LOG
                    122:                _exit(-1);
                    123:        }
                    124:        if ((f = fdopen(service, "r")) == NULL) {
                    125: # ifdef LOG
                    126:                syslog(LOG_ERR, "fdopen failed\n");
                    127: # else LOG
                    128:                fprintf(stderr, "fdopen failed\n");
                    129: # endif LOG
                    130:                _exit(-2);
                    131:        }
                    132: 
                    133:        (void) fgets(buf, BUFSIZ, f);
                    134:        (void) sprintf(buf, "HELO HuntGame@%s\r\n", my_machine_name);
                    135:        (void) write(service, buf, strlen(buf));
                    136:        (void) fgets(buf, BUFSIZ, f);
                    137:        (void) sprintf(buf, "EXPN %s@%s\r\n", RENDEZVOUS, my_machine_name);
                    138:        (void) write(service, buf, strlen(buf));
                    139:        while (fgets(buf, BUFSIZ, f) != NULL) {
                    140:                char    *s, *t;
                    141: 
                    142:                if (buf[0] != '2' || buf[1] != '5' || buf[2] != '0')
                    143:                        break;
                    144:                if ((s = index(buf + 4, '<')) == NULL)
                    145:                        s = buf + 4, t = buf + strlen(buf) - 1;
                    146:                else {
                    147:                        s += 1;
                    148:                        if ((t = rindex(s, '>')) == NULL)
                    149:                                t = s + strlen(s) - 1;
                    150:                        else
                    151:                                t -= 1;
                    152:                }
                    153:                while (isspace(*s))
                    154:                        s += 1;
                    155:                if (*s == '\\')
                    156:                        s += 1;
                    157:                while (isspace(*t))
                    158:                        t -= 1;
                    159:                *(t + 1) = '\0';
                    160:                do_announce(s);         /* construct and send talk request */
                    161:                if (buf[3] == ' ')
                    162:                        break;
                    163:        }
                    164:        (void) shutdown(service, 2);
                    165:        (void) close(service);
                    166:        _exit(0);
                    167: }
                    168: 
                    169: /*
                    170:  * The msg.id's for the invitations on the local and remote machines.
                    171:  * These are used to delete the invitations.
                    172:  */
                    173: 
                    174: do_announce(s)
                    175:        char    *s;
                    176: {
                    177:        CTL_RESPONSE                    response;
                    178:        extern  struct  sockaddr_in     ctl_addr;
                    179: 
                    180:        get_remote_name(s);     /* setup his_machine_addr, msg.r_name */
                    181: 
                    182: # ifdef TALK_43
                    183: # if BSD_RELEASE >= 44
                    184:        msg.ctl_addr = *(struct osockaddr *) &ctl_addr;
                    185: # else
                    186:        msg.ctl_addr = *(struct sockaddr *) &ctl_addr;
                    187: # endif
                    188:        msg.ctl_addr.sa_family = htons(msg.ctl_addr.sa_family);
                    189: # else
                    190:        msg.ctl_addr = ctl_addr;
                    191:        msg.ctl_addr.sin_family = htons(msg.ctl_addr.sin_family);
                    192: # endif
                    193:        msg.id_num = (int) htonl((u_long) -1);  /* an impossible id_num */
                    194:        ctl_transact(his_machine_addr, msg, ANNOUNCE, &response);
                    195:        if (response.answer != SUCCESS)
                    196:                return;
                    197: 
                    198:        /*
                    199:         * Have the daemons delete the invitations now that we
                    200:         * have announced.
                    201:         */
                    202: 
                    203:        /* we don't care if cleanup doesn't make it. */
                    204:        msg.type = DELETE;
                    205:        msg.id_num = (int) htonl(response.id_num);
                    206:        daemon_addr.sin_addr = his_machine_addr;
                    207:        if (sendto(ctl_sockt, (char *) &msg, sizeof (msg), 0,
                    208:                        (struct sockaddr *) &daemon_addr, sizeof(daemon_addr))
                    209:                        != sizeof(msg))
                    210:                p_error("send delete remote");
                    211: }
                    212: #else
                    213: faketalk()
                    214: {
                    215:        return;
                    216: }
                    217: #endif

unix.superglobalmegacorp.com

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