Changeset 342 for asp3_tinet_ecnl_rx/trunk/ntshell/src/netcmd.c
- Timestamp:
- Apr 27, 2018, 2:26:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/ntshell/src/netcmd.c
r340 r342 73 73 extern void ping4(T_IN4_ADDR *addr, uint_t tmo, uint_t len); 74 74 75 /* 76 * str_num -- cons_printf の数値変換 77 */ 78 79 static void 80 str_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 92 static int 93 str_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 140 int 141 str_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 163 int 164 str_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 222 int 223 str_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 75 239 int usrcmd_ping(int argc, char **argv) 76 240 { 77 int _ttmo, size;241 int tmo, size; 78 242 char apip = DEFAULT_API_PROTO; 79 243 char *line = argv[1]; … … 153 317 ER ret; 154 318 uint32_t expire, renew, rebind; 319 char temp[30]; 320 int pos; 155 321 156 322 if ((ret = dhcp4c_get_info(&svaddr, &expire, &renew, &rebind, &bind_start)) == E_OK) { 157 ntstdio_printf(&ntstdio, "DHCPv4 server: %hI,\n", &svaddr); 323 pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0); 324 temp[pos] = '\0'; 325 ntstdio_printf(&ntstdio, "DHCPv4 server: %s,\n", temp); 158 326 ntstdio_printf(&ntstdio, " Renew: %u:%02u:%02u,\n", 159 327 renew / 3600, (renew / 60) % 60, renew % 60); … … 279 447 int count, dcount, col; 280 448 T_IN6_ADDR in6_addr; 449 char temp[30]; 450 int pos; 281 451 282 452 ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount); … … 294 464 memcpy((void*)&in4_addr, (void*)(msg + rr.rdata_offset), sizeof(in4_addr)); 295 465 in4_addr = ntohl(in4_addr); 296 ntstdio_printf(&ntstdio, " IPv4 addr: %hI\n", &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); 297 469 break; 298 470 case DNS_TYPE_NS: … … 316 488 case DNS_TYPE_AAAA: 317 489 memcpy((void*)&in6_addr, (void*)(msg + rr.rdata_offset), sizeof(in6_addr)); 318 ntstdio_printf(&ntstdio, " IPv6 addr: %lI\n", &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); 319 493 break; 320 494 default: … … 347 521 T_IN4_ADDR in4_addr; 348 522 #endif 523 char temp[30]; 524 int pos; 349 525 350 526 #if defined(SUPPORT_INET6) … … 363 539 if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr)) 364 540 ntstdio_printf(&ntstdio, "not available.\n"); 365 else 366 ntstdio_printf(&ntstdio, "%lI.\n", &in6_addr); 541 else { 542 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0); 543 temp[pos] = '\0'; 544 ntstdio_printf(&ntstdio, "%s.\n", temp); 545 } 367 546 #endif /* of #if defined(SUPPORT_INET6) */ 368 547 … … 372 551 if (in4_addr == IPV4_ADDRANY) 373 552 ntstdio_printf(&ntstdio, "not available.\n"); 374 else 375 ntstdio_printf(&ntstdio, "%hI.\n", &in4_addr); 553 else { 554 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0); 555 temp[pos] = '\0'; 556 ntstdio_printf(&ntstdio, "%s.\n", temp); 557 } 376 558 #endif /* of #if defined(SUPPORT_INET4) */ 377 559 }
Note:
See TracChangeset
for help on using the changeset viewer.