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

📄 netime.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/netime.c,v 1.2 2001/11/09 21:06:51 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1994-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: netime.c,v $ * Revision 1.2  2001/11/09 21:06:51  josh * demo router path modification * * Revision 1.1.1.1  2001/11/05 17:49:09  tneale * Tornado shuffle * * Revision 2.5  2001/01/19 22:24:38  paul * Update copyright. * * Revision 2.4  2000/03/17 00:14:19  meister * Update copyright message * * Revision 2.3  1999/04/15 21:43:40  wes * Fix SNARK_ATTACHE_34_DNS_COMPAT to continue working.. * * Revision 2.2  1999/04/09 20:48:46  wes * let it build without ATTACHE_DNS or ATTACHE_TCP * * Revision 2.1  1998/04/09 22:00:25  wes * Start splitting main.c into app-specific files; add netime client * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stdio.h>#include <stdlib.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/ip.h>#include <wrn/wm/attache/glue.h>#include "cmds.h"#if INSTALL_ATTACHE_NETIME_CLIENT#include <wrn/wm/attache/netime.h>#endif#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/read_ini.h>#if INSTALL_ATTACHE_NETIME_CLIENT && INSTALL_ATTACHE_DNSstruct netime_state {  struct sty *sty;  ipaddr_t *addresses;		/* array of addresses to fill in */  int naddr;			/* max addresses we have room for.. */  int vaddr;			/* number of valid addresses so far.. */  int nnames;			/* number of names left to resolve */  char **names;			/* pointer to tail of argv */  netime_query_t *query;	/* the netime query.. */};static void netime_dns_won(struct dns_query *query,			   char *dname,			   int n,			   ipaddr_t addrs[],			   void *cookie);#if INSTALL_SNARK_ATTACHE_34_DNS_COMPATstatic void netime_dns_won_compat  (struct dns_query *query, char *dname, int n, inaddr_t addrs[], void *cookie){  snark_attache_dns_34_compat(netime_dns_won, query, dname, n, addrs, cookie);}#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT *//* netime_dns_err() * * DNS callback if it didn't get an IP address * * prints an error and kills the "session" state block */static void netime_dns_err(struct dns_query *query,			   enum dns_error error,			   void *cookie){  struct netime_state * session = cookie;  display_dns_error(session->sty, query, error);  /* Give the terminal back. */  sty_read(session->sty, do_cmd, prompt, 0);  GLUE_FREE(session->addresses); /* !!! */  GLUE_FREE(session);		/* !!! */}void do_netime_callback (netime_query_t *query,			 bits32_t timestamp,			 void *cookie){  struct netime_state *session = cookie;  printf("Got back answer: %x\n", (unsigned)timestamp);  /* Give the terminal back. */  sty_read(session->sty, do_cmd, prompt, 0);  GLUE_FREE(session->addresses); /* !!! */  GLUE_FREE(session);		/* !!! */}/* netime_dns_won() * * DNS callback if it got an IP address * * Starts resolution of the next name in the list, or starts the time * query if we run out of names.. */static void netime_dns_won(struct dns_query *query,			 char *dname,			 int n,			 ipaddr_t addrs[],			 void *cookie){  struct netime_state *session = cookie;  int v, m;    v = session->vaddr;  m = session->naddr;  if (v+n > m)   {    ipaddr_t *taddrs;    int nm = m+m;    while (v+n > nm)      nm = nm+nm;        /* oops.  too many addresses.. */    taddrs = GLUE_ALLOC (nm * sizeof (ipaddr_t));    if (taddrs == NULL)     {      abort();			/* !!! */    }    MEMCPY(taddrs, session->addresses, m*sizeof(ipaddr_t));    m = nm;  }  MEMCPY(&session->addresses[v], addrs, n*sizeof(ipaddr_t));  v += n;  session->vaddr = v;  session->naddr = m;    if (session->nnames > 0)  {    char *name = session->names[0];    session->names++;    session->nnames--;    /* Go to the DNS for the next ip address */    DNS_NAME_TO_IPADDR(name, netime_dns_won, netime_dns_err,		       &domain_config, 0, session);  } else {    session->query = netime_query (session->addresses, session->vaddr, 1, do_netime_callback, session);    if (session->query == NULL)     {      printf("Bogon!\n");    }  }}boolean_t do_netime(struct sty *sty, int argc, char **argv){  struct netime_state *session;  session = (struct netime_state *)GLUE_ALLOC(sizeof(*session));  if (session == NULL)   {    sty_puts(sty, "%% Couldn't allocate state block\n");    return 1;  }    session->addresses = (ipaddr_t *)GLUE_ALLOC(argc * sizeof(ipaddr_t));    if (session->addresses == NULL)   {    sty_puts(sty, "%% Couldn't allocate state block\n");    return 1;  }  session->sty = sty;  session->naddr = argc;  session->vaddr = 0;  session->names = &argv[2];  session->nnames = argc-2;    /* Go to the DNS for the first ip address */  DNS_NAME_TO_IPADDR(argv[1], netime_dns_won, netime_dns_err,		      &domain_config, 0, session);  return 0;}boolean_t cmd_netime  (struct sty *sty, enum help_level help,		       int argc, char **argv){  switch (help) {   case help_none:    if (argc < 2) {      sty_puts(sty, "insufficient arguments\n");      sty_puts(sty, "usage:  netime host [host ...]\n");      break;    }    return do_netime(sty, argc, argv);   case help_short:    sty_puts(sty, "netime          netime host [host ...]\n");    break;   case help_long:    sty_puts(sty, "\The \"netime\" command attempts to retrieve the time \via the NETIME protocol.\n \It queries each host in turn until it gets a response\n");    break;  }  return 1;}#endif

⌨️ 快捷键说明

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