int dopasswd(cisco_t *cp, char *pw_prompt) { char *w; int done = 0; int len_prompt = strlen(cp->prompt); for ( ; ; ) { if (pw_prompt) /* dousername may have read passwd prompt */ w = pw_prompt; else w = mygetwd(cp->fin, cp->prompt); pw_prompt = NULL; if (w == NULL) break; if (strlen(w) >= len_prompt && strncmp(&w[strlen(w)-len_prompt], cp->prompt, len_prompt) == 0) break; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "Password:? got - %s\n", w); #endif if (strcmp(w, PWPROMPT) == 0) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send passwd: %s\n", cp->passwd); } #endif fprintf(cp->fout, "%s\n", cp->passwd); fflush(cp->fout); for ( ; ; ) { w = mygetwd(cp->fin, cp->prompt); if (w == NULL || strcmp(w, PWPROMPT) == 0) /* closed connection or user-level password re-prompt */ break; if (strlen(w) >= len_prompt && strncmp(&w[strlen(w)-len_prompt], cp->prompt, len_prompt) == 0) { /* command prompt */ done = 1; break; } } break; } } if (done == 0) { fprintf(stderr, "Error: Cisco user-level password negotiation failed for \"%s\"\n", cp->host); fprintf(stderr, "To check that a user-level password is required, enter the following command:\n" " $ telnet %s\n" "If the prompt \"%s\" does not appear, no user-level password is required.\n" "Otherwise, enter the user-level password \"%s\" to check that this\n" "is correct.\n", cp->host, PWPROMPT, cp->passwd); } return done; }
int dousername(cisco_t *cp, char **pw_prompt) { char *w; int len, done = 0; int len_prompt = strlen(cp->prompt); for ( ; ; ) { w = mygetwd(cp->fin, cp->prompt); if (w == NULL) break; if (strlen(w) >= len_prompt && strncmp(&w[strlen(w)-len_prompt], cp->prompt, len_prompt) == 0) break; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "Username:? got - %s\n", w); #endif if (strcmp(w, USERPROMPT) == 0) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send username: %s\n", cp->username); } #endif fprintf(cp->fout, "%s\n", cp->username); fflush(cp->fout); for ( ; ; ) { w = mygetwd(cp->fin, cp->prompt); if (w == NULL || strcmp(w, USERPROMPT) == 0) /* closed connection or Username re-prompt */ break; len = strlen(w); if ((len >= len_prompt && strncmp(&w[len-len_prompt], cp->prompt, len_prompt) == 0) || w[len-1] == ':') { /* command prompt or passwd */ if (w[len-1] == ':') *pw_prompt = w; done = 1; break; } } break; } } if (done == 0) { fprintf(stderr, "Error: Cisco username negotiation failed for \"%s\"\n", cp->host); fprintf(stderr, "To check that a username is required, enter the following command:\n" " $ telnet %s\n" "If the prompt \"%s\" does not appear, no username is required.\n" "Otherwise, enter the username \"%s\" to check that this\n" "is correct.\n", cp->host, USERPROMPT, cp->username); } return done; }
void cinit(void) { Sym *s; int i; nullgen.sym = S; nullgen.offset = 0; nullgen.type = D_NONE; if(FPCHIP) nullgen.dval = 0; for(i=0; i<sizeof(nullgen.sval); i++) nullgen.sval[i] = 0; nullgen.displace = 0; nullgen.type = D_NONE; nullgen.index = D_NONE; nullgen.scale = 0; nullgen.field = 0; nerrors = 0; iostack = I; iofree = I; peekc = IGN; nhunk = 0; for(i=0; i<NHASH; i++) hash[i] = S; for(i=0; itab[i].name; i++) { s = slookup(itab[i].name); s->type = itab[i].type; s->value = itab[i].value; } pathname = allocn(pathname, 0, 100); if(mygetwd(pathname, 99) == 0) { pathname = allocn(pathname, 100, 900); if(mygetwd(pathname, 999) == 0) strcpy(pathname, "/???"); } }
int main(int argc, char **argv) { int envc; /* environment argument count */ char **envv; /* environment argument list */ FILE *names; /* name file pointer */ int oldnum; /* number in old cross-ref */ char path[PATHLEN + 1]; /* file path */ FILE *oldrefs; /* old cross-reference file */ char *s; int c, i; pid_t pid; /* save the command name for messages */ argv0 = basename(argv[0]); /* get the current directory for build() and line-oriented P command */ if (mygetwd(currentdir) == NULL) { (void) fprintf(stderr, "cscope: warning: cannot get current directory name\n"); (void) strcpy(currentdir, "<unknown>"); } /* initialize any view path; (saves time since currendir is known) */ vpinit(currentdir); dbvpndirs = vpndirs; /* number of directories in database view path */ /* directories (including current) in database view path */ dbvpdirs = vpdirs; /* the first source directory is the current directory */ sourcedir("."); /* read the environment */ editor = mygetenv("EDITOR", EDITOR); editor = mygetenv("VIEWER", editor); /* use viewer if set */ home = getenv("HOME"); shell = mygetenv("SHELL", SHELL); tmpdir = mygetenv("TMPDIR", TMPDIR); /* increment nesting depth */ cscopedepth = atoi(mygetenv("CSCOPEDEPTH", "0")); (void) sprintf(path, "CSCOPEDEPTH=%d", ++cscopedepth); (void) putenv(stralloc(path)); if ((s = getenv("CSCOPEOPTIONS")) != NULL) { /* parse the environment option string */ envc = 1; envv = mymalloc(sizeof (char *)); s = strtok(stralloc(s), OPTSEPS); while (s != NULL) { envv = myrealloc(envv, ++envc * sizeof (char *)); envv[envc - 1] = stralloc(s); s = strtok((char *)NULL, OPTSEPS); } /* set the environment options */ options(envc, envv); } /* set the command line options */ options(argc, argv); /* create the temporary file names */ pid = getpid(); (void) sprintf(temp1, "%s/cscope%d.1", tmpdir, (int)pid); (void) sprintf(temp2, "%s/cscope%d.2", tmpdir, (int)pid); /* if running in the foreground */ if (signal(SIGINT, SIG_IGN) != SIG_IGN) { /* cleanup on the interrupt and quit signals */ (void) signal(SIGINT, myexit); (void) signal(SIGQUIT, myexit); } /* cleanup on the hangup signal */ (void) signal(SIGHUP, myexit); /* if the database path is relative and it can't be created */ if (reffile[0] != '/' && access(".", WRITE) != 0) { /* if the database may not be up-to-date or can't be read */ (void) sprintf(path, "%s/%s", home, reffile); if (isuptodate == NO || access(reffile, READ) != 0) { /* put it in the home directory */ reffile = stralloc(path); (void) sprintf(path, "%s/%s", home, invname); invname = stralloc(path); (void) sprintf(path, "%s/%s", home, invpost); invpost = stralloc(path); (void) fprintf(stderr, "cscope: symbol database will be %s\n", reffile); } } /* if the cross-reference is to be considered up-to-date */ if (isuptodate == YES) { if ((oldrefs = vpfopen(reffile, "r")) == NULL) { cannotopen(reffile); exit(1); } /* * get the crossref file version but skip the current * directory */ if (fscanf(oldrefs, "cscope %d %*s", &fileversion) != 1) { (void) fprintf(stderr, "cscope: cannot read file version from file %s\n", reffile); exit(1); } if (fileversion >= 8) { /* override these command line options */ compress = YES; invertedindex = NO; /* see if there are options in the database */ for (;;) { /* no -q leaves multiple blanks */ while ((c = getc(oldrefs)) == ' ') { ; } if (c != '-') { (void) ungetc(c, oldrefs); break; } switch (c = getc(oldrefs)) { case 'c': /* ASCII characters only */ compress = NO; break; case 'q': /* quick search */ invertedindex = YES; (void) fscanf(oldrefs, "%ld", &totalterms); break; case 'T': /* truncate symbols to 8 characters */ dbtruncated = YES; truncatesyms = YES; break; } } initcompress(); /* seek to the trailer */ if (fscanf(oldrefs, "%ld", &traileroffset) != 1) { (void) fprintf(stderr, "cscope: cannot read trailer offset from " "file %s\n", reffile); exit(1); } if (fseek(oldrefs, traileroffset, 0) != 0) { (void) fprintf(stderr, "cscope: cannot seek to trailer in " "file %s\n", reffile); exit(1); } } /* * read the view path for use in converting relative paths to * full paths * * note: don't overwrite vp[n]dirs because this can cause * the wrong database index files to be found in the viewpath */ if (fileversion >= 13) { if (fscanf(oldrefs, "%d", &dbvpndirs) != 1) { (void) fprintf(stderr, "cscope: cannot read view path size from " "file %s\n", reffile); exit(1); } if (dbvpndirs > 0) { dbvpdirs = mymalloc( dbvpndirs * sizeof (char *)); for (i = 0; i < dbvpndirs; ++i) { if (fscanf(oldrefs, "%s", path) != 1) { (void) fprintf(stderr, "cscope: cannot read view " "path from file %s\n", reffile); exit(1); } dbvpdirs[i] = stralloc(path); } } } /* skip the source and include directory lists */ skiplist(oldrefs); skiplist(oldrefs); /* get the number of source files */ if (fscanf(oldrefs, "%d", &nsrcfiles) != 1) { (void) fprintf(stderr, "cscope: cannot read source file size from " "file %s\n", reffile); exit(1); } /* get the source file list */ srcfiles = mymalloc(nsrcfiles * sizeof (char *)); if (fileversion >= 9) { /* allocate the string space */ if (fscanf(oldrefs, "%d", &oldnum) != 1) { (void) fprintf(stderr, "cscope: cannot read string space size " "from file %s\n", reffile); exit(1); } s = mymalloc(oldnum); (void) getc(oldrefs); /* skip the newline */ /* read the strings */ if (fread(s, oldnum, 1, oldrefs) != 1) { (void) fprintf(stderr, "cscope: cannot read source file names " "from file %s\n", reffile); exit(1); } /* change newlines to nulls */ for (i = 0; i < nsrcfiles; ++i) { srcfiles[i] = s; for (++s; *s != '\n'; ++s) { ; } *s = '\0'; ++s; } /* if there is a file of source file names */ if (namefile != NULL && (names = vpfopen(namefile, "r")) != NULL || (names = vpfopen(NAMEFILE, "r")) != NULL) { /* read any -p option from it */ while (fscanf(names, "%s", path) == 1 && *path == '-') { i = path[1]; s = path + 2; /* for "-Ipath" */ if (*s == '\0') { /* if "-I path" */ (void) fscanf(names, "%s", path); s = path; } switch (i) { case 'p': /* file path components */ /* to display */ if (*s < '0' || *s > '9') { (void) fprintf(stderr, "cscope: -p option " "in file %s: " "missing or " "invalid numeric " "value\n", namefile); } dispcomponents = atoi(s); } } (void) fclose(names); } } else { for (i = 0; i < nsrcfiles; ++i) { if (fscanf(oldrefs, "%s", path) != 1) { (void) fprintf(stderr, "cscope: cannot read source file " "name from file %s\n", reffile); exit(1); } srcfiles[i] = stralloc(path); } } (void) fclose(oldrefs); } else { /* get source directories from the environment */ if ((s = getenv("SOURCEDIRS")) != NULL) { sourcedir(s); } /* make the source file list */ srcfiles = mymalloc(msrcfiles * sizeof (char *)); makefilelist(); if (nsrcfiles == 0) { (void) fprintf(stderr, "cscope: no source files found\n"); printusage(); exit(1); } /* get include directories from the environment */ if ((s = getenv("INCLUDEDIRS")) != NULL) { includedir(s); } /* add /usr/include to the #include directory list */ includedir("/usr/include"); /* initialize the C keyword table */ initsymtab(); /* create the file name(s) used for a new cross-reference */ (void) strcpy(path, reffile); s = basename(path); *s = '\0'; (void) strcat(path, "n"); ++s; (void) strcpy(s, basename(reffile)); newreffile = stralloc(path); (void) strcpy(s, basename(invname)); newinvname = stralloc(path); (void) strcpy(s, basename(invpost)); newinvpost = stralloc(path); /* build the cross-reference */ initcompress(); build(); if (buildonly == YES) { exit(0); } } opendatabase(); /* * removing a database will not release the disk space if a cscope * process has the file open, so a project may want unattended cscope * processes to exit overnight, including their subshells and editors */ if (noacttime) { (void) signal(SIGALRM, timedout); (void) alarm(noacttime); } /* * if using the line oriented user interface so cscope can be a * subprocess to emacs or samuel */ if (linemode == YES) { if (*pattern != '\0') { /* do any optional search */ if (search() == YES) { while ((c = getc(refsfound)) != EOF) { (void) putchar(c); } } } if (onesearch == YES) { myexit(0); } for (;;) { char buf[PATLEN + 2]; if (noacttime) { (void) alarm(noacttime); } (void) printf(">> "); (void) fflush(stdout); if (fgets(buf, sizeof (buf), stdin) == NULL) { myexit(0); } /* remove any trailing newline character */ if (*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; } switch (*buf) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* samuel only */ field = *buf - '0'; (void) strcpy(pattern, buf + 1); (void) search(); (void) printf("cscope: %d lines\n", totallines); while ((c = getc(refsfound)) != EOF) { (void) putchar(c); } break; case 'c': /* toggle caseless mode */ case ctrl('C'): if (caseless == NO) { caseless = YES; } else { caseless = NO; } egrepcaseless(caseless); break; case 'r': /* rebuild database cscope style */ case ctrl('R'): freefilelist(); makefilelist(); /* FALLTHROUGH */ case 'R': /* rebuild database samuel style */ rebuild(); (void) putchar('\n'); break; case 'C': /* clear file names */ freefilelist(); (void) putchar('\n'); break; case 'F': /* add a file name */ (void) strcpy(path, buf + 1); if (infilelist(path) == NO && vpaccess(path, READ) == 0) { addsrcfile(path); } (void) putchar('\n'); break; case 'P': /* print the path to the files */ if (prependpath != NULL) { (void) puts(prependpath); } else { (void) puts(currentdir); } break; case 'q': /* quit */ case ctrl('D'): case ctrl('Z'): myexit(0); default: (void) fprintf(stderr, "cscope: unknown command '%s'\n", buf); break; } } /* NOTREACHED */ } /* pause before clearing the screen if there have been error messages */ if (errorsfound == YES) { errorsfound = NO; askforreturn(); } (void) signal(SIGINT, SIG_IGN); /* ignore interrupts */ (void) signal(SIGPIPE, SIG_IGN); /* | command can cause pipe signal */ /* initialize the curses display package */ (void) initscr(); /* initialize the screen */ setfield(); /* set the initial cursor position */ entercurses(); (void) keypad(stdscr, TRUE); /* enable the keypad */ dispinit(); /* initialize display parameters */ putmsg(""); /* clear any build progress message */ display(); /* display the version number and input fields */ /* do any optional search */ if (*pattern != '\0') { atfield(); /* move to the input field */ (void) command(ctrl('A')); /* search */ display(); /* update the display */ } else if (reflines != NULL) { /* read any symbol reference lines file */ (void) readrefs(reflines); display(); /* update the display */ } for (;;) { if (noacttime) { (void) alarm(noacttime); } atfield(); /* move to the input field */ /* exit if the quit command is entered */ if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) { break; } /* execute the commmand, updating the display if necessary */ if (command(c) == YES) { display(); } } /* cleanup and exit */ myexit(0); /* NOTREACHED */ return (0); }
int grab_cisco(intf_t *ip) { int style; int next_state; int state = NOISE; int skip = 0; int i; int namelen; char *pw_prompt = NULL; char *w; int fd; int fd2; int nval = 0; cisco_t *cp = ip->cp; intf_t tmp; int len_prompt = strlen(cp->prompt); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { fprintf(stderr, "grab_cisco(%s:%s):\n", cp->host, ip->interface); } #endif tmp.bandwidth = tmp.rate_in = tmp.rate_out = -1; tmp.bytes_in = tmp.bytes_out = tmp.bytes_out_bcast = -1; if (cp->fin == NULL) { fd = conn_cisco(cp); if (fd < 0) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "grab_cisco(%s:%s): connect failed: %s\n", cp->host, ip->interface, netstrerror()); #endif return -1; } else { cp->fin = fdopen (fd, "r"); if ((fd2 = dup(fd)) < 0) { perror("dup"); exit(1); } cp->fout = fdopen (fd2, "w"); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { fprintf(stderr, "grab_cisco(%s:%s): connected fin=%d fout=%d", cp->host, ip->interface, fileno(cp->fin), fileno(cp->fout)); if (cp->username != NULL) fprintf(stderr, " username=%s", cp->username); else fprintf(stderr, " NO username"); if (cp->passwd != NULL) fprintf(stderr, " passwd=%s", cp->passwd); else fprintf(stderr, " NO passwd"); fputc('\n', stderr); } #endif if (cp->username != NULL) { /* * Username stuff ... */ if (dousername(cp, &pw_prompt) == 0) { fclose(cp->fin); fclose(cp->fout); cp->fin = cp->fout = NULL; return -1; } } if (cp->passwd != NULL) { /* * User-level password stuff ... */ if (dopasswd(cp, pw_prompt) == 0) { fclose(cp->fin); fclose(cp->fout); cp->fin = cp->fout = NULL; return -1; } } #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send: \n"); } #endif fprintf(cp->fout, "\n"); fflush(cp->fout); } #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send: terminal length 0\n"); } #endif fprintf(cp->fout, "terminal length 0\n"); fflush(cp->fout); } timeout = 0; signal(SIGALRM, onalarm); /* * Choice of timeout here is somewhat arbitrary ... for a long * time this was 5 (seconds), but then testing with an entry * level Model 800 ADSL router revealed that up to 20 seconds * was required to generate the expected output. */ alarm(20); style = SHOW_INT; /* default Cisco command */ if (ip->interface[0] == 's' && strchr(ip->interface, '.') != NULL) { /* * Frame-relay PVC on subinterface for s2/3.7 style interface name */ style = SHOW_FRAME; if (ip->bandwidth == -2) { /* * one-trip initialzation ... need show int s2/3.7 to * get bandwidth */ ip->bandwidth = get_fr_bw(cp, &ip->interface[1]); } tmp.bandwidth = ip->bandwidth; if (tmp.bandwidth != -1) nval++; } if (style == SHOW_FRAME) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send: show frame pvc int s%s\n", &ip->interface[1]); } #endif fprintf(cp->fout, "show frame pvc int s%s\n", &ip->interface[1]); next_state = BYTES_IN; } else { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send: show int %s\n", ip->interface); } #endif fprintf(cp->fout, "show int %s\n", ip->interface); } fflush(cp->fout); state = NOISE; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) { fprintf(stderr, "Parse:"); fflush(stderr); } #endif while (state != DONE) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) { fprintf(stderr, "[%s] ", statestr[state+1]); fflush(stderr); } #endif w = mygetwd(cp->fin, cp->prompt); if (w == NULL || timeout) { /* * End of File (telenet timeout?) * ... mark as closed, and try again at next request */ #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "grab_cisco(%s:%s): forced disconnect fin=%d\n", cp->host, ip->interface, fileno(cp->fin)); #endif fclose(cp->fin); fclose(cp->fout); cp->fin = cp->fout = NULL; alarm(0); return -1; } switch (state) { case NOISE: for (i = 0; i < num_intf_tab; i++) { namelen = strlen(intf_tab[i].name); if (strncmp(w, intf_tab[i].name, namelen) == 0) { state = IN_REPORT; break; } } break; case IN_REPORT: if (strcmp(w, "Description:") == 0) skip2eol(cp->fin); if (strlen(w) >= len_prompt && strncmp(&w[strlen(w)-len_prompt], cp->prompt, len_prompt) == 0) state = DONE; else if (style == SHOW_INT) { if (strcmp(w, "minute") == 0 || strcmp(w, "second") == 0) state = RATE; else if (strcmp(w, "input,") == 0) state = BYTES_IN; else if (strcmp(w, "output,") == 0) state = BYTES_OUT; else if (strcmp(w, "BW") == 0) state = BW; } else if (style == SHOW_FRAME) { if (strcmp(w, "bytes") == 0) { if (next_state == BYTES_IN) { state = BYTES_IN; next_state = BYTES_OUT; } else if (next_state == BYTES_OUT) { state = BYTES_OUT; next_state = BYTES_OUT_BCAST; } else if (next_state == BYTES_OUT_BCAST) { state = BYTES_OUT_BCAST; next_state = IN_REPORT; } else state = next_state; } } break; case RATE: if (strcmp(w, "input") == 0) { skip = 1; state = RATE_IN; } else if (strcmp(w, "output") == 0) { skip = 1; state = RATE_OUT; } break; case RATE_IN: if (skip-- == 0) { tmp.rate_in = atol(w) / 8; nval++; state = IN_REPORT; } break; case RATE_OUT: if (skip-- == 0) { tmp.rate_out = atol(w) / 8; nval++; state = IN_REPORT; } break; case BYTES_IN: tmp.bytes_in = strtoull(w, NULL, 10); nval++; state = IN_REPORT; break; case BYTES_OUT: tmp.bytes_out = strtoull(w, NULL, 10); nval++; state = IN_REPORT; break; case BYTES_OUT_BCAST: tmp.bytes_out_bcast = strtoull(w, NULL, 10); nval++; state = IN_REPORT; break; case BW: sscanf(w, "%d", &tmp.bandwidth); tmp.bandwidth *= 1000; /* Kbit -> bytes/sec */ tmp.bandwidth /= 8; nval++; state = IN_REPORT; break; } } alarm(0); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { fprintf(stderr, "Extracted %d values ...\n", nval); if (tmp.bandwidth != 0xffffffff) fprintf(stderr, "bandwidth: %d bytes/sec\n", tmp.bandwidth); else fprintf(stderr, "bandwidth: ? bytes/sec\n"); fprintf(stderr, "recent rate (bytes/sec):"); if (tmp.rate_in != 0xffffffff) fprintf(stderr, " %d in", tmp.rate_in); else fprintf(stderr, " ? in"); if (tmp.rate_out != 0xffffffff) fprintf(stderr, " %d out", tmp.rate_out); else fprintf(stderr, " ? out"); fprintf(stderr, "\ntotal bytes:"); if (tmp.bytes_in != 0xffffffffffffffffLL) fprintf(stderr, " %llu in", (unsigned long long)tmp.bytes_in); else fprintf(stderr, " ? in"); if (tmp.bytes_out != 0xffffffffffffffffLL) fprintf(stderr, " %llu out", (unsigned long long)tmp.bytes_out); else fprintf(stderr, " ? out"); if (tmp.bytes_out_bcast != 0xffffffffffffffffLL) fprintf(stderr, " %llu out_bcast", (unsigned long long)tmp.bytes_out_bcast); else fprintf(stderr, " ? out_bcast"); fprintf(stderr, "\n\n"); } #endif /* pretend this is atomic */ ip->bandwidth = tmp.bandwidth; ip->rate_in = tmp.rate_in; ip->rate_out = tmp.rate_out; ip->bytes_in = tmp.bytes_in; ip->bytes_out = tmp.bytes_out; ip->bytes_out_bcast = tmp.bytes_out_bcast; return nval; }
static int get_fr_bw(cisco_t *cp, char *interface) { int state = NOISE; int bandwidth = -1; char *w; int len_prompt = strlen(cp->prompt); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "Send: s%s\n", interface); } #endif fprintf(cp->fout, "show int s%s\n", interface); fflush(cp->fout); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "BW Parse:"); #endif while (state != DONE) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "[%s] ", statestr[state+1]); #endif w = mygetwd(cp->fin, cp->prompt); if (w == NULL || timeout) { /* * End of File (telenet timeout?) */ alarm(0); return -1; } switch (state) { case NOISE: if (strncmp(w, "Serial", 6) == 0 && strcmp(&w[6], interface) == 0) state = IN_REPORT; break; case IN_REPORT: if (strcmp(w, "Description:") == 0) skip2eol(cp->fin); else if (strlen(w) >= len_prompt && strncmp(&w[strlen(w)-len_prompt], cp->prompt, len_prompt) == 0) state = DONE; else if (strcmp(w, "BW") == 0) state = BW; break; case BW: sscanf(w, "%d", &bandwidth); bandwidth *= 1000; /* Kbit -> bytes/sec */ bandwidth /= 8; state = IN_REPORT; break; } } alarm(0); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { fprintf(stderr, "Extracted bandwidth: %d bytes/sec\n", bandwidth); } #endif return bandwidth; }