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; }
int get_nvdnssrv(struct nvparm_info * nvinfo_ptr, char * parm) { char * cp; unsigned subnet; /* dummy for passing to parse_ipad() */ int svr_num; svr_num = atoi(parm); if (svr_num < 1 || svr_num > MAXDNSSERVERS) { printf("Error in line %d; DNS server number must be 1-%d\n", line, MAXDNSSERVERS); return -1; } parm += 4; /* point to IP address field */ cp = parse_ipad((ip_addr *)nvinfo_ptr->nvdata + (svr_num - 1), \ &subnet, parm); if (cp) { printf(IPerr, line, cp); return -1; } return 0; }
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; }
/* FUNCTION: get_nvipdec() * * get_nvipdec - get Internet ip address * * * PARAM1: char * parm * * RETURNS: */ int get_nvipdec(struct nvparm_info * nvinfo_ptr, char * parm) { char * cp; unsigned subnet; /* dummy for passing to parse_ipad() */ cp = parse_ipad((ip_addr *)(nvinfo_ptr->nvdata), &subnet, parm); if (cp) { printf(IPerr, line, cp); return -1; } return 0; }
u_long inet_addr(char FAR * str) { u_long ipaddr; unsigned bits ; /* parse_ipad expects a "char and we are passing "char far Hence * we need to make the conversion. Usually this function will be * used for debugging, so I think we can bear the STRCPY overhead. */ static char nearBuf[30]; strcpy((char FAR *)nearBuf,str); if ( parse_ipad(&ipaddr,&bits,nearBuf) == NULL ) { return ipaddr ; } else { return (u_long)NULL ; } }
/* * FUNCTION: bsd_inet_addr() * * Parses a dotted-decimal Internet address * * PARAM1: cp; IN - dotted-decimal Internet address * RETURNS: The parsed Internet address, in network order */ BSD_IN_ADDR_T bsd_inet_addr(char * cp) { BSD_IN_ADDR_T ret; ip_addr addr; unsigned sbits; char * err; err = parse_ipad(&addr, &sbits, cp); if (err == NULL) { /* return the address as success */ ret = addr; } else { /* return failure */ ret = 0; } return ret; }
/* * FUNCTION: bsd_inet_aton() * * Parses a dotted-decimal Internet address * * PARAM1: cp; IN - dotted-decimal Internet address * PARAM2: pin; OUT - pointer to buffer where parsed address is to be * returned * RETURNS: 1 if parsing was successful, * 0 if parsing failed. */ int bsd_inet_aton(char * cp, struct in_addr * pin) { ip_addr addr; unsigned sbits; char * err; err = parse_ipad(&addr, &sbits, cp); if (err == NULL) { /* if the caller gave us a buffer, copy the returned address * into it */ if (pin != NULL) pin->s_addr = addr; /* return success */ return 1; } else { /* return failure */ return 0; } }
int ftp_open(void * pio) { char * hostname=NULL; char * user; char * passwd; char * msg; u_long domain; /* AF_INET or AF_INET6 */ u_char server[16]; /* dual mode IP address */ u_long x; GEN_IO io= (GEN_IO) pio ; FC_MENULOG(); /* extract args from command buffer */ if ( io != NULL ) hostname = nextarg(io->inbuf); if (*hostname == 0) { ns_printf(pio,ousage); return -1; } user = nextarg(hostname); *(user-1) = 0; /* null terminate hostname */ if (*user == 0) { ns_printf(pio,ousage); return -1; } passwd = nextarg(user); if (*passwd != 0) /* if passwrod was specd... */ *(passwd-1) = 0; /* ...null terminate user */ #ifdef IP_V6 /* Code for both dual-mode and IP_V6 only: * If there are colons in the host name, then assume * it's IPv6, else set domain for IP_V4 */ if(strchr(hostname, ':')) domain = AF_INET6; else domain = AF_INET; if(inet_pton(domain, hostname, &server) !=0) msg = pton_error; else msg = NULL; #else /* IP_V4 only */ { unsigned int my_bits; /* tmp, for subnet bits */ msg = parse_ipad((ip_addr*)&server, &my_bits, hostname); domain = AF_INET; } #endif /* IP_V4 */ if (msg) { ns_printf(pio,"FTP host address error: %s\n", msg); return -1; } /* Supports only one client connection for each PIO */ if ( ftp_get_con(pio) != NULL ) { ns_printf(pio,"ftp session already open\n"); return -1; } x = strlen (passwd) + 1; #ifdef OS_PREEMPTIVE ftpc_send_msg5 (FTPC_CNTRL_START_SESS, (u_long) pio, server, sizeof (server), (u_char *) &domain, sizeof (domain), (u_char *) user, (strlen (user) + 1), (u_char *) passwd, (strlen (passwd) + 1)); #else ftpc_process_open (pio, server, domain, user, passwd); #endif return 0; }
int inet_pton(int af, const char * src, void * dst) { /* * Altera modification: * Conditionally declare variables to remove build warning */ #if defined(IP_V6) const char * cp; /* char after previous colon */ unshort * dest; /* word pointer to dst */ int colons; /* number of colons in src */ int words; /* count of words written to dest */ #endif #if defined(IP_V4) || defined(MINI_IP) /* RFC 2133 wants us to support both types of address */ if(af == AF_INET) /* wants a v4 address */ { u_long ip4addr; unsigned sbits; char * err; err = parse_ipad(&ip4addr, &sbits, (char *) src); if(err == NULL) { /* copy the parsed address into caller's buffer, and * return success */ MEMCPY(dst, &ip4addr, sizeof (u_long)); return 0; } else { /* return failure */ pton_error = "IPv4 address parse failure"; return 1; } } #endif /* IP_V4 */ #ifdef IP_V6 if(af != AF_INET6) { pton_error = "bad domain"; return -1; } /* count the number of colons in the address */ cp = src; colons = 0; while(*cp) if(*cp++ == ':') colons++; if(colons < 2 || colons > 7) { pton_error = "must have 2-7 colons"; return 1; } /* loop through address text, parseing 16-bit chunks */ cp = src; dest = dst; words = 0; if(*cp == ':') /* leading colon has implied zero, e.g. "::1" */ { *dest++ = 0; words++; cp++; /* bump past leading colon, eg ":!" */ } while(*cp > ' ') { if(words >= 8) { /* !!!??? */ dprintf("*** inet_pton: logic error?\n"); dtrap(); /* logic error? */ pton_error = "internal"; return 1; } if(*cp == ':') /* found a double-colon? */ { int i; for(i = (8 - colons); i > 0; i--) { *dest++ = 0; /* add zeros to dest address */ words++; /* count total words */ } cp++; /* bump past double colon */ if(*cp <= ' ') /* last colon was last char? */ { *dest++ = 0; /* add one final zero */ words++; /* count total words */ } } else { unshort wordval; wordval = htons(atoh(cp)); /* get next 16 bit word */ if((wordval == 0) && (*cp != '0')) /* check format */ { pton_error = "must be hex numbers or colons"; return 1; } *dest++ = wordval; words++; /* count total words set in dest */ cp = strchr((char *)cp, ':'); /* find next colon */ if(cp) /* bump past colon */ cp++; else /* no more colons? */ break; /* done with parsing */ } } if(words != 8) { pton_error = "too short - missing colon?"; return 1; } #endif /* IP_V6 */ return 0; }
int if_config(void * pio) { char * name; char * addr = NULL; char * mask = NULL; unsigned bits; NET ifp; struct niconfig_0 cfg; name = nextarg(((GEN_IO)pio)->inbuf); if (*name) { addr = nextarg(name); } if (addr && *addr) { mask = nextarg(addr); *(addr-1) = 0; /* null terminate name text */ if (mask && *mask) { *(mask-1) = 0; /* null terminate addr text */ } } if (!(*name) || !(*addr)) { ns_printf(pio, "specify if's name, ip_addr, [mask]\n"); return -1; } for (ifp = (NET)(netlist.q_head); ifp; ifp = ifp->n_next) if (strncmp(ifp->name, name, strlen(ifp->name)) == 0) break; if (!ifp) { ns_printf(pio, "Can't find iface %s\n", name); return -1; } name = parse_ipad(&(cfg.n_ipaddr), &bits, addr); if (name) { ns_printf(pio, "IP address parse error: %s\n", name); return -1; } if (*mask) { name = parse_ipad(&(cfg.snmask), &bits, mask); if (name) { ns_printf(pio, "subnet mask parse error: %s\n", name); return -1; } } else { cfg.snmask = 0L; while (bits--) cfg.snmask = (cfg.snmask << 1) | 1; } ni_set_config(ifp, &cfg); return 0; }
int get_nvipdec_nets(struct nvparm_info * nvinfo_ptr, char * parm) { char * cp; unsigned subnet; /* dummy for passing to parse_ipad() */ switch(nvinfo_ptr->nvtype) { case NVIPDEC_NETS: cp = parse_ipad((ip_addr *)&(((struct ifinfo *)(nvinfo_ptr->nvdata) + \ netidx)->ipaddr), &subnet, parm); break; case NVSBDEC_NETS: cp = parse_ipad((ip_addr *)&(((struct ifinfo *)(nvinfo_ptr->nvdata) + \ netidx)->subnet), &subnet, parm); break; case NVGTDEC_NETS: cp = parse_ipad((ip_addr *)&(((struct ifinfo *)(nvinfo_ptr->nvdata) + \ netidx)->gateway), &subnet, parm); break; #if defined (IP_MULTICAST) && (defined (IGMP_V1) || defined (IGMP_V2)) case NVCHAR_NETS: { struct ifinfo * ifip; u_char cval; ifip = ((struct ifinfo *) (nvinfo_ptr->nvdata)) + netidx; /* extract the IGMP operating mode (1 for v1, 2 for v2) from * configuration file */ cval = (u_char) atoi (parm); switch (cval) { case IGMP_MODE_V1: #ifdef IGMP_V1 cp = 0; ifip->igmp_oper_mode = cval; #else /* return an error if the configuration file specifies * support for IGMPv1, but the protocol is not compiled * into the build. */ cp = igmp_bld_err_str; #endif break; case IGMP_MODE_V2: #ifdef IGMP_V2 cp = 0; ifip->igmp_oper_mode = cval; #else /* return an error if the configuration file specifies * support for IGMPv2, but the protocol is not compiled * into the build. */ cp = igmp_bld_err_str; #endif break; default: /* indicate failure if mode is not one of the two expected * values (1 for IGMPv1, 2 for IGMPv2) */ cp = igmp_bad_prot_err_str; break; } /* end SWITCH */ if (!cp) printf ("interface: %s, cval: %u, netidx: %u\n", ifip->name, cval, netidx); } break; #endif /* IP_MULTICAST and (IGMPv1 or IGMPv2) */ default: /* Bad programming ? */ dprintf("get_nv_value: unknown nvtype in nvparm_format %d\n", \ nvinfo_ptr->nvtype ); return -1; } if (cp) { printf(IPerr, line, cp); return -1; } return 0; }
int in_reshost(char * host, /* IN - textual IP address or host name */ ip_addr * address, /* OUT - address if successful */ int flags) /* IN - RH_VERBOSE, RH_BLOCK */ { char * cp; /* error holder */ unsigned snbits; /* for pass to parse_ipad() */ #ifdef DNS_CLIENT int e; /* Net error code */ u_long tmo; /* timeout for blocking calls */ int blocking = flags & RH_BLOCK; #endif /* DNS_CLIENT */ int verbose = flags & RH_VERBOSE; cp = parse_ipad(address, &snbits, host); if (!cp) /* worked, string was parsable dot notation */ return 0; #ifndef DNS_CLIENT if (verbose) dprintf("Unable to parse IP host %s.\nerror: %s\n", host, (char*)cp); return ENP_PARAM; #else /* DNS_CLIENT enabled in build */ if (verbose) dprintf("can't parse %s (%s), trying DNS\n", host, cp); tmo = cticks + (5 * TPS); /* set timeout value */ if (dns_servers[0]) /* dont bother if no servers are set */ { if (verbose) dprintf("trying DNS lookup...\n"); e = dns_query(host, address); if (e == ENP_SEND_PENDING) { if (blocking) { while (tmo > cticks) { tk_yield(); e = dns_query(host, address); if (e == 0) goto rh_got_dns; } } if (verbose) dprintf("DNS inquiry sent\n"); return 0; } else if(e == 0) { rh_got_dns: /* DNS resolution worked */ if (verbose) dprintf("active host found via DNS (%u.%u.%u.%u)\n", PUSH_IPADDR(*address)); return 0; } else if(e == ENP_TIMEOUT) /* timeout? */ { if (verbose) dprintf("DNS timeout"); } else { if (verbose) dprintf("DNS error %d", e); } if (verbose) dprintf(", host not set\n"); return e; } if (verbose) dprintf("DNS/host-parse failed.\n"); return ENP_PARAM; #endif /* DNS_CLIENT */ }
int flood_addr(void * pio) { char * cp = nextarg(((GEN_IO)pio)->inbuf); char arg; /* first char of second arg - a, d, or l. */ char * hosttext; ip_addr host; unsigned i; if (!*cp) /* no arg given */ goto fa_usage; arg = ((*cp) | 0x40); /* force arg to lowercase */ if(arg == 'l') /* user wants list */ { ns_printf(pio, "Current flood target list:\n"); for(i = 0; i < MAXFLOODTARGETS; i++) { if (floodtargs[i] == 0) break; ns_printf(pio, "%u.%u.%u.%u\n", PUSH_IPADDR(floodtargs[i])); } return 0; } /* make sure arg is 'a' or 'd' ('l' is handled above */ if((arg != 'a') && (arg != 'd')) { ns_printf(pio, "Arg must begin with 'a' or 'd'\n"); goto fa_usage; } hosttext = nextarg(cp); if(!(*hosttext)) goto fa_usage; cp = parse_ipad(&host, &i, hosttext); if(cp) { ns_printf(pio, "%s\n", cp); goto fa_usage; } for(i = 0; i < MAXFLOODTARGETS; i++) { if((arg == 'a') && (floodtargs[i] == 0)) { floodtargs[i] = host; ns_printf(pio, "Added host %u.%u.%u.%u\n", PUSH_IPADDR(host)); return 0; } if((arg == 'd') && (floodtargs[i] == host)) { floodtargs[i] = 0; ns_printf(pio, "Deleted host %u.%u.%u.%u\n", PUSH_IPADDR(host)); for( ; i < (MAXFLOODTARGETS - 1); i++) /* move up rest of list */ floodtargs[i] = floodtargs[i + 1]; floodtargs[i] = 0; /* clear last entry */ return 0; } } ns_printf(pio, "Sorry, %s\n", arg=='a'?"flood target table full":"Host not in list"); return -1; fa_usage: ns_printf(pio, "Usage: faddr <add|delete|list> X.X.X.X\n"); return -1; }