void lflag_print() { extern int pplan; register PERSON *pn; register int sflag, r; PERSON *tmp; DBT data, key; for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); pn = tmp; if (sflag != R_FIRST) putchar('\n'); lprint(pn); if (!pplan) { (void)show_text(pn->dir, _PATH_FORWARD, "Mail forwarded to"); (void)show_text(pn->dir, _PATH_PROJECT, "Project"); if (!show_text(pn->dir, _PATH_PLAN, "Plan")) (void)printf("No Plan.\n"); } } }
void read2pipe() { // std::in std::string line; while(std::getline(std::cin, line)) { std::istringstream s(line); std::string word; std::vector<std::string> words; while(s >> word) { std::string::iterator siter = word.begin(); bool english = true; for(; siter != word.end(); siter++) { if (*siter >= 'a' and *siter <= 'z') { } else if (*siter >= 'A' and *siter <= 'Z') { } else { english = false; } } if (english) { words.push_back(word); } } if (words.size() == 2) { lprint(words); } words.clear(); } }
void relay(int s) { char buf[8192]; int n; fd_set readfds; struct ttys *ttyp; /* Don't need our data anymore */ /* XXX This makes SunOS barf */ /* brk(0); */ signal(SIGQUIT, slirp_exit); signal(SIGHUP, slirp_exit); signal(SIGINT, slirp_exit); signal(SIGTERM, slirp_exit); /* Fudge to get term_raw and term_restore to work */ if (NULL == (ttyp = tty_attach (0, slirp_tty))) { lprint ("Error: tty_attach failed in misc.c:relay()\r\n"); slirp_exit (1); } ttyp->fd = 0; ttyp->flags |= TTY_CTTY; term_raw(ttyp); while (1) { FD_ZERO(&readfds); FD_SET(0, &readfds); FD_SET(s, &readfds); n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0); if (n <= 0) slirp_exit(0); if (FD_ISSET(0, &readfds)) { n = read(0, buf, 8192); if (n <= 0) slirp_exit(0); n = writen(s, buf, n); if (n <= 0) slirp_exit(0); } if (FD_ISSET(s, &readfds)) { n = read(s, buf, 8192); if (n <= 0) slirp_exit(0); n = writen(0, buf, n); if (n <= 0) slirp_exit(0); } } /* Just in case.... */ exit(1); }
static int get_dns_addr(struct in_addr *pdns_addr) { char buff[512]; char buff2[257]; FILE *f; int found = 0; struct in_addr tmp_addr; f = fopen("/etc/resolv.conf", "r"); if (!f) return -1; #ifdef DEBUG lprint("IP address of your DNS(s): "); #endif while (fgets(buff, 512, f) != NULL) { if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { if (!inet_aton(buff2, &tmp_addr)) continue; if (tmp_addr.s_addr == loopback_addr.s_addr) tmp_addr = our_addr; /* If it's the first one, set it to dns_addr */ if (!found) *pdns_addr = tmp_addr; #ifdef DEBUG else lprint(", "); #endif if (++found > 3) { #ifdef DEBUG lprint("(more)"); #endif break; } #ifdef DEBUG else lprint("%s", inet_ntoa(tmp_addr)); #endif } } fclose(f); if (!found) return -1; return 0; }
void icmpstats(PNATState pData) { lprint("\n"); lprint("ICMP stats:\n"); lprint(" %6d ICMP packets received\n", icmpstat.icps_received); lprint(" %6d were too short\n", icmpstat.icps_tooshort); lprint(" %6d with bad checksums\n", icmpstat.icps_checksum); lprint(" %6d with type not supported\n", icmpstat.icps_notsupp); lprint(" %6d with bad type feilds\n", icmpstat.icps_badtype); lprint(" %6d ICMP packets sent in reply\n", icmpstat.icps_reflect); }
void udpstats(PNATState pData) { lprint("\n"); lprint("UDP stats:\n"); lprint(" %6d datagrams received\n", udpstat.udps_ipackets); lprint(" %6d with packets shorter than header\n", udpstat.udps_hdrops); lprint(" %6d with bad checksums\n", udpstat.udps_badsum); lprint(" %6d with data length larger than packet\n", udpstat.udps_badlen); lprint(" %6d UDP socket cache misses\n", udpstat.udpps_pcbcachemiss); lprint(" %6d datagrams sent\n", udpstat.udps_opackets); }
/* * XXX Allow more than one X redirection? */ void redir_x(u_int32_t inaddr, int start_port, int display, int screen) { int i; if (x_port >= 0) { lprint("X Redir: X already being redirected.\r\n"); show_x(0, 0); } else { for (i = 6001 + (start_port-1); i <= 6100; i++) { if (solisten(htons(i), inaddr, htons(6000 + display), 0)) { /* Success */ x_port = i - 6000; x_display = display; x_screen = screen; show_x(0, 0); return; } } lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n"); } }
void print(int s) { if(s>=str_ptr){ normal_warning("print","bad string pointer"); return; }else if(s<STRING_OFFSET){ if(s<0){ normal_warning("print","bad string offset"); }else{ if((false)&&(selector> pseudo)){ print_char(s); return; } if(s==new_line_char_par){ if(selector<pseudo){ print_ln(); return; } } if(s<=0x7F){ print_char(s); }else if(s<=0x7FF){ print_char(0xC0+(s/0x40)); print_char(0x80+(s%0x40)); }else if(s<=0xFFFF){ print_char(0xE0+(s/0x1000)); print_char(0x80+((s%0x1000)/0x40)); print_char(0x80+((s%0x1000)%0x40)); }else if(s>=0x110000){ int c= s-0x110000; if(c>=256){ formatted_warning("print","bad raw byte to print (c=%d), skipped",c); }else{ print_char(c); } }else{ print_char(0xF0+(s/0x40000)); print_char(0x80+((s%0x40000)/0x1000)); print_char(0x80+(((s%0x40000)%0x1000)/0x40)); print_char(0x80+(((s%0x40000)%0x1000)%0x40)); } } return; } if(selector==new_string){ append_string(str_string(s),(unsigned)str_length(s)); return; } lprint(&str_lstring(s)); }
void write_log(ulong period) { # define buflen 1024 char buf[buflen]; snprintf(buf, buflen, "\t\t@ %lu:\tdevrtc_getusecs = [%lu]\n", period, devrtc_getusecs()); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tparticipating = [%d]\n", period, dam_participating); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tmyPr = [%E]\n", period, dam_myPr); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tmaxPrHeard = [%E]\n", period, dam_maxPrHeard); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tdelta = [%E]\n", period, dam_delta); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tmyID = [%s]\n", period, dam_myID); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tleaderID = [%s]\n", period, dam_leaderID); lprint(buf); snprintf(buf, buflen, "\t\t@ %lu:\tmyParent = [%s]\n", period, dam_myParent); lprint(buf); if (!strcmp(dam_myID, dam_leaderID)) { snprintf(buf, buflen, "\n%lu\t%lu\tpeak @ location\t%E %E %E\tnode %s\n", period, devrtc_getusecs(), devloc_getxloc(), devloc_getyloc(), devloc_getzloc(), dam_myID); lprint(buf); } sprintf(buf, "\n"); lprint(buf); return; }
void slirp_stats(void) { #ifdef LOG_ENABLED ipstats(); tcpstats(); udpstats(); icmpstats(); mbufstats(); sockstats(); #else lprint("SLIRP statistics code not compiled.\n"); #endif }
static void msg_handler(grn_ctx *ctx, grn_obj *msg) { uint32_t etime; struct timeval tv; grn_msg *m = (grn_msg *)msg; grn_com *com = ((grn_msg *)msg)->peer; session *s = com->opaque; s->stat = 3; gettimeofday(&tv, NULL); etime = (tv.tv_sec - s->tv.tv_sec) * 1000000 + (tv.tv_usec - s->tv.tv_usec); if (etime > etime_max) { etime_max = etime; } if (etime < etime_min) { etime_min = etime; } if (ctx->rc) { m->header.proto = 0; } switch (m->header.proto) { case GRN_COM_PROTO_GQTP : if (GRN_BULK_VSIZE(msg) == 2) { etime_amount += etime; } else { if (verbose) { GRN_TEXT_PUTC(ctx, msg, '\0'); lprint(ctx, "%8d(%4d) %8d : %s", s->query_id, s->n_sessions, etime, GRN_BULK_HEAD(msg)); } } if ((m->header.flags & GRN_CTX_TAIL)) { grn_com_queue_enque(ctx, &fsessions, (grn_com_queue_entry *)s); nrecv++; } break; case GRN_COM_PROTO_HTTP : nrecv++; /* lprint(ctx, "recv: %d, %d", (int)GRN_BULK_VSIZE(msg), nrecv); */ grn_com_close_(ctx, com); grn_com_queue_enque(ctx, &fsessions, (grn_com_queue_entry *)s); break; default : grn_com_close_(ctx, com); grn_com_queue_enque(ctx, &fsessions, (grn_com_queue_entry *)s); break; } grn_msg_close(ctx, msg); }
char *men_str(void *arg) { switch (item_type(arg)) { case L_STRING : { return lstring_value(arg); } break; case L_CONS_CELL : { return lstring_value(CAR(arg)); } break; default : { lprint(arg); dprintf(" is not a valid menu option\n"); exit(0); } } return NULL; }
static void sockstats(void) { char buff[256]; int n; struct socket *so; lprint(" \r\n"); lprint( "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\r\n"); for (so = tcb.so_next; so != &tcb; so = so->so_next) { n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE"); while (n < 17) buff[n++] = ' '; buff[17] = 0; lprint("%s %3d %15s %5d ", buff, so->s, inet_ntoa(so->so_laddr), ntohs(so->so_lport)); lprint("%15s %5d %5d %5d\r\n", inet_ntoa(so->so_faddr), ntohs(so->so_fport), so->so_rcv.sb_cc, so->so_snd.sb_cc); } for (so = udb.so_next; so != &udb; so = so->so_next) { n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000); while (n < 17) buff[n++] = ' '; buff[17] = 0; lprint("%s %3d %15s %5d ", buff, so->s, inet_ntoa(so->so_laddr), ntohs(so->so_lport)); lprint("%15s %5d %5d %5d\r\n", inet_ntoa(so->so_faddr), ntohs(so->so_fport), so->so_rcv.sb_cc, so->so_snd.sb_cc); } }
static void mbufstats(void) { struct mbuf *m; int i; lprint(" \r\n"); lprint("Mbuf stats:\r\n"); lprint(" %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max); i = 0; for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next) i++; lprint(" %6d mbufs on free list\r\n", i); i = 0; for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next) i++; lprint(" %6d mbufs on used list\r\n", i); lprint(" %6d mbufs queued as packets\r\n\r\n", if_queued); }
void tcpstats(PNATState pData) { lprint("\n"); lprint("TCP stats:\n"); lprint(" %6d packets sent\n", tcpstat.tcps_sndtotal); lprint(" %6d data packets (%d bytes)\n", tcpstat.tcps_sndpack, tcpstat.tcps_sndbyte); lprint(" %6d data packets retransmitted (%d bytes)\n", tcpstat.tcps_sndrexmitpack, tcpstat.tcps_sndrexmitbyte); lprint(" %6d ack-only packets (%d delayed)\n", tcpstat.tcps_sndacks, tcpstat.tcps_delack); lprint(" %6d URG only packets\n", tcpstat.tcps_sndurg); lprint(" %6d window probe packets\n", tcpstat.tcps_sndprobe); lprint(" %6d window update packets\n", tcpstat.tcps_sndwinup); lprint(" %6d control (SYN/FIN/RST) packets\n", tcpstat.tcps_sndctrl); lprint(" %6d times tcp_output did nothing\n", tcpstat.tcps_didnuttin); lprint(" %6d packets received\n", tcpstat.tcps_rcvtotal); lprint(" %6d acks (for %d bytes)\n", tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte); lprint(" %6d duplicate acks\n", tcpstat.tcps_rcvdupack); lprint(" %6d acks for unsent data\n", tcpstat.tcps_rcvacktoomuch); lprint(" %6d packets received in sequence (%d bytes)\n", tcpstat.tcps_rcvpack, tcpstat.tcps_rcvbyte); lprint(" %6d completely duplicate packets (%d bytes)\n", tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte); lprint(" %6d packets with some duplicate data (%d bytes duped)\n", tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte); lprint(" %6d out-of-order packets (%d bytes)\n", tcpstat.tcps_rcvoopack, tcpstat.tcps_rcvoobyte); lprint(" %6d packets of data after window (%d bytes)\n", tcpstat.tcps_rcvpackafterwin, tcpstat.tcps_rcvbyteafterwin); lprint(" %6d window probes\n", tcpstat.tcps_rcvwinprobe); lprint(" %6d window update packets\n", tcpstat.tcps_rcvwinupd); lprint(" %6d packets received after close\n", tcpstat.tcps_rcvafterclose); lprint(" %6d discarded for bad checksums\n", tcpstat.tcps_rcvbadsum); lprint(" %6d discarded for bad header offset fields\n", tcpstat.tcps_rcvbadoff); lprint(" %6d connection requests\n", tcpstat.tcps_connattempt); lprint(" %6d connection accepts\n", tcpstat.tcps_accepts); lprint(" %6d connections established (including accepts)\n", tcpstat.tcps_connects); lprint(" %6d connections closed (including %d drop)\n", tcpstat.tcps_closed, tcpstat.tcps_drops); lprint(" %6d embryonic connections dropped\n", tcpstat.tcps_conndrops); lprint(" %6d segments we tried to get rtt (%d succeeded)\n", tcpstat.tcps_segstimed, tcpstat.tcps_rttupdated); lprint(" %6d retransmit timeouts\n", tcpstat.tcps_rexmttimeo); lprint(" %6d connections dropped by rxmt timeout\n", tcpstat.tcps_timeoutdrop); lprint(" %6d persist timeouts\n", tcpstat.tcps_persisttimeo); lprint(" %6d keepalive timeouts\n", tcpstat.tcps_keeptimeo); lprint(" %6d keepalive probes sent\n", tcpstat.tcps_keepprobe); lprint(" %6d connections dropped by keepalive\n", tcpstat.tcps_keepdrops); lprint(" %6d correct ACK header predictions\n", tcpstat.tcps_predack); lprint(" %6d correct data packet header predictions\n", tcpstat.tcps_preddat); lprint(" %6d TCP cache misses\n", tcpstat.tcps_socachemiss); /* lprint(" Packets received too short: %d\n", tcpstat.tcps_rcvshort); */ /* lprint(" Segments dropped due to PAWS: %d\n", tcpstat.tcps_pawsdrop); */ }
void ipstats(PNATState pData) { lprint("\n"); lprint("IP stats:\n"); lprint(" %6d total packets received (%d were unaligned)\n", ipstat.ips_total, ipstat.ips_unaligned); lprint(" %6d with incorrect version\n", ipstat.ips_badvers); lprint(" %6d with bad header checksum\n", ipstat.ips_badsum); lprint(" %6d with length too short (len < sizeof(iphdr))\n", ipstat.ips_tooshort); lprint(" %6d with length too small (len < ip->len)\n", ipstat.ips_toosmall); lprint(" %6d with bad header length\n", ipstat.ips_badhlen); lprint(" %6d with bad packet length\n", ipstat.ips_badlen); lprint(" %6d fragments received\n", ipstat.ips_fragments); lprint(" %6d fragments dropped\n", ipstat.ips_fragdropped); lprint(" %6d fragments timed out\n", ipstat.ips_fragtimeout); lprint(" %6d packets reassembled ok\n", ipstat.ips_reassembled); lprint(" %6d outgoing packets fragmented\n", ipstat.ips_fragmented); lprint(" %6d total outgoing fragments\n", ipstat.ips_ofragments); lprint(" %6d with bad protocol field\n", ipstat.ips_noproto); lprint(" %6d total packets delivered\n", ipstat.ips_delivered); }
int main(int argc, char** argv) { full_argc(argc); Automat a; int c; Lexeme_list *list; c = getchar(); try { for (;;) { if (c==EOF) break; a.feed_char(c); a.run(); if (a.full_lex()) a.add_new_elem(); if (a.use_prev==0) { if (c=='\n') a.inc_nstr(); c = getchar(); } if (a.is_long()) throw "too long name"; } } catch (const char *s) { printf("Error: %s\n", s); return 1; } a.print_list(); if (a.is_any_errors()) { printf("Some lexical errors detected!\n"); return 1; } list = a.get_list(); PolizItem *lst; LabelTable *lable_lst; VarTable *var_lst; SyntaxAnalyzer s; s.set_list(list); try { s.analyze(); printf("SUCCESSFULL ANALYZATION!!!\n\n"); lst = s.poliz_list; lable_lst = s.label_list; } catch (const Exeption &ex) { printf("Error: %s\nbut found %s\nstr# %d\n", ex.GetComment(), ex.GetLexeme(), ex.GetNstr()); return 1; } lprint(lst); server.set(atoi(argv[2]), argv[1]); server.connection(); robot.set(argv, server); robot.readnsend_name(); robot.join_or_create(); printf("start playing\n"); robot.start_easy_game(lst); var_lst = PolizElem::Get_var_table(); delete_var_list(var_lst); delete_label_list(lable_lst); delete_poliz_list(lst); return 0; }
struct ttys *tty_attach(int unit, char *device) { char buff[256], *bptr; struct ttys *ttyp, *ttyp_tmp, *ttyp_last = 0; struct stat stat; DEBUG_CALL("tty_attach"); DEBUG_ARG("unit = %d", unit); DEBUG_ARG("device = %lx", (long)device); if ((ttyp = (struct ttys *)malloc(sizeof(struct ttys))) == NULL) return 0; memset(ttyp, 0, sizeof(struct ttys)); ttyp->next = 0; ttyp->fd = 0; /* Default changed from -1 -RedWolf */ /* Only open the device if there is one */ if (device) { if ((ttyp->fd = open(device, O_RDWR)) < 0) { free(ttyp); return 0; /* XXXXX */ } lprint ("Opening device %s...\r\n\r\n", device); } /* Link it to the *tail* of the list XXXXX */ if (!ttys) { ttys = ttyp; } else { for (ttyp_tmp = ttys; ttyp_tmp; ttyp_tmp = ttyp_tmp->next) ttyp_last = ttyp_tmp; /* XXX More checks? */ ttyp_last->next = ttyp; } #ifdef FULL_BOLT fd_nonblock(ttyp->fd); #endif if (ttyp->fd >= 0 && isatty(ttyp->fd) && fstat(ttyp->fd, &stat) == 0) { /* Save the current permissions */ ttyp->mode = stat.st_mode; #ifdef HAVE_FCHMOD fchmod(ttyp->fd, S_IRUSR|S_IWUSR); #else chmod(ttyname(ttyp->fd), S_IRUSR|S_IWUSR); #endif } ttyp->unit = unit; #ifndef FULL_BOLT ttyp->towrite = towrite_max; #endif #ifndef FULL_BOLT ttyp->baud = DEFAULT_BAUD; ttyp->bytesps = ttyp->baud/10; #endif ttyp->lastime = curtime; ttyp->sc_xc_state = 0; ttyp->sc_rc_state = 0; /* Default is SLIP */ ttyp->proto = PROTO_SLIP; ttyp->up = 1; /* SLIP is always up */ ttyp->if_input = sl_input; ttyp->if_encap = sl_encap; ttys_unit[unit] = ttyp; /* Rawify the terminal, if applicable */ if (ttyp->fd >= 0) term_raw(ttyp); /* Config the new tty */ if ((bptr = (char *)getenv("HOME"))) sprintf(buff, "%s/.slirprc-%d", bptr, unit); else sprintf(buff, ".slirprc-%d", unit); config(buff, ttyp->unit); return ttyp; }
/* * XXX This is ugly * We create and bind a socket, then fork off to another * process, which connects to this socket, after which we * exec the wanted program. If something (strange) happens, * the accept() call could block us forever. * * do_pty = 0 Fork/exec inetd style * do_pty = 1 Fork/exec using slirp.telnetd * do_ptr = 2 Fork/exec using pty */ int fork_exec(struct socket *so, char *ex, int do_pty) { int s; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); int opt; int master; char *argv[256]; #if 0 char buff[256]; #endif /* don't want to clobber the original */ char *bptr; char *curarg; int c, i, ret; DEBUG_CALL("fork_exec"); DEBUG_ARG("so = %lx", (long)so); DEBUG_ARG("ex = %lx", (long)ex); DEBUG_ARG("do_pty = %lx", (long)do_pty); if (do_pty == 2) { if (slirp_openpty(&master, &s) == -1) { lprint("Error: openpty failed: %s\n", strerror(errno)); return 0; } } else { memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || listen(s, 1) < 0) { lprint("Error: inet socket: %s\n", strerror(errno)); closesocket(s); return 0; } } switch(fork()) { case -1: lprint("Error: fork failed: %s\n", strerror(errno)); close(s); if (do_pty == 2) close(master); return 0; case 0: /* Set the DISPLAY */ if (do_pty == 2) { (void) close(master); #ifdef TIOCSCTTY /* XXXXX */ (void) setsid(); ioctl(s, TIOCSCTTY, (char *)NULL); #endif } else { getsockname(s, (struct sockaddr *)&addr, &addrlen); close(s); /* * Connect to the socket * XXX If any of these fail, we're in trouble! */ s = socket(AF_INET, SOCK_STREAM, 0); addr.sin_addr = loopback_addr; do { ret = connect(s, (struct sockaddr *)&addr, addrlen); } while (ret < 0 && errno == EINTR); } #if 0 if (x_port >= 0) { #ifdef HAVE_SETENV sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen); setenv("DISPLAY", buff, 1); #else sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen); putenv(buff); #endif } #endif dup2(s, 0); dup2(s, 1); dup2(s, 2); for (s = 3; s <= 255; s++) close(s); i = 0; bptr = strdup(ex); /* No need to free() this */ if (do_pty == 1) { /* Setup "slirp.telnetd -x" */ argv[i++] = "slirp.telnetd"; argv[i++] = "-x"; argv[i++] = bptr; } else do { /* Change the string into argv[] */ curarg = bptr; while (*bptr != ' ' && *bptr != (char)0) bptr++; c = *bptr; *bptr++ = (char)0; argv[i++] = strdup(curarg); } while (c); argv[i] = 0; execvp(argv[0], argv); /* Ooops, failed, let's tell the user why */ { char buff[256]; sprintf(buff, "Error: execvp of %s failed: %s\n", argv[0], strerror(errno)); write(2, buff, strlen(buff)+1); } close(0); close(1); close(2); /* XXX */ exit(1); default: if (do_pty == 2) { close(s); so->s = master; } else { /* * XXX this could block us... * XXX Should set a timer here, and if accept() doesn't * return after X seconds, declare it a failure * The only reason this will block forever is if socket() * of connect() fail in the child process */ do { so->s = accept(s, (struct sockaddr *)&addr, &addrlen); } while (so->s < 0 && errno == EINTR); closesocket(s); opt = 1; setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); opt = 1; setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); } fd_nonblock(so->s); /* Append the telnet options now */ if (so->so_m != 0 && do_pty == 1) { sbappend(so, so->so_m); so->so_m = 0; } return 1; } }
void add_emu(char *buff) { u_int lport, fport; u_int8_t tos = 0, emu = 0; char buff1[256], buff2[256], buff4[128]; char *buff3 = buff4; struct emu_t *emup; struct socket *so; if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) { lprint("Error: Bad arguments\r\n"); return; } if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) { lport = 0; if (sscanf(buff1, "%d", &fport) != 1) { lprint("Error: Bad first argument\r\n"); return; } } if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) { buff3 = 0; if (sscanf(buff2, "%256s", buff1) != 1) { lprint("Error: Bad second argument\r\n"); return; } } if (buff3) { if (strcmp(buff3, "lowdelay") == 0) tos = IPTOS_LOWDELAY; else if (strcmp(buff3, "throughput") == 0) tos = IPTOS_THROUGHPUT; else { lprint("Error: Expecting \"lowdelay\"/\"throughput\"\r\n"); return; } } if (strcmp(buff1, "ftp") == 0) emu = EMU_FTP; else if (strcmp(buff1, "irc") == 0) emu = EMU_IRC; else if (strcmp(buff1, "none") == 0) emu = EMU_NONE; /* ie: no emulation */ else { lprint("Error: Unknown service\r\n"); return; } /* First, check that it isn't already emulated */ for (emup = tcpemu; emup; emup = emup->next) { if (emup->lport == lport && emup->fport == fport) { lprint("Error: port already emulated\r\n"); return; } } /* link it */ emup = (struct emu_t *)malloc(sizeof (struct emu_t)); emup->lport = (u_int16_t)lport; emup->fport = (u_int16_t)fport; emup->tos = tos; emup->emu = emu; emup->next = tcpemu; tcpemu = emup; /* And finally, mark all current sessions, if any, as being emulated */ for (so = tcb.so_next; so != &tcb; so = so->so_next) { if ((lport && lport == ntohs(so->so_lport)) || (fport && fport == ntohs(so->so_fport))) { if (emu) so->so_emu = emu; if (tos) so->so_iptos = tos; } } lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport); }
static int do_client() { int rc = -1; char *buf; grn_thread thread; struct timeval tvb, tve; grn_com_header sheader; grn_ctx ctx_, *ctx = &ctx_; grn_ctx_init(ctx, 0); GRN_COM_QUEUE_INIT(&fsessions); sessions = grn_hash_create(ctx, NULL, sizeof(grn_sock), sizeof(session), 0); sheader.proto = GRN_COM_PROTO_GQTP; sheader.qtype = 0; sheader.keylen = 0; sheader.level = 0; sheader.flags = 0; sheader.status = 0; sheader.opaque = 0; sheader.cas = 0; if ((buf = GRN_MALLOC(BUFSIZE))) { if (!grn_com_event_init(ctx, &ev, 1000, sizeof(grn_com))) { ev.msg_handler = msg_handler; if (!THREAD_CREATE(thread, receiver, NULL)) { int cnt = 0; gettimeofday(&tvb, NULL); lprint(ctx, "begin: max_concurrency=%d max_tp=%d", max_con, max_tp); while (fgets(buf, BUFSIZE, stdin)) { uint32_t size = strlen(buf) - 1; session *s = session_alloc(ctx, dests + (cnt++ % dest_cnt)); if (s) { gettimeofday(&s->tv, NULL); s->n_query++; s->query_id = ++nsent; s->n_sessions = (nsent - nrecv); switch (proto) { case 'H' : case 'h' : if (grn_com_send_text(ctx, s->com, buf, size, 0)) { fprintf(stderr, "grn_com_send_text failed\n"); } s->stat = 2; /* lprint(ctx, "sent %04d %04d %d", s->n_query, s->query_id, s->com->fd); */ break; default : if (grn_com_send(ctx, s->com, &sheader, buf, size, 0)) { fprintf(stderr, "grn_com_send failed\n"); } break; } } else { fprintf(stderr, "grn_com_copen failed\n"); } for (;;) { gettimeofday(&tve, NULL); if ((nrecv < max_tp * (tve.tv_sec - tvb.tv_sec)) && (nsent - nrecv) < max_con) { break; } /* lprint(ctx, "s:%d r:%d", nsent, nrecv); */ usleep(1000); } if (!(nsent % 1000)) { lprint(ctx, " : %d", nsent); } } done = 1; pthread_join(thread, NULL); gettimeofday(&tve, NULL); { double qps; uint64_t etime = (tve.tv_sec - tvb.tv_sec); etime *= 1000000; etime += (tve.tv_usec - tvb.tv_usec); qps = (double)nsent * 1000000 / etime; lprint(ctx, "end : n=%d min=%d max=%d avg=%d qps=%f etime=%d.%06d", nsent, etime_min, etime_max, (int)(etime_amount / nsent), qps, etime / 1000000, etime % 1000000); } { session *s; GRN_HASH_EACH(ctx, sessions, id, NULL, NULL, &s, { session_close(ctx, s); }); } rc = 0; } else {
/* * invoke RSH */ int rsh_exec(struct socket *so, struct socket *ns, char *user, char *host, char *args) { int fd[2]; int fd0[2]; int s; char buff[256]; DEBUG_CALL("rsh_exec"); DEBUG_ARG("so = %lx", (long)so); if (pipe(fd)<0) { lprint("Error: pipe failed: %s\n", strerror(errno)); return 0; } /* #ifdef HAVE_SOCKETPAIR */ #if 1 if (socketpair(PF_UNIX,SOCK_STREAM,0, fd0) == -1) { close(fd[0]); close(fd[1]); lprint("Error: openpty failed: %s\n", strerror(errno)); return 0; } #else if (slirp_openpty(&fd0[0], &fd0[1]) == -1) { close(fd[0]); close(fd[1]); lprint("Error: openpty failed: %s\n", strerror(errno)); return 0; } #endif switch(fork()) { case -1: lprint("Error: fork failed: %s\n", strerror(errno)); close(fd[0]); close(fd[1]); close(fd0[0]); close(fd0[1]); return 0; case 0: close(fd[0]); close(fd0[0]); /* Set the DISPLAY */ if (x_port >= 0) { #ifdef HAVE_SETENV sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen); setenv("DISPLAY", buff, 1); #else sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen); putenv(buff); #endif } dup2(fd0[1], 0); dup2(fd0[1], 1); dup2(fd[1], 2); for (s = 3; s <= 255; s++) close(s); execlp("rsh","rsh","-l", user, host, args, NULL); /* Ooops, failed, let's tell the user why */ sprintf(buff, "Error: execlp of %s failed: %s\n", "rsh", strerror(errno)); write(2, buff, strlen(buff)+1); close(0); close(1); close(2); /* XXX */ exit(1); default: close(fd[1]); close(fd0[1]); ns->s=fd[0]; so->s=fd0[0]; return 1; } }
static void usage(void) { lprint(2, "usage: wikeyname\n"); exit(1); }
void fatal(char *str) { lprint("Node [%s] Fatal: %s\n", dam_myID, str); exit(-1); }