int main (int argc, char *argv[]) { int index; set_program_name (argv[0]); iu_argp_init ("talk", program_authors); argp_parse (&argp, argc, argv, 0, &index, NULL); argc -= index; argv += index; if (argc == 0) { printf ("Usage: talk user [ttyname]\n"); exit (-1); } if (!isatty (0)) { printf ("Standard input must be a tty, not a pipe or a file\n"); exit (-1); } get_names (argc, argv); init_display (); open_ctl (); open_sockt (); start_msgs (); if (!check_local ()) invite_remote (); end_msgs (); set_edit_chars (); talk (); }
int main(int argc, char *argv[]) { if (pledge("stdio rpath inet dns getpw tty", NULL) == -1) err(1, "pledge"); get_names(argc, argv); init_display(); open_ctl(); open_sockt(); start_msgs(); if (!check_local()) invite_remote(); end_msgs(); set_edit_chars(); if (his_machine_addr.s_addr == my_machine_addr.s_addr) { if (pledge("stdio tty", NULL) == -1) err(1, "pledge"); } else { if (pledge("stdio inet tty", NULL) == -1) err(1, "pledge"); } talk(); return (0); }
int invite_remote (void) { int new_sockt; struct itimerval itimer; CTL_RESPONSE response; itimer.it_value.tv_sec = RING_WAIT; itimer.it_value.tv_usec = 0; itimer.it_interval = itimer.it_value; if (listen (sockt, 5) != 0) p_error ("Error on attempt to listen for caller"); msg.addr.sa_family = htons (my_addr.sin_family); memcpy (msg.addr.sa_data, ((struct sockaddr *) &my_addr)->sa_data, sizeof ((struct sockaddr *) & my_addr)->sa_data); msg.id_num = htonl (-1); /* an impossible id_num */ invitation_waiting = 1; announce_invite (); /* * Shut off the automatic messages for a while, * so we can use the interupt timer to resend the invitation */ end_msgs (); setitimer (ITIMER_REAL, &itimer, (struct itimerval *) 0); message ("Waiting for your party to respond"); signal (SIGALRM, re_invite); setjmp (invitebuf); while ((new_sockt = accept (sockt, 0, 0)) < 0) { if (errno == EINTR) continue; p_error ("Unable to connect with your party"); } close (sockt); sockt = new_sockt; /* * Have the daemons delete the invitations now that we * have connected. */ current_state = "Waiting for your party to respond"; start_msgs (); msg.id_num = htonl (local_id); ctl_transact (my_machine_addr, msg, DELETE, &response); msg.id_num = htonl (remote_id); ctl_transact (his_machine_addr, msg, DELETE, &response); invitation_waiting = 0; return 0; }
int main(int argc, char **argv) { (void) setlocale(LC_CTYPE, ""); get_names(argc, argv); check_writeable(); init_display(); open_ctl(); open_sockt(); start_msgs(); if (!check_local()) invite_remote(); end_msgs(); set_edit_chars(); talk(); return 0; }
void invite_remote(void) { int new_sockt; struct itimerval itimer; CTL_RESPONSE response; struct sockaddr rp; socklen_t rplen = sizeof(struct sockaddr); struct hostent *rphost; char rname[STRING_LENGTH]; itimer.it_value.tv_sec = RING_WAIT; itimer.it_value.tv_usec = 0; itimer.it_interval = itimer.it_value; if (listen(sockt, 5) != 0) quit("Error on attempt to listen for caller", 1); #ifdef MSG_EOR /* copy new style sockaddr to old, swap family (short in old) */ msg.addr = *(struct osockaddr *)&my_addr; /* XXX new to old style*/ msg.addr.sa_family = htons(my_addr.sin_family); #else msg.addr = *(struct sockaddr *)&my_addr; #endif msg.id_num = htonl(-1); /* an impossible id_num */ invitation_waiting = 1; announce_invite(); /* * Shut off the automatic messages for a while, * so we can use the interrupt timer to resend the invitation. * We no longer turn automatic messages back on to avoid a bonus * message after we've connected; this is okay even though end_msgs() * gets called again in main(). */ end_msgs(); setitimer(ITIMER_REAL, &itimer, NULL); message("Waiting for your party to respond"); signal(SIGALRM, re_invite); (void) setjmp(invitebuf); while ((new_sockt = accept(sockt, &rp, &rplen)) == -1) { if (errno == EINTR || errno == EWOULDBLOCK || errno == ECONNABORTED) continue; quit("Unable to connect with your party", 1); } close(sockt); sockt = new_sockt; /* * Have the daemons delete the invitations now that we * have connected. */ msg.id_num = htonl(local_id); ctl_transact(my_machine_addr, msg, DELETE, &response); msg.id_num = htonl(remote_id); ctl_transact(his_machine_addr, msg, DELETE, &response); invitation_waiting = 0; /* * Check to see if the other guy is coming from the machine * we expect. */ if (his_machine_addr.s_addr != ((struct sockaddr_in *)&rp)->sin_addr.s_addr) { rphost = gethostbyaddr((char *) &((struct sockaddr_in *)&rp)->sin_addr, sizeof(struct in_addr), AF_INET); if (rphost) snprintf(rname, STRING_LENGTH, "Answering talk request from %s@%s", msg.r_name, rphost->h_name); else snprintf(rname, STRING_LENGTH, "Answering talk request from %s@%s", msg.r_name, inet_ntoa(((struct sockaddr_in *)&rp)->sin_addr)); message(rname); } }