Annotation of 42BSD/ucb/talk/get_addrs.c, revision 1.1

1.1     ! root        1: /* $Header: get_addrs.c 1.5 83/04/01 17:55:41 moore Exp $ */
        !             2: 
        !             3: #include "talk_ctl.h"
        !             4: 
        !             5: struct hostent *gethostbyname();
        !             6: struct servent *getservbyname();
        !             7: 
        !             8: get_addrs(my_machine_name, his_machine_name)
        !             9: char *my_machine_name;
        !            10: char *his_machine_name;
        !            11: {
        !            12:     struct hostent *hp;
        !            13:     struct servent *sp;
        !            14: 
        !            15:     msg.pid = getpid();
        !            16: 
        !            17:        /* look up the address of the local host */
        !            18: 
        !            19:     hp = gethostbyname(my_machine_name);
        !            20: 
        !            21:     if (hp == (struct hostent *) 0) {
        !            22:        printf("This machine doesn't exist. Boy, am I confused!\n");
        !            23:        exit(-1);
        !            24:     }
        !            25: 
        !            26:     if (hp->h_addrtype != AF_INET) {
        !            27:        printf("Protocal mix up with local machine address\n");
        !            28:        exit(-1);
        !            29:     }
        !            30: 
        !            31:     bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
        !            32: 
        !            33:        /* if he is on the same machine, then simply copy */
        !            34: 
        !            35:     if ( bcmp((char *)&his_machine_name, (char *)&my_machine_name,
        !            36:                sizeof(his_machine_name)) == 0) {
        !            37:        bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
        !            38:                sizeof(his_machine_name));
        !            39:     } else {
        !            40: 
        !            41:        /* look up the address of the recipient's machine */
        !            42: 
        !            43:        hp = gethostbyname(his_machine_name);
        !            44: 
        !            45:        if (hp == (struct hostent *) 0 ) {
        !            46:            printf("%s is an unknown host\n", his_machine_name);
        !            47:            exit(-1);
        !            48:        }
        !            49: 
        !            50:        if (hp->h_addrtype != AF_INET) {
        !            51:            printf("Protocol mix up with remote machine address\n");
        !            52:            exit(-1);
        !            53:        }
        !            54: 
        !            55:        bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
        !            56:     }
        !            57: 
        !            58:        /* find the daemon portal */
        !            59: 
        !            60: #ifdef NTALK
        !            61:     sp = getservbyname("ntalk", "udp");
        !            62: #else
        !            63:     sp = getservbyname("talk", "udp");
        !            64: #endif
        !            65: 
        !            66:     if (strcmp(sp->s_proto, "udp") != 0) {
        !            67:        printf("Protocol mix up with talk daemon\n");
        !            68:        exit(-1);
        !            69:     }
        !            70: 
        !            71:     if (sp == 0) {
        !            72:            p_error("This machine doesn't support a tcp talk daemon");
        !            73:            exit(-1);
        !            74:     }
        !            75: 
        !            76:     daemon_port = sp->s_port;
        !            77: }

unix.superglobalmegacorp.com

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