source: asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c@ 352

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

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 18.8 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, size;
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 ('0' <= *line && *line <= '9') {
265 if (*line == '6')
266 apip = API_PROTO_IPV6;
267 if (*line == '4')
268 apip = API_PROTO_IPV4;
269 line++;
270 }
271#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
272
273 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
274 ntstdio_printf(&ntstdio, "[PING] unknown host.\n");
275 return 0;
276 }
277
278 line = argv[2];
279 if ('0' <= *line && *line <= '9')
280 line = get_int(&tmo, line);
281 else
282 tmo = 3;
283
284 line = argv[3];
285 if ('0' <= *line && *line <= '9')
286 line = get_int(&size, line);
287 else
288 size = 64;
289
290#if defined(SUPPORT_INET6)
291#if defined(SUPPORT_INET4)
292 if (apip == API_PROTO_IPV6) {
293 ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
294 ping6(&addr, (uint_t)tmo, (uint_t)size);
295 }
296 else {
297 addr4 = ntohl(addr.s6_addr32[3]);
298 ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
299 ping4(&addr4, (uint_t)tmo, (uint_t)size);
300 }
301#else /* of #if defined(SUPPORT_INET4) */
302 ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
303 ping6(&addr, (uint_t)tmo, (uint_t)size);
304#endif /* of #if defined(SUPPORT_INET4) */
305#else /* of #if defined(SUPPORT_INET6) */
306 ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
307 ping4(&addr, (uint_t)tmo, (uint_t)size);
308#endif /* of #if defined(SUPPORT_INET6) */
309
310 return 0;
311}
312
313static void dhcp4c_info()
314{
315 T_IN4_ADDR svaddr;
316 SYSTIM bind_start;
317 ER ret;
318 uint32_t expire, renew, rebind;
319 char temp[30];
320 int pos;
321
322 if ((ret = dhcp4c_get_info(&svaddr, &expire, &renew, &rebind, &bind_start)) == E_OK) {
323 pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
324 temp[pos] = '\0';
325 ntstdio_printf(&ntstdio, "DHCPv4 server: %s,\n", temp);
326 ntstdio_printf(&ntstdio, " Renew: %u:%02u:%02u,\n",
327 renew / 3600, (renew / 60) % 60, renew % 60);
328 ntstdio_printf(&ntstdio, " Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n",
329 rebind / 3600, (rebind / 60) % 60, rebind % 60,
330 expire / 3600, (expire / 60) % 60, expire % 60);
331 }
332 else if (ret == E_OBJ)
333 ntstdio_printf(&ntstdio, "DHCPv4 server: not available.\n");
334}
335
336int usrcmd_dhcp4c(int argc, char **argv)
337{
338 ER ret;
339 if (ntlibc_strcmp(argv[1], "rel") == 0) {
340 ret = dhcp4c_rel_info();
341 ntstdio_printf(&ntstdio, "dhcp4c_rel_info %d\n", ret);
342 }
343 else if (ntlibc_strcmp(argv[1], "renew") == 0) {
344 ret = dhcp4c_renew_info();
345 ntstdio_printf(&ntstdio, "dhcp4c_renew_info %d\n", ret);
346 }
347 else {
348 dhcp4c_info();
349 }
350 return 0;
351}
352
353/*
354* s_show_dns_domain_name -- DNS のドメイン名を表示する。
355*/
356
357static uint_t
358s_show_dns_domain_name(uint8_t *hdr, uint_t offset)
359{
360 uint8_t *ptr;
361 uint_t c;
362
363 ptr = hdr + offset;
364 while (*ptr) {
365 if ((*ptr & DNS_MSG_COMP_MARK) == DNS_MSG_COMP_MARK) {
366 s_show_dns_domain_name(hdr, (*ptr & ~DNS_MSG_COMP_MARK) << 8 | *(ptr + 1));
367 ptr += 2;
368 break;
369 }
370 else {
371 for (c = 1; c <= *ptr; c++)
372 ntstdio_printf(&ntstdio, "%c", *(ptr + c));
373 ptr += *ptr + 1;
374 if (*ptr)
375 ntstdio_printf(&ntstdio, ".");
376 }
377 }
378 return ptr - hdr;
379}
380
381/*
382 * show_dns_soa -- DNS の SOA RDATA を表示する。
383 */
384
385static ER_UINT
386show_dns_soa(uint8_t *msg, ER_UINT length, uint_t offset)
387{
388 T_RSLV_SOA soa;
389 ER_UINT error;
390 uint_t rn_offset;
391
392 if ((error = dns_analyze_soa(&soa, offset, msg, length)) < 0)
393 return error;
394
395 ntstdio_printf(&ntstdio, " mname: ");
396 rn_offset = s_show_dns_domain_name(msg, offset);
397 ntstdio_putc(&ntstdio, '\n');
398 ntstdio_printf(&ntstdio, " rname: ");
399 s_show_dns_domain_name(msg, rn_offset);
400 ntstdio_putc(&ntstdio, '\n');
401
402 ntstdio_printf(&ntstdio, " serial: %d\n", soa.serial);
403 ntstdio_printf(&ntstdio, " refresh: %d\n", soa.refresh);
404 ntstdio_printf(&ntstdio, " retry: %d\n", soa.retry);
405 ntstdio_printf(&ntstdio, " expirel: %d\n", soa.expire);
406 ntstdio_printf(&ntstdio, " minimum: %d\n", soa.minimum);
407
408 return E_OK;
409}
410
411/*
412 * show_dns_qdsection -- DNS の Question セクションを表示する。
413 */
414
415static ER_UINT
416show_dns_qdsection(uint8_t *msg, ER_UINT length, T_RSLV_DNS_MSG *rslv)
417{
418 T_RSLV_QD qd;
419 ER_UINT offset, error;
420 int scount;
421
422 ntstdio_printf(&ntstdio, "question section: %d\n", rslv->dns_hdr.qdcount);
423 offset = rslv->qd_offset;
424 for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
425 if ((error = dns_analyze_qd(&qd, offset, msg, length)) < 0)
426 return error;
427
428 ntstdio_printf(&ntstdio, "%2d: ", scount);
429 s_show_dns_domain_name(msg, offset);
430 ntstdio_printf(&ntstdio, "\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
431 offset = error;
432 }
433
434 return E_OK;
435}
436
437/*
438 * show_dns_section -- DNS の各セクションを表示する。
439 */
440
441static ER_UINT
442show_dns_section(uint8_t *msg, ER_UINT length, uint_t scount, uint_t offset, char *title)
443{
444 T_RSLV_RR rr;
445 T_IN4_ADDR in4_addr;
446 ER_UINT error;
447 int count, dcount, col;
448 T_IN6_ADDR in6_addr;
449 char temp[30];
450 int pos;
451
452 ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount);
453 for (count = 1; count <= scount; count++) {
454 if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
455 return error;
456
457 ntstdio_printf(&ntstdio, "%2d: ", count);
458 s_show_dns_domain_name(msg, offset);
459 ntstdio_printf(&ntstdio, "\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
460 dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
461
462 switch (rr.type) {
463 case DNS_TYPE_A:
464 memcpy((void*)&in4_addr, (void*)(msg + rr.rdata_offset), sizeof(in4_addr));
465 in4_addr = ntohl(in4_addr);
466 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
467 temp[pos] = '\0';
468 ntstdio_printf(&ntstdio, " IPv4 addr: %s\n", temp);
469 break;
470 case DNS_TYPE_NS:
471 ntstdio_printf(&ntstdio, " host: ");
472 s_show_dns_domain_name(msg, rr.rdata_offset);
473 ntstdio_putc(&ntstdio, '\n');
474 break;
475 case DNS_TYPE_CNAME:
476 ntstdio_printf(&ntstdio, " host: ");
477 s_show_dns_domain_name(msg, rr.rdata_offset);
478 ntstdio_putc(&ntstdio, '\n');
479 break;
480 case DNS_TYPE_SOA:
481 show_dns_soa(msg, length, rr.rdata_offset);
482 break;
483 case DNS_TYPE_PTR:
484 ntstdio_printf(&ntstdio, " PTR: ");
485 s_show_dns_domain_name(msg, rr.rdata_offset);
486 ntstdio_putc(&ntstdio, '\n');
487 break;
488 case DNS_TYPE_AAAA:
489 memcpy((void*)&in6_addr, (void*)(msg + rr.rdata_offset), sizeof(in6_addr));
490 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
491 temp[pos] = '\0';
492 ntstdio_printf(&ntstdio, " IPv6 addr: %s\n", temp);
493 break;
494 default:
495 ntstdio_printf(&ntstdio, " data: ");
496 col = 32;
497 for (dcount = 0; dcount < rr.rdlength; dcount++) {
498 ntstdio_printf(&ntstdio, "%02x", *(msg + rr.rdata_offset + dcount));
499 if (--col == 0) {
500 ntstdio_printf(&ntstdio, "\n ");
501 col = 32;
502 }
503 }
504 ntstdio_putc(&ntstdio, '\n');
505 break;
506 }
507 }
508
509 return E_OK;
510}
511/*
512 * dns_info -- DNS 情報の表示
513 */
514
515static void dns_info()
516{
517#if defined(SUPPORT_INET6)
518 T_IN6_ADDR in6_addr;
519#endif
520#if defined(SUPPORT_INET4)
521 T_IN4_ADDR in4_addr;
522#endif
523 char temp[30];
524 int pos;
525
526#if defined(SUPPORT_INET6)
527
528 ntstdio_printf(&ntstdio, "domain name: %s\n", dns_in6_get_dname());
529
530#else /* of #if defined(SUPPORT_INET6) */
531
532 ntstdio_printf(&ntstdio, "domain name: %s\n", dns_in4_get_dname());
533
534#endif /* of #if defined(SUPPORT_INET6) */
535
536#if defined(SUPPORT_INET6)
537 dns_in6_get_addr(&in6_addr);
538 ntstdio_printf(&ntstdio, "IPv6 DNS server: ");
539 if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
540 ntstdio_printf(&ntstdio, "not available.\n");
541 else {
542 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
543 temp[pos] = '\0';
544 ntstdio_printf(&ntstdio, "%s.\n", temp);
545 }
546#endif /* of #if defined(SUPPORT_INET6) */
547
548#if defined(SUPPORT_INET4)
549 dns_in4_get_addr(&in4_addr);
550 ntstdio_printf(&ntstdio, "IPv4 DNS server: ");
551 if (in4_addr == IPV4_ADDRANY)
552 ntstdio_printf(&ntstdio, "not available.\n");
553 else {
554 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
555 temp[pos] = '\0';
556 ntstdio_printf(&ntstdio, "%s.\n", temp);
557 }
558#endif /* of #if defined(SUPPORT_INET4) */
559}
560
561/*
562 * name_lookup -- ホスト名-IP アドレス変換
563 */
564
565const char *rcode_str[] = {
566 "no error",
567 "format error",
568 "server error",
569 "name error",
570 "not implement",
571 "refused",
572};
573
574int usrcmd_dnsc(int argc, char **argv)
575{
576 char *line = argv[1];
577 static char hostname[DBG_LINE_SIZE + 1];
578
579 T_RSLV_DNS_MSG rslv;
580 ER_UINT length, offset;
581 ER error;
582 uint_t flags = 0;
583 uint8_t *msg;
584
585 if (ntlibc_strcmp(line, "info") == 0) {
586 dns_info();
587 return 0;
588 }
589
590 /* コマンドのオプションを設定する。*/
591 line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
592 if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) {
593 ntstdio_printf(&ntstdio, "DNS server not available.\n");
594 return 0;
595 }
596
597 /* 照会するホスト名・IP アドレスを解析する。*/
598 resolv_hoststr(&flags, hostname, sizeof(hostname), line);
599
600 /* 正引きでも逆引きでもプロトコル上は正引きを指定する。*/
601 flags |= DNS_LUP_OPCODE_FORWARD;
602
603 /* IPv6 アドレス、または IPv4 アドレスが指定された時は、照会タイプは PTR に設定する。*/
604 if (((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV6) ||
605 ((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV4))
606 flags = (flags & ~DNS_LUP_FLAGS_QTYPE_MASK) | DNS_LUP_FLAGS_QTYPE_PTR;
607
608 if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) {
609 ntstdio_printf(&ntstdio, "get buffer error: %s.\n", itron_strerror(error));
610 return 0;
611 }
612
613 if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) {
614 //ntstdio_printf(&ntstdio, "error: %s.\n", itron_strerror(length));
615 goto err_ret;
616 }
617
618 dly_tsk(1 * 1000);
619 ntstdio_printf(&ntstdio, "DNS header: flags: ");
620 if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
621 DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) {
622 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
623 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
624 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
625 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
626 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
627 ntstdio_printf(&ntstdio, " ");
628 }
629 ntstdio_printf(&ntstdio, "opcode: ");
630 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
631 ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
632 ntstdio_printf(&ntstdio, ", rcode: %s.\n",
633 (rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
634 ? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
635
636 if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) {
637 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
638 }
639 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) {
640 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
641 }
642 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) {
643 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
644 }
645 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) {
646 ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
647 }
648
649err_ret:
650 if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK)
651 ntstdio_printf(&ntstdio, "release buffer error: %s.\n", itron_strerror(error));
652 return 0;
653}
654
655int usrcmd_ntpc(int argc, char **argv)
656{
657 ntp_cli_execute();
658 return 0;
659}
Note: See TracBrowser for help on using the repository browser.