struct netmap_if * get_if() { void *mmap_addr; uint32_t off; char *arg; /* defaults */ off = curr_nmr.nr_offset; mmap_addr = last_mmap_addr; /* first arg: if offset */ arg = nextarg(); if (!arg) { goto doit; } off = strtoul(arg, NULL, 0); /* second arg: mmap address */ arg = nextarg(); if (!arg) { goto doit; } mmap_addr = (void*)strtoul(arg, NULL, 0); doit: return NETMAP_IF(mmap_addr, off); }
void do_mmap() { size_t memsize; off_t off = 0; int fd; char *arg; arg = nextarg(); if (!arg) { memsize = last_memsize; fd = last_fd; goto doit; } memsize = atoi(arg); arg = nextarg(); if (!arg) { fd = last_fd; goto doit; } fd = atoi(arg); arg = nextarg(); if (arg) { off = (off_t)atol(arg); } doit: last_mmap_addr = mmap(0, memsize, PROT_WRITE | PROT_READ, MAP_SHARED, fd, off); if (last_access_addr == NULL) last_access_addr = last_mmap_addr; output_err(last_mmap_addr == MAP_FAILED ? -1 : 0, "mmap(0, %zu, PROT_WRITE|PROT_READ, MAP_SHARED, %d, %jd)=%p", memsize, fd, (intmax_t)off, last_mmap_addr); }
void do_buf() { struct netmap_ring *ring; long int buf_idx, len; char *buf, *arg; /* defaults */ buf_idx = 2; len = 64; arg = nextarg(); if (!arg) goto doit; buf_idx = strtoll(arg, NULL, 0); arg = nextarg(); if (!arg) goto doit; len = strtoll(arg, NULL, 0); doit: ring = get_ring(); buf = NETMAP_BUF(ring, buf_idx); dump_payload(buf, len); }
void do_regif() { int ret; char *arg, *name; int fd = last_fd; name = nextarg(); if (!name) { name = nmr_name; goto doit; } bzero(&curr_nmr, sizeof(curr_nmr)); curr_nmr.nr_version = NETMAP_API; curr_nmr.nr_flags = NR_REG_ALL_NIC; strncpy(curr_nmr.nr_name, name, sizeof(curr_nmr.nr_name)); arg = nextarg(); if (!arg) { goto doit; } fd = atoi(arg); arg = nextarg(); parse_nmr_config(arg, &curr_nmr); doit: ret = ioctl(fd, NIOCREGIF, &curr_nmr); last_memsize = curr_nmr.nr_memsize; output_err(ret, "ioctl(%d, NIOCREGIF) for %s: region %d memsize=%zu", fd, name, curr_nmr.nr_arg2, last_memsize); }
static void process(void) { struct iblok *ip; char *arg; long linecnt = 0; ip = ib_alloc(0, 0); if (iflag) { iflen = strlen(iflag); while ((arg = nextarg(ip, &linecnt)) != NULL) { if (eflag && *eflag && strcmp(arg, eflag) == 0) break; insert(arg); } } else { do { arg = nextarg(ip, &linecnt); if (arg && eflag && *eflag && strcmp(arg, eflag) == 0) arg = NULL; addarg(arg, lflag && lflag == linecnt ? linecnt = 0, 1 : 0); } while (arg != NULL); } }
void do_getinfo() { int ret; char *arg, *name; int fd; bzero(&curr_nmr, sizeof(curr_nmr)); curr_nmr.nr_version = NETMAP_API; name = nextarg(); if (name) { strncpy(curr_nmr.nr_name, name, sizeof(curr_nmr.nr_name)); } else { name = "any"; } arg = nextarg(); if (!arg) { fd = last_fd; goto doit; } fd = atoi(arg); arg = nextarg(); parse_nmr_config(arg, &curr_nmr); doit: ret = ioctl(fd, NIOCGINFO, &curr_nmr); last_memsize = curr_nmr.nr_memsize; output_err(ret, "ioctl(%d, NIOCGINFO) for %s: region %d memsize=%zu", fd, name, curr_nmr.nr_arg2, last_memsize); }
/* xappend - built-in function append */ LVAL xappend(void) { LVAL list,last=NULL,next,val; /* protect some pointers */ xlsave1(val); /* initialize */ val = NIL; /* append each argument */ if (moreargs()) { while (xlargc > 1) { /* append each element of this list to the result list */ for (list = nextarg(); consp(list); list = cdr(list)) { next = consa(car(list)); if (val) rplacd(last,next); else val = next; last = next; } } /* handle the last argument */ if (val) rplacd(last,nextarg()); else val = nextarg(); } /* restore the stack */ xlpop(); /* return the list */ return (val); }
/* xnconc - destructively append lists */ LVAL xnconc(void) { LVAL next,last=NULL,val; /* initialize */ val = NIL; /* concatenate each argument */ if (moreargs()) { while (xlargc > 1) { /* ignore everything except lists */ if ((next = nextarg()) && consp(next)) { /* concatenate this list to the result list */ if (val) rplacd(last,next); else val = next; /* find the end of the list */ while (consp(cdr(next))) next = cdr(next); last = next; } } /* handle the last argument */ if (val) rplacd(last,nextarg()); else val = nextarg(); } /* return the list */ return (val); }
void do_echo() { char *arg; for (arg = nextarg(); arg; arg = nextarg()) { printf("%s\n", arg); } }
static int tftpio(int dir, void * pio) { ip_addr fhost; char *dfile; /* source & dest file names */ char *sfile; char *hostname = NULL; char *msg; int e; GEN_IO io = (GEN_IO)pio; /* extract args from command buffer */ if (io != (GEN_IO)NULL) hostname = nextarg(io->inbuf); if ((hostname == (char *)NULL) || (*hostname == '\0')) { ns_printf(pio, usage, (dir==PUT) ? "put" : "get"); return -1; } sfile = nextarg(hostname); *(sfile-1) = '\0'; /* null terminate hostname */ if (*sfile == '\0') { ns_printf(pio, usage, (dir==PUT) ? "put" : "get"); return -1; } dfile = nextarg(sfile); if (*dfile != '\0') /* if dfile was specified... */ *(dfile-1) = '\0'; /* ...null terminate sfile */ else /* if not specified default to sfile */ dfile = sfile; msg = parse_ipad(&fhost, (unsigned *)&e, hostname); if (msg) { ns_printf(pio,"TFTP host address error: %s\n", msg); return -1; } /* if we're getting the file, swap src,dest file names */ if (dir == GET) { msg = sfile; sfile = dfile; dfile = msg; } last_pio = pio; /* save pio for callback */ /* call tftp client code to create the session and start the transfer */ #ifdef TFTP_CLIENT msg = tftpuse(fhost, sfile, dfile, dir, OCTET, tfc_done); #endif if (msg) ns_printf(pio, "TFTP client error: %s\n", msg); return 0; }
int linkstats(void * pio) { int iface = 1; char * cp; cp = nextarg(((GEN_IO)pio)->inbuf); if (*cp) { iface = atoi(cp); if (iface < 1 || iface > (int)ifNumber) { ns_printf(pio,"interface number must be 1 to %d.\n", ifNumber); return -1; } } iface--; if (nets[iface]->n_stats) nets[iface]->n_stats(pio,iface); /* actually call the stats */ else ns_printf(pio,"no stats routine for interface %d\n", iface+1); return 0; }
int nv_add_entry(void * pio, int index, struct nv_sectioninfo *sec) { char * cp; int err; if ( index == NOT_A_SECTION ) { ns_printf(pio,"Could not find info about table. Can't process cmd.\n"); return -1; } cp = nextarg( ((GEN_IO)pio)->inbuf ); /* see if user put parm on cmd line */ if (!*cp) { if ( sec[index].usage_func ) sec[index].usage_func(pio); return -1; } err=sec[index].parse_func(cp); if ( err == SUCCESS ) return SUCCESS; else { ns_printf(pio,"Error #%d\n",err); return -1; } }
int upnp_restart(void * pio) { char * cp; NET ifp; int iface; cp = nextarg( ((GEN_IO)pio)->inbuf ); if(!*cp) { ns_printf(pio, "please enter iface to restart UPnP\n"); return -1; } ifp = if_netbytext(pio, cp); if(ifp == NULL) /* error parsing iface name/number text? */ return -1; iface = if_netnumber(ifp); /* skip the DHCP step and go right to autoIP */ upnp[iface].state = UPNP_START; upnp[iface].ip_method = eIP_METHOD_AUTO_FIXED; autoIPs[iface].state = AUTOIP_START; autoIPs[iface].response_timer = 0; autoIPs[iface].arp_attempts = 0; ns_printf(pio, "(re)started UPnP in iface %s\n", ifp->name); return 0; }
/* * Get output filename */ void openout() { char filen2[FILENAME_LEN+1]; FILE *fp; clear() ; /* erase line */ output = 0 ; /* start with none */ if ( nextarg(filenum, filen2, FILENAME_LEN) == NULL_CHAR ) return ; /* For weird reasons, output is opened before input, so have to check * input exists beforehand.. */ if ( ( fp=fopen(filen2,"r")) == NULL ) { fprintf(stderr,"Cannot open source file: %s\n",filen2); exit(1); } fclose(fp); /* Close it again... */ /* copy file name to string */ strcpy(Filename,filen2) ; strcpy(Filenorig,filen2); changesuffix(filen2,".asm"); /* Change appendix to .asm */ if ( (output=fopen(filen2, "w")) == NULL && (!eof) ) { fprintf(stderr,"Cannot open output file: %s\n",line); exit(1); } clear() ; /* erase line */ }
/* xstrcat - concatenate a bunch of strings */ LVAL xstrcat(void) { LVAL *saveargv,tmp,val; unsigned char *str; int saveargc,len; /* save the argument list */ saveargv = xlargv; saveargc = xlargc; /* find the length of the new string */ for (len = 0; moreargs(); ) { tmp = xlgastring(); len += (int)getslength(tmp) - 1; } /* create the result string */ val = new_string(len+1); str = getstring(val); /* restore the argument list */ xlargv = saveargv; xlargc = saveargc; /* combine the strings */ for (*str = '\0'; moreargs(); ) { tmp = nextarg(); strcat((char *) str, (char *) getstring(tmp)); } /* return the new string */ return (val); }
int nv_del_entry(void * pio, int index, struct nv_sectioninfo *sec) { GEN_STRUCT entry; char * cp; if ( index == NOT_A_SECTION ) { ns_printf(pio,"Could not find info about table. Can't process cmd.\n"); return -1; } cp = nextarg( ((GEN_IO)pio)->inbuf ); /* see if user put parm on cmd line */ if (!*cp) { if ( sec[index].usage_func ) sec[index].usage_func(pio); return -1; } entry = niche_list_getat((NICHELIST)sec[index].list,atoi(cp)); if ( entry ) { niche_del((NICHELIST)sec[index].list,entry); return SUCCESS; } else return -1; }
int upnp_base(void * pio) { char * cp; u_long newbase; u_long oldrange; unsigned mask; cp = nextarg( ((GEN_IO)pio)->inbuf ); if(!*cp) { ns_printf(pio, "please enter IP address for new base\n"); return -1; } cp = parse_ipad(&newbase, &mask, cp); if(cp) { ns_printf(pio, "Bad IP address: %s\n", cp); return -1; } oldrange = dAUTO_IP_RANGE; dBASE_AUTO_IP_ADDRESS = htonl(newbase); /* store in local endian */ dMAX_AUTO_IP_ADDRESS = htonl(newbase + oldrange); ns_printf(pio, "Changed base of Auto-IP address pool to %u.%u.%u.%u\n", PUSH_IPADDR(newbase) ); return 0; }
void do_poll() { /* timeout fd fd... */ nfds_t nfds = 0, allocated_fds = 10, i; struct pollfd *fds; int timeout = 500; /* 1/2 second */ char *arg; int ret; arg = nextarg(); if (arg) timeout = atoi(arg); fds = malloc(allocated_fds * sizeof(struct pollfd)); if (fds == NULL) { output_err(-1, "out of memory"); return; } while ( (arg = nextarg()) ) { if (nfds >= allocated_fds) { struct pollfd *new_fds; allocated_fds *= 2; new_fds = realloc(fds, allocated_fds * sizeof(struct pollfd)); if (new_fds == NULL) { free(fds); output_err(-1, "out of memory"); return; } fds = new_fds; } fds[nfds].fd = atoi(arg); fds[nfds].events = POLLIN; nfds++; } ret = poll(fds, nfds, timeout); for (i = 0; i < nfds; i++) { output("poll(%d)=%s%s%s%s%s", fds[i].fd, (fds[i].revents & POLLIN) ? "IN " : "- ", (fds[i].revents & POLLOUT)? "OUT " : "- ", (fds[i].revents & POLLERR)? "ERR " : "- ", (fds[i].revents & POLLHUP)? "HUP " : "- ", (fds[i].revents & POLLNVAL)?"NVAL" : "-"); } output_err(ret, "poll(...)=%d", ret); free(fds); }
NET if_getbypio(void * pio) { char * name; name = nextarg(((GEN_IO)pio)->inbuf); return(if_getbyname(name)); }
void do_rxsync() { char *arg = nextarg(); int fd = arg ? atoi(arg) : last_fd; int ret = ioctl(fd, NIOCRXSYNC, NULL); output_err(ret, "ioctl(%d, NIOCRXSYNC)=%d", fd, ret); }
void do_close() { int ret, fd; char *arg = nextarg(); fd = arg ? atoi(arg) : last_fd; ret = close(fd); output_err(ret, "close(%d)=%d", fd, ret); }
int ftp_move(void * pio, int direction) { char * sfile=NULL; /* name of source file to put/get */ char * dfile; /* optional name */ GEN_IO io= (GEN_IO) pio ; unsigned long int transfer_type; if ( ftp_get_con(pio) == NULL ) { ns_printf(pio,"Open FTP session first\n"); return -1; } /* extract args from command buffer */ if ( io != NULL ) sfile = nextarg(io->inbuf); /* name of source file */ if (!sfile || !*sfile) { ns_printf(pio,"usage: ftp put|get filename [destname]\n"); return -1; } dfile = nextarg(sfile); if (dfile && *dfile) /* optional dest name given? */ *(dfile-1) = 0; /* null terminate source file name */ else dfile = sfile; /* use foreign name for both */ if (direction) transfer_type = FTPC_GET_TRANSFER; else transfer_type = FTPC_PUT_TRANSFER; #ifdef OS_PREEMPTIVE ftpc_send_msg4 (FTPC_CNTRL_MOVE_FILE, (u_long) pio, (u_char *) &transfer_type, sizeof (transfer_type), (u_char *) sfile, (strlen (sfile) + 1), (u_char *) dfile, (strlen (dfile) + 1)); #else ftpc_process_move (pio, transfer_type, sfile, dfile); #endif return 0; }
static VALUE *eval2(void) { VALUE *l, *r; int op; arith_t val; l = eval3(); while (1) { op = nextarg("<"); if (!op) { op = nextarg("<="); if (!op) { op = nextarg("="); if (!op) { op = nextarg("=="); if (!op) { op = nextarg("!="); if (!op) { op = nextarg(">="); if (!op) { op = nextarg(">"); if (!op) return l; }}}}}} G.args++; r = eval3(); toarith(l); toarith(r); val = cmp_common(l, r, op); freev(l); freev(r); l = int_value(val); } }
static int apopcmd(char *arg) { char *resp; resp = nextarg(arg); if(setuser(arg) < 0) return -1; return dologin(resp); }
val_t eic_getenv(void) { val_t v; v.p.sp = v.p.p = getenv(nextarg(getargs(),ptr_t).p); if(v.p.p) setEp( v.p, strlen(v.p.p) + 1 ); else v.p.ep = v.p.p; return v; }
void do_expr() { unsigned long stack[11]; int top = 10; char *arg; int err = 0; stack[10] = ULONG_MAX; while ( (arg = nextarg()) ) { errno = 0; char *rest; unsigned long n = strtoul(arg, &rest, 0); if (!errno && rest != arg) { if (top <= 0) { err = -1; break; } stack[--top] = n; continue; } if (top <= 8) { unsigned long n1 = stack[top++]; unsigned long n2 = stack[top++]; unsigned long r = 0; switch (arg[0]) { case '+': r = n1 + n2; break; case '-': r = n1 - n2; break; case '*': r = n1 * n2; break; case '/': if (n2) r = n1 / n2; else { errno = EDOM; err = -1; } break; default: err = -1; break; } stack[--top] = r; continue; } err = -1; break; } output_err(err, "expr=%lu", stack[top]); }
int settrapsize(void * pio) { char * cp; cp = nextarg(((GEN_IO)pio)->inbuf); memtrapsize = atoi(cp); ns_printf(pio,"malloc trap size set to %d\n", memtrapsize); return 0; }
/* * get a macro line argument * * char *tok; buffer to place argument */ int macarg(char *tok) { int savcle; /* buffer to store original clexec */ int status; savcle = clexec; /* save execution mode */ clexec = TRUE; /* get the argument */ status = nextarg("", tok, NSTRING, ctoec('\n')); clexec = savcle; /* restore execution mode */ return status; }
static VALUE *eval7(void) { VALUE *v; if (!*G.args) bb_error_msg_and_die("syntax error"); if (nextarg("(")) { G.args++; v = eval(); if (!nextarg(")")) bb_error_msg_and_die("syntax error"); G.args++; return v; } if (nextarg(")")) bb_error_msg_and_die("syntax error"); return str_value(*G.args++); }
static VALUE *eval3(void) { VALUE *l, *r; int op; arith_t val; l = eval4(); while (1) { op = nextarg("+"); if (!op) { op = nextarg("-"); if (!op) return l; } G.args++; r = eval4(); val = arithmetic_common(l, r, op); freev(l); freev(r); l = int_value(val); } }