⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
  sty_read(state->sty, do_cmd, prompt, 0);  GLUE_FREE(state);}static boolean_t cmd_telnet  (struct sty *sty, enum help_level help, int argc, char **argv){  struct telnet_state *state;  switch (help) {   case help_none:    if (argc < 2) {      sty_puts(sty, "% No hostname specified.\n");      break;    }    if ((state = GLUE_ALLOC(sizeof(*state))) == 0) {      sty_puts(sty, "couldn't allocate telnet state block\n");      break;    }    MEMSET(state, 0, sizeof(*state));    state->sty = sty;    if (argc > 2)      state->port = atoi(argv[2]);    if (state->port == 0)      state->port = TN_RESERVED_PORT;    sty_printf(sty, "Translating %s...", argv[1]);    DNS_NAME_TO_IPADDR(argv[1], telnet_dns_won, telnet_dns_err,		       &domain_config, 0, state);    return 0;			/* DON'T reschedule command scanner yet */   case help_short:    sty_puts(sty, "telnet          open TELNET connection to specified host\n");    break;   case help_long:    sty_puts(sty, "\The \"telnet\" command attempts to open a TELNET connection to\n\a host you specify.\n");    break;  }  return 1;}#endif /* INSTALL_ATTACHE_TELNET && INSTALL_ATTACHE_DNS */#if INSTALL_ATTACHE_PING && INSTALL_ATTACHE_DNS#ifndef PING_DELAY#define	PING_DELAY	1000#endif#ifndef	PING_MAX#define	PING_MAX	5#endifstruct ping_state {  struct ping_conn pingc;  struct timer timer;  struct sty *sty;  bits16_t max;  bits32_t delay;  bits32_t timestamp;  char name[MAX_IPADDR_STRING_LEN];};static void ping_done(struct ping_state *state, char *msg){  ping_ignore(ping_conn_get_port(&state->pingc));  etc_tm_cancel(&state->timer);  sty_printf(state->sty, "[%s]\n", msg);  sty_read(state->sty, do_cmd, prompt, 0);  GLUE_FREE(state);  return;}static void ping_sendnext(struct ping_state *state){  bits16_t seq = ping_conn_get_seq(&state->pingc);  packet *p;  if (seq++ >= state->max) {    ping_done(state, "finished");    return;  }  if ((p = ping_alloc(0, 0)) == 0) {    ping_done(state, "couldn't allocate packet buffer");    return;  }  ping_conn_set_seq(&state->pingc, seq);  if (ping_send_conn(p, &state->pingc) == IP_SEND_IPSEC_DENIED)      sty_printf (state->sty, "Outbound PING administratively denied.\n");  state->timestamp = GLUE_NOW();  etc_tm_set(&state->timer, state->delay);}static void ping_timeout(struct timer *tm, void *cookie){  struct ping_state *state = cookie;  sty_printf(state->sty, "ping %s #%hu timed out\n",	     state->name, ping_conn_get_seq(&state->pingc));  ping_sendnext(state);}static void ping_receive(packet *p, void *cookie){  struct ping_state *state = cookie;  bits16_t seq = PING_RCV_GET_SEQUENCE(p);  if (seq == ping_conn_get_seq(&state->pingc)) {    bits32_t rtt = GLUE_NOW() - state->timestamp;    sty_printf(state->sty, "ping %s #%hu ok, RTT %lu.%03lu seconds\n",	       state->name, seq, rtt / 1000, rtt % 1000);    pkt_free(p);    ping_sendnext(state);  } else {    sty_printf(state->sty, "ping %s #%hu arrived late\n", 	       state->name, seq);    pkt_free(p);  }}static void ping_unreachable(packet *p, void *cookie){  struct ping_state *state = cookie;  ipaddr_t host;  IP_RCV_GET_SRC_IP(p, &host);  sty_printf(state->sty, "ping %s #%hu got Destination Unreachable from %s\n",	     state->name, PING_RCV_GET_SEQUENCE(p),	     ipaddr_to_string(&host, 0, 0));  pkt_free(p);}static void ping_start(struct ping_state *state, char *dname){  ping_conn_set_port(&state->pingc,		     ping_listen(0, ping_receive, ping_unreachable, state));  ipaddr_to_string(ip_conn_ptr_dst_ip(ping_conn_get_ip_conn(&state->pingc)),		   state->name, sizeof(state->name));  sty_printf(state->sty, "[host %s (%s), max tries %hu, delay %lu.%03lu]\n",	     (dname ? dname : state->name), state->name, state->max,	     state->delay / 1000, state->delay % 1000);  if (ping_conn_get_port(&state->pingc))     ping_sendnext(state);  else    ping_done(state, "couldn't get listener\n");}static void ping_dns_won  (struct dns_query *query, char *dname, int n, ipaddr_t addrs[], void *cookie){  struct ping_state *state = cookie;  ip_conn_set_dst_ip(ping_conn_get_ip_conn(&state->pingc), &addrs[0]);  ping_start(state, dname);}#if INSTALL_SNARK_ATTACHE_34_DNS_COMPATstatic void ping_dns_won_compat  (struct dns_query *query, char *dname, int n, inaddr_t addrs[], void *cookie){  snark_attache_dns_34_compat(ping_dns_won, query, dname, n, addrs, cookie);}#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */static void ping_dns_err  (struct dns_query *query, enum dns_error error, void *cookie){  struct ping_state *state = cookie;  display_dns_error(state->sty, query, error);  sty_read(state->sty, do_cmd, prompt, 0);  GLUE_FREE(state);}static boolean_t cmd_ping  (struct sty *sty, enum help_level help, int argc, char **argv){  struct ping_state *state;  switch (help) {   case help_none:    if (argc < 2) {      sty_puts(sty, "% You have to tell me who to ping.\n");      break;    }    if ((state = (struct ping_state *) GLUE_ALLOC(sizeof(*state))) == 0) {      sty_puts(sty, "% Couldn't allocate state block\n");      break;    }    etc_tm_init(&state->timer);    ping_conn_init(&state->pingc);    state->sty = sty;    state->timer.cookie = state;    state->timer.handler = ping_timeout;    state->max = PING_MAX;    state->delay = PING_DELAY;    if (argc >= 3)      sscanf(argv[2], "%hu", &state->max);    if (argc >= 4)      sscanf(argv[3], "%lu", &state->delay);    DNS_NAME_TO_IPADDR(argv[1], ping_dns_won, ping_dns_err, &domain_config,		       0, state);    return 0;			/* DON'T reschedule command scanner yet */   case help_short:    sty_puts(sty, "ping            ping host [tries] [delay]\n");    break;   case help_long:    sty_puts(sty, "\The \"ping\" command attempts to ping a host for you.\n\First argument is hostname or IP address.\n\Optional second argument is number of times to ping.\n\Optional third argument is how many milliseconds to delay between tries.\n");    break;  }  return 1;}#endif /* INSTALL_ATTACHE_PING && INSTALL_ATTACHE_DNS */#if INSTALL_ATTACHE_TCP && INSTALL_ATTACHE_DNS#define	FINGER_PORT	79#define	FINGER_WINDOW	4096static bits16_t finger_rcv(struct tcb *tcb, packet *p){  struct sty *sty = tcp_get_cookie(tcb);  int i;  for (i = 0; ((unsigned) i) < p->pkt_datalen; ++i)    if (p->pkt_data[i] != '\r')      sty_putc(sty, p->pkt_data[i]);  pkt_free(p);  return FINGER_WINDOW;}static void finger_open(struct tcb *tcb){  struct sty *sty = tcp_get_cookie(tcb);  char *name = sty->app_cookie;  size_t len = STRLEN(name);  packet *p = tcp_alloc(len + 2);  STRCPY((char *) (p->pkt_data), name);  p->pkt_data[len++] = '\r';  p->pkt_data[len++] = '\n';  p->pkt_datalen = len;  tcp_write(tcb, p);}static void finger_fclose(struct tcb *tcb){  tcp_close(tcb);}static void finger_close(struct tcb *tcb, int reason){  struct sty *sty = tcp_get_cookie(tcb);  if (!sty)    return;  sty_putc(sty, '\n');  switch (reason) {   case TCP_CLOSE_OK:    break;   case TCP_CLOSE_RESET:    sty_puts(sty, "connection reset\n");    break;   case TCP_CLOSE_TIMEOUT:    sty_puts(sty, "connection timed out\n");    break;   case TCP_CLOSE_UNREACHABLE:    sty_puts(sty, "destination unreachable\n");    break;   default:    sty_printf(sty, "unknown TCP error code %d\n", reason);  }  sty_read(sty, do_cmd, prompt, 0);}static void finger_dns_won  (struct dns_query *query, char *dname, int n, ipaddr_t addrs[], void *cookie){  struct sty *sty = cookie;  struct tcb *tcb;  int rc;  sty_printf(sty, "[%s]\n", dname);  if ((tcb = tcp_create()) == 0) {    sty_puts(sty, "couldn't allocate tcb\n");    sty_read(sty, do_cmd, prompt, 0);    return;  }  tcp_set_remote_ipaddr(tcb, &addrs[0]);  tcp_set_remote_port(tcb, FINGER_PORT);  tcp_set_open_upcall(tcb, finger_open);  tcp_set_receive_upcall(tcb, finger_rcv);  tcp_set_remote_close_upcall(tcb, finger_fclose);  tcp_set_closed_upcall(tcb, finger_close);  tcp_set_receive_window(tcb, FINGER_WINDOW);  if ((rc = tcp_start(tcb, TCP_ACTIVE)) != TCP_START_OK) {    sty_printf(sty, "couldn't open connection, rc = %d\n", rc);    sty_read(sty, do_cmd, prompt, 0);    return;  }  tcp_set_cookie(tcb, sty);}#if INSTALL_SNARK_ATTACHE_34_DNS_COMPATstatic void finger_dns_won_compat  (struct dns_query *query, char *dname, int n, inaddr_t addrs[], void *cookie){  snark_attache_dns_34_compat(finger_dns_won, query, dname, n, addrs, cookie);}#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */static void finger_dns_err  (struct dns_query *query, enum dns_error error, void *cookie){  struct sty *sty = cookie;  display_dns_error(sty, query, error);  sty_read(sty, do_cmd, prompt, 0);}static boolean_t cmd_finger  (struct sty *sty, enum help_level help, int argc, char **argv){  char *host;  switch (help) {   case help_none:    if (argc < 2) {      sty_puts(sty, "% You have to tell me who to finger.\n");      break;    }    if ((host = strrchr(argv[1], '@')) == 0) {      sty_puts(sty, "% Local finger not supported yet, sorry.\n");      break;    }    *host++ = '\0';    sty->app_cookie = argv[1];    DNS_NAME_TO_IPADDR(host, finger_dns_won, finger_dns_err,			&domain_config, 0, sty);    return 0;			/* DON'T reschedule command scanner yet */   case help_short:    sty_puts(sty, "finger          finger user@host\n");    break;   case help_long:    sty_puts(sty, "\The \"finger\" command attempts to finger user@host for you.\n");    break;  }  return 1;}#endif /* INSTALL_ATTACHE_TCP && INSTALL_ATTACHE_DNS *//* * Just writes out some interesting, hopefully, compile time options */static boolean_t cmd_compile_options  (struct sty *sty, enum help_level help, int argc, char **argv){  switch (help) {   case help_short:    sty_puts(sty, "compile-options print configuration information\n");    break;   case help_long:    sty_puts(sty, "\The \"compile-options\" command prints out some of the compile-time\n\options used for building the Attache and Envoy libraries that went\n\into this demo router.\n");    break;   case help_none:    sty_puts(sty, "This router was built with:\n");    sty_puts(sty, "     IPV6             : ");#if INSTALL_ATTACHE_IPV6    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     IP Forwarding    : ");#if INSTALL_ATTACHE_IP_FORWARDING    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     IP Security      : ");#if INSTALL_ATTACHE_IPSEC    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     Router Discovery : ");#if INSTALL_ATTACHE_IPV4_ROUTER_DISCOVERY    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     Multicast        : ");#if INSTALL_ATTACHE_MULTICAST    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     IGMP             : ");#if INSTALL_ATTACHE_MULTICAST_IGMP    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     Attache RIP      : ");#if INSTALL_ATTACHE_RIP    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     TCP              : ");#if INSTALL_ATTACHE_TCP    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     ENVOY            : ");#if INSTALL_ENVOY    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     SNMPv1           : ");#if INSTALL_ENVOY_SNMP_VERSION_1    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     SNMPv2           : ");#if INSTALL_ENVOY_SNMP_VERSION_2    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     SNMPv3           : ");#if INSTALL_ENVOY_SNMP_VERSION_3    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     PPP              : ");#if INSTALL_ATTACHE_PPP    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     PPP Debug        : ");#if INSTALL_ATTACHE_PPP_DEBUG    sty_puts(sty, "On\n");#else    sty_puts(sty, "Off\n");#endif    sty_puts(sty, "     PPP over SLIP    : ");#if INSTALL_SNARK_PKTDRV_PPP_OVER_SLIP    sty_puts(sty, "On\n");#else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -