source: asp3_tinet_ecnl_rx/trunk/ntshell/src/netcmd.c@ 364

Last change on this file since 364 was 364, checked in by coas-nagasima, 5 years ago

TINETとSocket APIなどを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 19.0 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
8 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
9 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
10 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
11 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
12 * スコード中に含まれていること.
13 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
14 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
15 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
16 * の無保証規定を掲載すること.
17 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
18 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
19 * と.
20 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
21 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
22 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
23 * 報告すること.
24 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
25 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
26 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
27 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
28 * 免責すること.
29 *
30 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
31 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
32 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
33 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
34 * の責任を負わない.
35 *
36 * @(#) $Id$
37 */
38#include "shellif.h"
39#include <kernel.h>
40#include <t_stdlib.h>
41#include <sil.h>
42#include <string.h>
43#include "syssvc/serial.h"
44#include "syssvc/syslog.h"
45#include <tinet_config.h>
46#include <netinet/in.h>
47#include <netinet/in_itron.h>
48#include <tinet_nic_defs.h>
49#include <tinet_cfg.h>
50#include <netinet/in_var.h>
51#include <net/ethernet.h>
52#include <net/if6_var.h>
53#include <net/net.h>
54#include <net/if_var.h>
55#include <netinet/udp_var.h>
56#include <netapp/netapp_var.h>
57#include <netapp/netapp.h>
58#include <netapp/dhcp4_cli.h>
59#include <netapp/resolver.h>
60#include "core/ntlibc.h"
61#include "util/ntstdio.h"
62#include "ntp_cli.h"
63#include "kernel_cfg.h"
64
65extern ntstdio_t ntstdio;
66
67#if defined(SUPPORT_INET6)
68#define DEFAULT_API_PROTO API_PROTO_IPV6
69#else
70#define DEFAULT_API_PROTO API_PROTO_IPV4
71#endif
72extern void ping6(T_IN6_ADDR *addr, uint_t tmo, uint_t len);
73extern void ping4(T_IN4_ADDR *addr, uint_t tmo, uint_t len);
74
75/*
76 * str_num -- cons_printf の数値変換
77 */
78
79static void
80str_chr(char *text, int *pos, int size, char c)
81{
82 if (*pos >= size)
83 return;
84 text[*pos] = c;
85 *pos = *pos + 1;
86}
87
88/*
89 * str_num -- cons_printf の数値変換
90 */
91
92static int
93str_num(char *text, int *pos, int size, ulong_t val, int radix,
94 const char *radchar, int width, bool_t minus, char padchar)
95{
96 char digits[24];
97 int ix, pad, pchars;
98 bool_t left;
99
100 if (width < 0) {
101 width = -width;
102 left = true;
103 }
104 else
105 left = false;
106
107 ix = 0;
108 do {
109 digits[ix ++] = radchar[val % radix];
110 val /= radix;
111 } while (val != 0);
112
113 if (minus)
114 digits[ix ++] = '-';
115
116 if (width > ix)
117 pchars = width;
118 else
119 pchars = ix;
120
121 pad = ix;
122 if (!left) /* 右詰め */
123 for ( ; pad < width; pad ++)
124 str_chr(text, pos, size, padchar);
125
126 while (ix -- > 0)
127 str_chr(text, pos, size, digits[ix]);
128
129 if (left) /* 左詰め */
130 for ( ; pad < width; pad ++)
131 str_chr(text, pos, size, padchar);
132
133 return pchars;
134}
135
136/*
137 * str_ipv4addr -- IPv4 アドレス出力
138 */
139
140int
141str_ipv4addr (char *text, int size, T_IN4_ADDR *addr, int width)
142{
143 int len = 3, pos = 0; /* 3 は '.' の文字数 */
144
145 len += str_num(text, &pos, size, (*addr >> 24) & 0xff, 10, radhex, 0, false, ' ');
146 str_chr(text, &pos, size, '.');
147 len += str_num(text, &pos, size, (*addr >> 16) & 0xff, 10, radhex, 0, false, ' ');
148 str_chr(text, &pos, size, '.');
149 len += str_num(text, &pos, size, (*addr >> 8) & 0xff, 10, radhex, 0, false, ' ');
150 str_chr(text, &pos, size, '.');
151 len += str_num(text, &pos, size, *addr & 0xff, 10, radhex, 0, false, ' ');
152
153 for ( ; len < width; len ++)
154 str_chr(text, &pos, size, ' ');
155
156 return len;
157}
158
159/*
160 * ipv6addr -- IPv6 アドレス出力
161 */
162
163int
164str_ipv6addr (char *text, int size, const T_IN6_ADDR *addr, int width)
165{
166 int len = 0, ix, len6, pos = 0;
167 bool_t omit = false, zero = false;
168
169 if (addr == NULL || IN6_IS_ADDR_UNSPECIFIED(addr)) {
170 str_chr(text, &pos, size, '0');
171 str_chr(text, &pos, size, ':');
172 str_chr(text, &pos, size, ':');
173 str_chr(text, &pos, size, '0');
174 len = 4;
175 }
176 else {
177 if (in6_is_addr_ipv4mapped(addr))
178 len6 = sizeof(T_IN6_ADDR) / 2 - 2;
179 else
180 len6 = sizeof(T_IN6_ADDR) / 2;
181 for (ix = 0; ix < len6; ix ++) {
182 if (omit) {
183 len += str_num(text, &pos, size, ntohs(addr->s6_addr16[ix]), 16, radhex, 0, false, ' ');
184 if (ix < 7) {
185 str_chr(text, &pos, size, ':');
186 len ++;
187 }
188 }
189 else if (ix > 0 && ix < 7 && addr->s6_addr16[ix] == 0)
190 zero = true;
191 else {
192 if (zero) {
193 omit = true;
194 str_chr(text, &pos, size, ':');
195 len ++;
196 }
197 len += str_num(text, &pos, size, ntohs(addr->s6_addr16[ix]), 16, radhex, 0, false, ' ');
198 if (ix < 7) {
199 str_chr(text, &pos, size, ':');
200 len ++;
201 }
202 }
203 }
204
205 if (len6 == sizeof(T_IN6_ADDR) / 2 - 2) {
206 T_IN4_ADDR ip4addr;
207
208 ip4addr = ntohl(addr->s6_addr32[3]);
209 len += str_ipv4addr(&text[len], size - len, &ip4addr, 0);
210 }
211
212 for ( ; len < width; len ++)
213 str_chr(text, &pos, size, ' ');
214 }
215 return len;
216}
217
218/*
219 * str_macaddr -- MAC アドレス出力
220 */
221
222int
223str_macaddr (char *text, int size, uint8_t *mac, int width)
224{
225 int oct, len, pos = 0;
226
227 for (oct = 5; oct -- > 0; ) {
228 str_num(text, &pos, size, *mac ++, 16, radhex, 2, false, '0');
229 str_chr(text, &pos, size, ':');
230 }
231 str_num(text, &pos, size, *mac, 16, radhex, 2, false, '0');
232
233 for (len = 17; len < width; len ++)
234 str_chr(text, &pos, size, ' ');
235
236 return len;
237}
238
239int usrcmd_ping(int argc, char **argv)
240{
241 int tmo = 3, size = 64;
242 char apip = DEFAULT_API_PROTO;
243 char *line = argv[1];
244#if defined(SUPPORT_INET6)
245 T_IN6_ADDR addr;
246#if defined(SUPPORT_INET4)
247 T_IN4_ADDR addr4;
248#endif
249#else
250 T_IN4_ADDR addr;
251#endif
252 static const char i6rlp_pmtu_str1[] = " FF1E::1:2 1 1452";
253 static const char i6rlp_pmtu_str2[] = " FF1E::1:2 1 1352";
254 static const char i6rlp_pmtu_str3[] = " fe80::0200:00ff:fe00:0100 1 2";
255
256 if (apip == '1')
257 ntlibc_strcpy(line, i6rlp_pmtu_str1);
258 else if (apip == '2')
259 ntlibc_strcpy(line, i6rlp_pmtu_str2);
260 else if (apip == '3')
261 ntlibc_strcpy(line, i6rlp_pmtu_str3);
262
263#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
264 if (argc <= 2)
265 return 0;
266
267 if ('0' <= *line && *line <= '9') {
268 if (*line == '6')
269 apip = API_PROTO_IPV6;
270 if (*line == '4')
271 apip = API_PROTO_IPV4;
272 line++;
273 }
274
275 line = argv[2];
276#else
277 if (argc <= 1)
278 return 0;
279#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
280
281 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
282 ntstdio_printf(&ntstdio, "[PING] unknown host.\n");
283 return 0;
284 }
285
286 if (argc > 2) {
287 line = argv[2];
288 if ('0' <= *line && *line <= '9')
289 line = get_int(&tmo, line);
290
291 if (argc > 3) {
292 line = argv[3];
293 if ('0' <= *line && *line <= '9')
294 line = get_int(&size, line);
295 }
296 }
297
298#if defined(SUPPORT_INET6)
299#if defined(SUPPORT_INET4)
300 if (apip == API_PROTO_IPV6) {
301 ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
302 ping6(&addr, (uint_t)tmo, (uint_t)size);
303 }
304 else {
305 addr4 = ntohl(addr.s6_addr32[3]);
306 ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
307 ping4(&addr4, (uint_t)tmo, (uint_t)size);
308 }
309#else /* of #if defined(SUPPORT_INET4) */
310 ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
311 ping6(&addr, (uint_t)tmo, (uint_t)size);
312#endif /* of #if defined(SUPPORT_INET4) */
313#else /* of #if defined(SUPPORT_INET6) */
314 ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
315 ping4(&addr, (uint_t)tmo, (uint_t)size);
316#endif /* of #if defined(SUPPORT_INET6) */
317
318 return 0;
319}
320
321static void dhcp4c_info()
322{
323 T_IN4_ADDR svaddr;
324 SYSTIM bind_start;
325 ER ret;
326 uint32_t expire, renew, rebind;
327 char temp[30];
328 int pos;
329
330 if ((ret = dhcp4c_get_info(&svaddr, &expire, &renew, &rebind, &bind_start)) == E_OK) {
331 pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
332 temp[pos] = '\0';
333 ntstdio_printf(&ntstdio, "DHCPv4 server: %s,\n", temp);
334 ntstdio_printf(&ntstdio, " Renew: %u:%02u:%02u,\n",
335 renew / 3600, (renew / 60) % 60, renew % 60);
336 ntstdio_printf(&ntstdio, " Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n",
337 rebind / 3600, (rebind / 60) % 60, rebind % 60,
338 expire / 3600, (expire / 60) % 60, expire % 60);
339 }
340 else if (ret == E_OBJ)
341 ntstdio_printf(&ntstdio, "DHCPv4 server: not available.\n");
342}
343
344int usrcmd_dhcp4c(int argc, char **argv)
345{
346 ER ret;
347
348 if (argc < 2)
349 return 0;
350
351 if (ntlibc_strcmp(argv[1], "rel") == 0) {
352 ret = dhcp4c_rel_info();
353 ntstdio_printf(&ntstdio, "dhcp4c_rel_info %d\n", ret);
354 }
355 else if (ntlibc_strcmp(argv[1], "renew") == 0) {
356 ret = dhcp4c_renew_info();
357 ntstdio_printf(&ntstdio, "dhcp4c_renew_info %d\n", ret);
358 }
359 else {
360 dhcp4c_info();
361 }
362
363 return 0;
364}
365
366/*
367* s_show_dns_domain_name -- DNS のドメイン名を表示する。
368*/
369
370static uint_t
371s_show_dns_domain_name(uint8_t *hdr, uint_t offset)
372{
373 uint8_t *ptr;
374 uint_t c;
375
376 ptr = hdr + offset;
377 while (*ptr) {
378 if ((*ptr & DNS_MSG_COMP_MARK) == DNS_MSG_COMP_MARK) {
379 s_show_dns_domain_name(hdr, (*ptr & ~DNS_MSG_COMP_MARK) << 8 | *(ptr + 1));
380 ptr += 2;
381 break;
382 }
383 else {
384 for (c = 1; c <= *ptr; c++)
385 ntstdio_printf(&ntstdio, "%c", *(ptr + c));
386 ptr += *ptr + 1;
387 if (*ptr)
388 ntstdio_printf(&ntstdio, ".");
389 }
390 }
391 return ptr - hdr;
392}
393
394/*
395 * show_dns_soa -- DNS の SOA RDATA を表示する。
396 */
397
398static ER_UINT
399show_dns_soa(uint8_t *msg, ER_UINT length, uint_t offset)
400{
401 T_RSLV_SOA soa;
402 ER_UINT error;
403 uint_t rn_offset;
404
405 if ((error = dns_analyze_soa(&soa, offset, msg, length)) < 0)
406 return error;
407
408 ntstdio_printf(&ntstdio, " mname: ");
409 rn_offset = s_show_dns_domain_name(msg, offset);
410 ntstdio_putc(&ntstdio, '\n');
411 ntstdio_printf(&ntstdio, " rname: ");
412 s_show_dns_domain_name(msg, rn_offset);
413 ntstdio_putc(&ntstdio, '\n');
414
415 ntstdio_printf(&ntstdio, " serial: %d\n", soa.serial);
416 ntstdio_printf(&ntstdio, " refresh: %d\n", soa.refresh);
417 ntstdio_printf(&ntstdio, " retry: %d\n", soa.retry);
418 ntstdio_printf(&ntstdio, " expirel: %d\n", soa.expire);
419 ntstdio_printf(&ntstdio, " minimum: %d\n", soa.minimum);
420
421 return E_OK;
422}
423
424/*
425 * show_dns_qdsection -- DNS の Question セクションを表示する。
426 */
427
428static ER_UINT
429show_dns_qdsection(uint8_t *msg, ER_UINT length, T_RSLV_DNS_MSG *rslv)
430{
431 T_RSLV_QD qd;
432 ER_UINT offset, error;
433 int scount;
434
435 ntstdio_printf(&ntstdio, "question section: %d\n", rslv->dns_hdr.qdcount);
436 offset = rslv->qd_offset;
437 for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
438 if ((error = dns_analyze_qd(&qd, offset, msg, length)) < 0)
439 return error;
440
441 ntstdio_printf(&ntstdio, "%2d: ", scount);
442 s_show_dns_domain_name(msg, offset);
443 ntstdio_printf(&ntstdio, "\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
444 offset = error;
445 }
446
447 return E_OK;
448}
449
450/*
451 * show_dns_section -- DNS の各セクションを表示する。
452 */
453
454static ER_UINT
455show_dns_section(uint8_t *msg, ER_UINT length, uint_t scount, uint_t offset, char *title)
456{
457 T_RSLV_RR rr;
458 T_IN4_ADDR in4_addr;
459 ER_UINT error;
460 int count, dcount, col;
461 T_IN6_ADDR in6_addr;
462 char temp[30];
463 int pos;
464
465 ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount);
466 for (count = 1; count <= scount; count++) {
467 if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
468 return error;
469
470 ntstdio_printf(&ntstdio, "%2d: ", count);
471 s_show_dns_domain_name(msg, offset);
472 ntstdio_printf(&ntstdio, "\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
473 dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
474
475 switch (rr.type) {
476 case DNS_TYPE_A:
477 memcpy((void*)&in4_addr, (void*)(msg + rr.rdata_offset), sizeof(in4_addr));
478 in4_addr = ntohl(in4_addr);
479 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
480 temp[pos] = '\0';
481 ntstdio_printf(&ntstdio, " IPv4 addr: %s\n", temp);
482 break;
483 case DNS_TYPE_NS:
484 ntstdio_printf(&ntstdio, " host: ");
485 s_show_dns_domain_name(msg, rr.rdata_offset);
486 ntstdio_putc(&ntstdio, '\n');
487 break;
488 case DNS_TYPE_CNAME:
489 ntstdio_printf(&ntstdio, " host: ");
490 s_show_dns_domain_name(msg, rr.rdata_offset);
491 ntstdio_putc(&ntstdio, '\n');
492 break;
493 case DNS_TYPE_SOA:
494 show_dns_soa(msg, length, rr.rdata_offset);
495 break;
496 case DNS_TYPE_PTR:
497 ntstdio_printf(&ntstdio, " PTR: ");
498 s_show_dns_domain_name(msg, rr.rdata_offset);
499 ntstdio_putc(&ntstdio, '\n');
500 break;
501 case DNS_TYPE_AAAA:
502 memcpy((void*)&in6_addr, (void*)(msg + rr.rdata_offset), sizeof(in6_addr));
503 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
504 temp[pos] = '\0';
505 ntstdio_printf(&ntstdio, " IPv6 addr: %s\n", temp);
506 break;
507 default:
508 ntstdio_printf(&ntstdio, " data: ");
509 col = 32;
510 for (dcount = 0; dcount < rr.rdlength; dcount++) {
511 ntstdio_printf(&ntstdio, "%02x", *(msg + rr.rdata_offset + dcount));
512 if (--col == 0) {
513 ntstdio_printf(&ntstdio, "\n ");
514 col = 32;
515 }
516 }
517 ntstdio_putc(&ntstdio, '\n');
518 break;
519 }
520 }
521
522 return E_OK;
523}
524/*
525 * dns_info -- DNS 情報の表示
526 */
527
528static void dns_info()
529{
530#if defined(SUPPORT_INET6)
531 T_IN6_ADDR in6_addr;
532#endif
533#if defined(SUPPORT_INET4)
534 T_IN4_ADDR in4_addr;
535#endif
536 char temp[30];
537 int pos;
538
539#if defined(SUPPORT_INET6)
540
541 ntstdio_printf(&ntstdio, "domain name: %s\n", dns_in6_get_dname());
542
543#else /* of #if defined(SUPPORT_INET6) */
544
545 ntstdio_printf(&ntstdio, "domain name: %s\n", dns_in4_get_dname());
546
547#endif /* of #if defined(SUPPORT_INET6) */
548
549#if defined(SUPPORT_INET6)
550 dns_in6_get_addr(&in6_addr);
551 ntstdio_printf(&ntstdio, "IPv6 DNS server: ");
552 if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
553 ntstdio_printf(&ntstdio, "not available.\n");
554 else {
555 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
556 temp[pos] = '\0';
557 ntstdio_printf(&ntstdio, "%s.\n", temp);
558 }
559#endif /* of #if defined(SUPPORT_INET6) */
560
561#if defined(SUPPORT_INET4)
562 dns_in4_get_addr(&in4_addr);
563 ntstdio_printf(&ntstdio, "IPv4 DNS server: ");
564 if (in4_addr == IPV4_ADDRANY)
565 ntstdio_printf(&ntstdio, "not available.\n");
566 else {
567 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
568 temp[pos] = '\0';
569 ntstdio_printf(&ntstdio, "%s.\n", temp);
570 }
571#endif /* of #if defined(SUPPORT_INET4) */
572}
573
574/*
575 * name_lookup -- ホスト名-IP アドレス変換
576 */
577
578const char *rcode_str[] = {
579 "no error",
580 "format error",
581 "server error",
582 "name error",
583 "not implement",
584 "refused",
585};
586
587int usrcmd_dnsc(int argc, char **argv)
588{
589 char *line = argv[1];
590 static char hostname[DBG_LINE_SIZE + 1];
591
592 T_RSLV_DNS_MSG rslv;
593 ER_UINT length, offset;
594 ER error;
595 uint_t flags = 0;
596 uint8_t *msg;
597
598 if (ntlibc_strcmp(line, "info") == 0) {
599 dns_info();
600 return 0;
601 }
602
603 /* コマンドのオプションを設定する。*/
604 line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
605 if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) {
606 ntstdio_printf(&ntstdio, "DNS server not available.\n");
607 return 0;
608 }
609
610 /* 照会するホスト名・IP アドレスを解析する。*/
611 resolv_hoststr(&flags, hostname, sizeof(hostname), line);
612
613 /* 正引きでも逆引きでもプロトコル上は正引きを指定する。*/
614 flags |= DNS_LUP_OPCODE_FORWARD;
615
616 /* IPv6 アドレス、または IPv4 アドレスが指定された時は、照会タイプは PTR に設定する。*/
617 if (((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV6) ||
618 ((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV4))
619 flags = (flags & ~DNS_LUP_FLAGS_QTYPE_MASK) | DNS_LUP_FLAGS_QTYPE_PTR;
620
621 if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) {
622 ntstdio_printf(&ntstdio, "get buffer error: %s.\n", itron_strerror(error));
623 return 0;
624 }
625
626 if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) {
627 //ntstdio_printf(&ntstdio, "error: %s.\n", itron_strerror(length));
628 goto err_ret;
629 }
630
631 dly_tsk(1 * 1000);
632 ntstdio_printf(&ntstdio, "DNS header: flags: ");
633 if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
634 DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) {
635 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
636 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
637 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
638 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
639 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
640 ntstdio_printf(&ntstdio, " ");
641 }
642 ntstdio_printf(&ntstdio, "opcode: ");
643 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
644 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
645 ntstdio_printf(&ntstdio, ", rcode: %s.\n",
646 (rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
647 ? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
648
649 if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) {
650 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
651 }
652 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) {
653 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
654 }
655 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) {
656 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
657 }
658 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) {
659 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
660 }
661
662err_ret:
663 if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK)
664 ntstdio_printf(&ntstdio, "release buffer error: %s.\n", itron_strerror(error));
665 return 0;
666}
667
668int usrcmd_ntpc(int argc, char **argv)
669{
670 ntp_cli_execute();
671 return 0;
672}
Note: See TracBrowser for help on using the repository browser.