1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: net_cons.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * ãããã¯ã¼ã¯çµç±ã³ã³ã½ã¼ã«å
|
---|
48 | ¥åºå
|
---|
49 | */
|
---|
50 |
|
---|
51 | #include <stdarg.h>
|
---|
52 | #include <string.h>
|
---|
53 |
|
---|
54 | #ifdef TARGET_KERNEL_ASP
|
---|
55 |
|
---|
56 | #include <kernel.h>
|
---|
57 | #include <sil.h>
|
---|
58 | #include <syssvc/serial.h>
|
---|
59 | #include <syssvc/logtask.h>
|
---|
60 | #include <t_syslog.h>
|
---|
61 | #include "kernel_cfg.h"
|
---|
62 | #include "tinet_cfg.h"
|
---|
63 |
|
---|
64 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
65 |
|
---|
66 | #ifdef TARGET_KERNEL_JSP
|
---|
67 |
|
---|
68 | #include <s_services.h>
|
---|
69 | #include <t_services.h>
|
---|
70 | #include "kernel_id.h"
|
---|
71 | #include "tinet_id.h"
|
---|
72 |
|
---|
73 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
74 |
|
---|
75 | #include <tinet_defs.h>
|
---|
76 |
|
---|
77 | #include <net/if.h>
|
---|
78 | #include <net/if_ppp.h>
|
---|
79 | #include <net/if_loop.h>
|
---|
80 | #include <net/ethernet.h>
|
---|
81 | #include <net/net.h>
|
---|
82 | #include <net/net_timer.h>
|
---|
83 |
|
---|
84 | #include <netinet/in.h>
|
---|
85 | #include <netinet/in_itron.h>
|
---|
86 |
|
---|
87 | #include <netapp/netapp.h>
|
---|
88 | #include <netapp/netapp_var.h>
|
---|
89 | #include <netapp/net_cons.h>
|
---|
90 |
|
---|
91 | #ifdef USE_NET_CONS
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * ãã¯ãå®ç¾©
|
---|
95 | */
|
---|
96 |
|
---|
97 | /* ãªãã¼ã ã®è§£é¤ */
|
---|
98 |
|
---|
99 | #undef syslog
|
---|
100 | #undef serial_rea_dat
|
---|
101 | #undef serial_ctl_por
|
---|
102 |
|
---|
103 | #define EOF (-1)
|
---|
104 |
|
---|
105 | /* TELNET ãªãã·ã§ã³ */
|
---|
106 |
|
---|
107 | #define TELNET_OPT_SE (240)
|
---|
108 | #define TELNET_OPT_NOP (241)
|
---|
109 | #define TELNET_OPT_DM (242)
|
---|
110 | #define TELNET_OPT_BRK (243)
|
---|
111 | #define TELNET_OPT_IP (244)
|
---|
112 | #define TELNET_OPT_AO (245)
|
---|
113 | #define TELNET_OPT_AYT (246)
|
---|
114 | #define TELNET_OPT_EC (247)
|
---|
115 | #define TELNET_OPT_EL (248)
|
---|
116 | #define TELNET_OPT_GA (249)
|
---|
117 | #define TELNET_OPT_SB (250)
|
---|
118 | #define TELNET_OPT_WILL (251)
|
---|
119 | #define TELNET_OPT_WONT (252)
|
---|
120 | #define TELNET_OPT_DO (253)
|
---|
121 | #define TELNET_OPT_DONT (254)
|
---|
122 | #define TELNET_OPT_IAC (255)
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * å¤æ°
|
---|
126 | */
|
---|
127 |
|
---|
128 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
129 |
|
---|
130 | uint8_t net_cons_swbuf[NET_CONS_SWBUF_SIZE];
|
---|
131 | uint8_t net_cons_rwbuf[NET_CONS_RWBUF_SIZE];
|
---|
132 |
|
---|
133 | bool_t connected = false; /* ã³ãã¯ã·ã§ã³ã®ç¶æ
|
---|
134 | */
|
---|
135 | bool_t wait_accept = false; /* æ¥ç¶è¦æ±å¾
|
---|
136 | ã¡ä¸ */
|
---|
137 |
|
---|
138 | #if defined(SUPPORT_INET4)
|
---|
139 |
|
---|
140 | T_IPV4EP dst;
|
---|
141 |
|
---|
142 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
143 |
|
---|
144 | #if defined(SUPPORT_INET6)
|
---|
145 |
|
---|
146 | T_IPV6EP dst;
|
---|
147 |
|
---|
148 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
149 |
|
---|
150 | uint8_t *snd_buff = NULL;
|
---|
151 | uint8_t *rcv_buff = NULL;
|
---|
152 | uint_t snd_off = 0;
|
---|
153 | uint_t rcv_off = 0;
|
---|
154 | uint_t net_ioctl = IOCTL_NULL;
|
---|
155 | ER_UINT snd_len = 0;
|
---|
156 | ER_UINT rcv_len = 0;
|
---|
157 |
|
---|
158 | /*
|
---|
159 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
160 | */
|
---|
161 |
|
---|
162 | ER
|
---|
163 | callback_nblk_net_cons (ID cepid, FN fncd, void *p_parblk)
|
---|
164 | {
|
---|
165 | ER error = E_OK;
|
---|
166 | SYSTIM now;
|
---|
167 |
|
---|
168 | switch (fncd) {
|
---|
169 |
|
---|
170 | case TFN_TCP_ACP_CEP:
|
---|
171 | get_tim(&now);
|
---|
172 | if (*(ER*)p_parblk == E_OK) {
|
---|
173 | syslog(LOG_NOTICE, "[NCS:%02u CBN] connected: %6lu, from: %s.%u",
|
---|
174 | cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
175 | connected = true;
|
---|
176 | }
|
---|
177 | else
|
---|
178 | syslog(LOG_NOTICE, "[NCS:%02d CBN] error: %s", itron_strerror(*(ER*)p_parblk));
|
---|
179 | snd_len = snd_off = rcv_len = rcv_off = 0;
|
---|
180 | wait_accept = false;
|
---|
181 | break;
|
---|
182 |
|
---|
183 | case TFN_TCP_CLS_CEP:
|
---|
184 | case TFN_TCP_RCV_BUF:
|
---|
185 | case TFN_TCP_GET_BUF:
|
---|
186 | case TFN_TCP_RCV_DAT:
|
---|
187 | case TFN_TCP_SND_DAT:
|
---|
188 | case TFN_TCP_CON_CEP:
|
---|
189 | case TFN_TCP_SND_OOB:
|
---|
190 | default:
|
---|
191 | error = E_PAR;
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | return error;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * éä¿¡ãããã¡ã®ãã©ãã·ã¥
|
---|
199 | */
|
---|
200 |
|
---|
201 | void
|
---|
202 | flush_snd_buff (void)
|
---|
203 | {
|
---|
204 | ER_UINT error;
|
---|
205 |
|
---|
206 | if (connected) {
|
---|
207 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
208 | if (snd_off > 0) {
|
---|
209 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK && error != E_CLS)
|
---|
210 | syslog(LOG_NOTICE, "[NCS:%02d SND] flush send error: %s",
|
---|
211 | NET_CONS_CEPID, itron_strerror(error));
|
---|
212 | snd_len = snd_off = 0;
|
---|
213 | }
|
---|
214 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
215 | }
|
---|
216 | return;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * æåéä¿¡
|
---|
221 | */
|
---|
222 |
|
---|
223 | void
|
---|
224 | cons_putchar (ID portid, char ch)
|
---|
225 | {
|
---|
226 | ER_UINT error;
|
---|
227 |
|
---|
228 | if (connected) {
|
---|
229 | if (ch == '\n' && (net_ioctl & IOCTL_CRLF) != 0)
|
---|
230 | cons_putchar(portid, '\r');
|
---|
231 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
232 | if (snd_off >= snd_len) {
|
---|
233 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK) {
|
---|
234 | if (error != E_CLS)
|
---|
235 | syslog(LOG_NOTICE, "[NCS:%02d SND] send buff error: %s",
|
---|
236 | NET_CONS_CEPID, itron_strerror(error));
|
---|
237 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
238 | return;
|
---|
239 | }
|
---|
240 | snd_off = 0;
|
---|
241 | if ((snd_len = tcp_get_buf(NET_CONS_CEPID, (void*)&snd_buff, TMO_FEVR)) <= 0) {
|
---|
242 | if (snd_len != E_CLS)
|
---|
243 | syslog(LOG_NOTICE, "[NCS:%02d SND] get buff error: %s",
|
---|
244 | NET_CONS_CEPID, itron_strerror(snd_len));
|
---|
245 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
246 | return;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | snd_buff[snd_off ++] = ch;
|
---|
250 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
251 | }
|
---|
252 | else
|
---|
253 | serial_wri_dat(portid, &ch, sizeof(ch));
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * æååä¿¡ï¼å¤æãªãï¼
|
---|
258 | */
|
---|
259 |
|
---|
260 | static int_t
|
---|
261 | cons_getchar_raw (void)
|
---|
262 | {
|
---|
263 | ER error = E_OK;
|
---|
264 |
|
---|
265 | if (connected) {
|
---|
266 | if (rcv_off >= rcv_len) {
|
---|
267 | rcv_off = 0;
|
---|
268 | if ((error = tcp_rel_buf(NET_CONS_CEPID, rcv_len)) != E_OK) {
|
---|
269 | if (error != E_CLS)
|
---|
270 | syslog(LOG_NOTICE, "[NCS:%02d RCV] release buff error: %s",
|
---|
271 | NET_CONS_CEPID, itron_strerror(error));
|
---|
272 | discon_net_cons();
|
---|
273 | return EOF;
|
---|
274 | }
|
---|
275 | if ((rcv_len = tcp_rcv_buf(NET_CONS_CEPID, (void*)&rcv_buff, TMO_FEVR)) == 0) {
|
---|
276 | discon_net_cons();
|
---|
277 | return EOF;
|
---|
278 | }
|
---|
279 | else if (rcv_len < 0) {
|
---|
280 | if (rcv_len != E_CLS)
|
---|
281 | syslog(LOG_NOTICE, "[NCS:%02d RCV] recieve buff error: %s",
|
---|
282 | NET_CONS_CEPID, itron_strerror(rcv_len));
|
---|
283 | discon_net_cons();
|
---|
284 | return EOF;
|
---|
285 | }
|
---|
286 | }
|
---|
287 | return rcv_buff[rcv_off ++];
|
---|
288 | }
|
---|
289 | else
|
---|
290 | return EOF;
|
---|
291 | }
|
---|
292 |
|
---|
293 | /*
|
---|
294 | * æååä¿¡ï¼TELNET ãªãã·ã§ã³ãã¹ãããï¼
|
---|
295 | */
|
---|
296 |
|
---|
297 | int_t
|
---|
298 | cons_getchar (ID portid)
|
---|
299 | {
|
---|
300 | T_SERIAL_RPOR rpor;
|
---|
301 | int_t ch, req;
|
---|
302 | char uch;
|
---|
303 | ER error;
|
---|
304 |
|
---|
305 | if (!wait_accept && !connected) {
|
---|
306 | wait_accept = true;
|
---|
307 | error = TCP_ACP_CEP(NET_CONS_CEPID, NET_CONS_REPID, &dst, TMO_NBLK);
|
---|
308 | #if 0
|
---|
309 | syslog(LOG_NOTICE, "[NCS:%02d ACP] status: %s",NET_CONS_CEPID, itron_strerror(error));
|
---|
310 | #endif
|
---|
311 | if (error != E_WBLK)
|
---|
312 | return EOF;
|
---|
313 | }
|
---|
314 |
|
---|
315 | while (true) {
|
---|
316 | if (connected) {
|
---|
317 | while ((ch = cons_getchar_raw()) == TELNET_OPT_IAC || ch == '\0') {
|
---|
318 | if (ch != '\0') {
|
---|
319 | switch (ch = cons_getchar_raw()) {
|
---|
320 | case TELNET_OPT_WILL:
|
---|
321 | case TELNET_OPT_WONT:
|
---|
322 | case TELNET_OPT_DO:
|
---|
323 | case TELNET_OPT_DONT:
|
---|
324 | req = cons_getchar_raw();
|
---|
325 | break;
|
---|
326 | case TELNET_OPT_SB:
|
---|
327 | while ((ch = cons_getchar_raw()) != EOF && ch != TELNET_OPT_IAC) {
|
---|
328 | if ((ch = cons_getchar_raw()) == EOF || ch == TELNET_OPT_SE)
|
---|
329 | break;
|
---|
330 | }
|
---|
331 | break;
|
---|
332 | default:
|
---|
333 | break;
|
---|
334 | }
|
---|
335 | }
|
---|
336 | }
|
---|
337 | if (ch != '\n') {
|
---|
338 | if ((net_ioctl & IOCTL_ECHO) != 0 && ch != EOF) {
|
---|
339 | cons_putchar(portid, ch);
|
---|
340 | flush_snd_buff();
|
---|
341 | }
|
---|
342 | return ch;
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 | else if (serial_ref_por(portid, &rpor) == E_OK && rpor.reacnt > 0) {
|
---|
347 | if (serial_rea_dat(portid, &uch, sizeof(uch)) > 0)
|
---|
348 | return uch;
|
---|
349 | else
|
---|
350 | return EOF;
|
---|
351 | }
|
---|
352 | dly_tsk(100);
|
---|
353 | }
|
---|
354 | return EOF;
|
---|
355 | }
|
---|
356 |
|
---|
357 | /*
|
---|
358 | * ã³ãã¯ã·ã§ã³ãåæ
|
---|
359 | */
|
---|
360 |
|
---|
361 | ER
|
---|
362 | discon_net_cons (void)
|
---|
363 | {
|
---|
364 | ER error = E_OK;
|
---|
365 | SYSTIM now;
|
---|
366 |
|
---|
367 | if (connected) {
|
---|
368 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
369 | if (snd_off > 0) {
|
---|
370 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK && error != E_CLS)
|
---|
371 | syslog(LOG_NOTICE, "[NCS:%02d SND] send buff error: %s",
|
---|
372 | NET_CONS_CEPID, itron_strerror(error));
|
---|
373 | }
|
---|
374 | if ((error = tcp_sht_cep(NET_CONS_CEPID)) != E_OK)
|
---|
375 | syslog(LOG_NOTICE, "[NCS:%02d SHT] shutdown error: %s",
|
---|
376 | NET_CONS_CEPID, itron_strerror(error));
|
---|
377 | if ((error = tcp_cls_cep(NET_CONS_CEPID, TMO_FEVR)) != E_OK)
|
---|
378 | syslog(LOG_NOTICE, "[NCS:%02d CLS] close error: %s",
|
---|
379 | NET_CONS_CEPID, itron_strerror(error));
|
---|
380 | connected = false;
|
---|
381 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
382 | get_tim(&now);
|
---|
383 | syslog(LOG_NOTICE, "[NCS:%02u SND] disconnected:%5lu, from: %s.%u",
|
---|
384 | NET_CONS_CEPID, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
385 | }
|
---|
386 | return error;
|
---|
387 | }
|
---|
388 |
|
---|
389 | /*
|
---|
390 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡
|
---|
391 | */
|
---|
392 |
|
---|
393 | ER
|
---|
394 | net_serial_ctl_por (ID portid, uint_t ioctl)
|
---|
395 | {
|
---|
396 | net_ioctl = ioctl;
|
---|
397 | return serial_ctl_por(portid, ioctl);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /*
|
---|
401 | * ãã°åºå
|
---|
402 | */
|
---|
403 |
|
---|
404 | ER
|
---|
405 | net_syslog (uint_t prio, const char *format, ...)
|
---|
406 | {
|
---|
407 | #if defined(SUPPORT_INET4)
|
---|
408 | T_IN4_ADDR *addr;
|
---|
409 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
410 |
|
---|
411 | ulong_t val;
|
---|
412 | SYSLOG log;
|
---|
413 | va_list ap;
|
---|
414 | char padchar, *str;
|
---|
415 | int_t ch, width, left, i;
|
---|
416 | bool_t longflag;
|
---|
417 |
|
---|
418 | if (connected) {
|
---|
419 | syscall(wai_sem(SEM_NET_CONS_PRINTF));
|
---|
420 | va_start(ap, format);
|
---|
421 | while ((ch = *format ++) != '\0') {
|
---|
422 | if (ch != '%') { /* æ¸å¼æå®ä»¥å¤ */
|
---|
423 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
424 | continue;
|
---|
425 | }
|
---|
426 |
|
---|
427 | width = 0;
|
---|
428 | longflag = false;
|
---|
429 | padchar = ' ';
|
---|
430 |
|
---|
431 | if (ch == '-') { /* 左詰ã */
|
---|
432 | format ++;
|
---|
433 | left = -1;
|
---|
434 | }
|
---|
435 | else
|
---|
436 | left = 1;
|
---|
437 |
|
---|
438 | if ((ch = *format ++) == '0') { /* ä¸ä½æ¡ã® 0 */
|
---|
439 | padchar = '0';
|
---|
440 | ch = *format ++;
|
---|
441 | }
|
---|
442 |
|
---|
443 | while ('0' <= ch && ch <= '9') { /* åºåå¹
|
---|
444 | */
|
---|
445 | width = width * 10 + ch - '0';
|
---|
446 | ch = *format ++;
|
---|
447 | }
|
---|
448 |
|
---|
449 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
450 | longflag = true;
|
---|
451 | ch = *format ++;
|
---|
452 | }
|
---|
453 |
|
---|
454 | switch (ch) {
|
---|
455 | case 'd':
|
---|
456 | val = longflag ? (ulong_t)va_arg(ap, long_t)
|
---|
457 | : (ulong_t)va_arg(ap, int_t);
|
---|
458 | if ((long_t)val >= 0)
|
---|
459 | cons_putnumber(CONSOLE_PORTID, val, 10, radhex, width * left, false, padchar);
|
---|
460 | else
|
---|
461 | cons_putnumber(CONSOLE_PORTID, -val, 10, radhex, width * left, true, padchar);
|
---|
462 | break;
|
---|
463 |
|
---|
464 | case 'u':
|
---|
465 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
466 | : (ulong_t)va_arg(ap, uint_t);
|
---|
467 | cons_putnumber(CONSOLE_PORTID, val, 10, radhex, width * left, false, padchar);
|
---|
468 | break;
|
---|
469 |
|
---|
470 | case 'x':
|
---|
471 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
472 | : (ulong_t)va_arg(ap, uint_t);
|
---|
473 | cons_putnumber(CONSOLE_PORTID, val, 16, radhex, width * left, false, padchar);
|
---|
474 | break;
|
---|
475 |
|
---|
476 | case 'X':
|
---|
477 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
478 | : (ulong_t)va_arg(ap, uint_t);
|
---|
479 | cons_putnumber(CONSOLE_PORTID, val, 16, radHEX, width * left, false, padchar);
|
---|
480 | break;
|
---|
481 |
|
---|
482 | case 'c':
|
---|
483 | ch = va_arg(ap, int_t);
|
---|
484 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
485 | break;
|
---|
486 |
|
---|
487 | case 's':
|
---|
488 | str = va_arg(ap, char*);
|
---|
489 | while ((ch = *str ++) != '\0') {
|
---|
490 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
491 | width --;
|
---|
492 | }
|
---|
493 | while (width -- > 0)
|
---|
494 | cons_putchar(CONSOLE_PORTID, ' ');
|
---|
495 | break;
|
---|
496 |
|
---|
497 | case 'I':
|
---|
498 |
|
---|
499 | #if defined(SUPPORT_INET4)
|
---|
500 |
|
---|
501 | addr = va_arg(ap, T_IN4_ADDR*);
|
---|
502 | put_ipv4addr(CONSOLE_PORTID, addr, width);
|
---|
503 |
|
---|
504 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
505 |
|
---|
506 | #if defined(SUPPORT_INET6)
|
---|
507 |
|
---|
508 | str = va_arg(ap, char*);
|
---|
509 | put_ipv6addr(CONSOLE_PORTID, (T_IN6_ADDR *)str, width);
|
---|
510 |
|
---|
511 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
512 |
|
---|
513 | break;
|
---|
514 |
|
---|
515 | case 'M':
|
---|
516 | str = va_arg(ap, char*);
|
---|
517 | put_macaddr(CONSOLE_PORTID, str, width);
|
---|
518 | break;
|
---|
519 |
|
---|
520 | case '%':
|
---|
521 | cons_putchar(CONSOLE_PORTID, '%');
|
---|
522 | break;
|
---|
523 |
|
---|
524 | case '0':
|
---|
525 | format --;
|
---|
526 | break;
|
---|
527 |
|
---|
528 | default:
|
---|
529 | break;
|
---|
530 | }
|
---|
531 |
|
---|
532 | }
|
---|
533 | va_end(ap);
|
---|
534 | cons_putchar(CONSOLE_PORTID, '\n');
|
---|
535 | flush_snd_buff();
|
---|
536 | syscall(sig_sem(SEM_NET_CONS_PRINTF));
|
---|
537 | return E_OK;
|
---|
538 | }
|
---|
539 | else {
|
---|
540 | log.logtype = LOG_TYPE_COMMENT;
|
---|
541 | log.loginfo[0] = (intptr_t)format;
|
---|
542 | i = 1;
|
---|
543 | va_start(ap, format);
|
---|
544 |
|
---|
545 | while ((ch = *format++) != '\0' && i < TMAX_LOGINFO) {
|
---|
546 | if (ch != '%') {
|
---|
547 | continue;
|
---|
548 | }
|
---|
549 |
|
---|
550 | longflag = false;
|
---|
551 |
|
---|
552 | ch = *format++;
|
---|
553 | while ('0' <= ch && ch <= '9') {
|
---|
554 | ch = *format++;
|
---|
555 | }
|
---|
556 |
|
---|
557 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
558 | longflag = true;
|
---|
559 | ch = *format ++;
|
---|
560 | }
|
---|
561 |
|
---|
562 | switch (ch) {
|
---|
563 | case 'd':
|
---|
564 | log.loginfo[i++] = longflag
|
---|
565 | ? (intptr_t)va_arg(ap, long_t)
|
---|
566 | : (intptr_t)va_arg(ap, int_t);
|
---|
567 | break;
|
---|
568 | case 'u':
|
---|
569 | case 'x':
|
---|
570 | case 'X':
|
---|
571 | log.loginfo[i++] = longflag
|
---|
572 | ? (intptr_t)va_arg(ap, ulong_t)
|
---|
573 | : (intptr_t)va_arg(ap, uint_t);
|
---|
574 | break;
|
---|
575 | case 'p':
|
---|
576 | log.loginfo[i++] = (intptr_t)va_arg(ap, void *);
|
---|
577 | break;
|
---|
578 | case 'c':
|
---|
579 | log.loginfo[i++] = (intptr_t)va_arg(ap, int_t);
|
---|
580 | break;
|
---|
581 | case 's':
|
---|
582 | log.loginfo[i++] = (intptr_t)va_arg(ap, const char *);
|
---|
583 | break;
|
---|
584 | case '\0':
|
---|
585 | format--;
|
---|
586 | break;
|
---|
587 | default:
|
---|
588 | break;
|
---|
589 | }
|
---|
590 | }
|
---|
591 | va_end(ap);
|
---|
592 |
|
---|
593 | #ifdef TARGET_KERNEL_ASP
|
---|
594 |
|
---|
595 | return(syslog_wri_log(prio, &log));
|
---|
596 |
|
---|
597 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
598 |
|
---|
599 | #ifdef TARGET_KERNEL_JSP
|
---|
600 |
|
---|
601 | return(vwri_log(prio, &log));
|
---|
602 |
|
---|
603 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
604 |
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | #endif /* of #ifdef USE_NET_CONS */
|
---|