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 | * ä¸è¨èä½æ¨©è
|
---|
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$
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * UDP4 ECHO ã¯ã©ã¤ã¢ã³ã
|
---|
48 | */
|
---|
49 |
|
---|
50 | #include <string.h>
|
---|
51 |
|
---|
52 | #if defined(TARGET_KERNEL_ASP)
|
---|
53 |
|
---|
54 | #include <kernel.h>
|
---|
55 | #include <sil.h>
|
---|
56 | #include <t_syslog.h>
|
---|
57 | #include "kernel_cfg.h"
|
---|
58 |
|
---|
59 | #endif /* of #if defined(TARGET_KERNEL_ASP) */
|
---|
60 |
|
---|
61 | #if defined(TARGET_KERNEL_JSP)
|
---|
62 |
|
---|
63 | #include <t_services.h>
|
---|
64 | #include "kernel_id.h"
|
---|
65 | #include "tinet_id.h"
|
---|
66 |
|
---|
67 | #endif /* of #if defined(TARGET_KERNEL_JSP) */
|
---|
68 |
|
---|
69 | #include <netinet/in.h>
|
---|
70 | #include <netinet/in_itron.h>
|
---|
71 |
|
---|
72 | #include <netapp/netapp.h>
|
---|
73 | #include <netapp/netapp_var.h>
|
---|
74 | #include <netapp/udp4_echo_cli.h>
|
---|
75 |
|
---|
76 | #if defined(USE_UDP4_ECHO_CLI_TSK)
|
---|
77 |
|
---|
78 | /* echo ãµã¼ãã®ãã¼ãçªå· */
|
---|
79 |
|
---|
80 | #define ECHO_SRV_PORTNO UINT_C(7)
|
---|
81 |
|
---|
82 | /* éä¿¡éé */
|
---|
83 |
|
---|
84 | #if defined(TOPPERS_S810_CLG3_85)
|
---|
85 |
|
---|
86 | #define SLP_ITV (30*SYSTIM_HZ)
|
---|
87 |
|
---|
88 | #else /* of #if defined(TOPPERS_S810_CLG3_85) */
|
---|
89 |
|
---|
90 | #define SLP_ITV (60*SYSTIM_HZ)
|
---|
91 |
|
---|
92 | #endif /* of #if defined(TOPPERS_S810_CLG3_85) */
|
---|
93 |
|
---|
94 | /* èªåå®è¡ */
|
---|
95 |
|
---|
96 | #if defined(UDP4_ECHO_CLI_AUTO_RUN_STR)
|
---|
97 | #else
|
---|
98 | #if 0
|
---|
99 | #define UDP4_ECHO_CLI_AUTO_RUN_STR "172.25.193.140 - 1000"
|
---|
100 | #endif
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * å
|
---|
105 | ¨åå¤æ°
|
---|
106 | */
|
---|
107 |
|
---|
108 | bool_t udp4_echo_cli_valid;
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * å¤æ°
|
---|
112 | */
|
---|
113 |
|
---|
114 | #define BUF_SIZE 2048
|
---|
115 |
|
---|
116 | static char udp_buf[BUF_SIZE];
|
---|
117 | static T_IPV4EP dst;
|
---|
118 |
|
---|
119 | #if defined(USE_UDP_NON_BLOCKING)
|
---|
120 |
|
---|
121 | static ER_UINT nblk_len;
|
---|
122 | static ID nblk_tskid;
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
126 | */
|
---|
127 |
|
---|
128 | ER
|
---|
129 | callback_nblk_udp4_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
130 | {
|
---|
131 | nblk_len = *(ER_UINT*)p_parblk;
|
---|
132 | syscall(wup_tsk(nblk_tskid));
|
---|
133 | return E_OK;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * udp4_echo_cli -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ãã³ããããã³ã°ã³ã¼ã«ä½¿ç¨)ã
|
---|
138 | */
|
---|
139 |
|
---|
140 | ER
|
---|
141 | udp4_echo_cli (ID cepid, T_IN4_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
142 | {
|
---|
143 | ER_UINT error;
|
---|
144 | SYSTIM time;
|
---|
145 | uint_t len;
|
---|
146 |
|
---|
147 | dst.ipaddr = *ipaddr;
|
---|
148 | dst.portno = portno;
|
---|
149 | len = strlen(line);
|
---|
150 | get_tim(&time);
|
---|
151 | get_tid(&nblk_tskid);
|
---|
152 | if ((error = udp_snd_dat(cepid, &dst, line, len, TMO_NBLK)) != E_WBLK) {
|
---|
153 | syslog(LOG_NOTICE, "[UEC4:%02u SND(NBLK)] error: %7lu,%s",
|
---|
154 | cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
|
---|
155 | return error;
|
---|
156 | }
|
---|
157 | else
|
---|
158 | syslog(LOG_NOTICE, "[UEC4:%02u SND(NBLK)] send: %7lu, to: %s.%d\n"
|
---|
159 | " msg: %s",
|
---|
160 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, line);
|
---|
161 |
|
---|
162 | syscall(slp_tsk());
|
---|
163 | get_tim(&time);
|
---|
164 | if (nblk_len < 0) { /* 0 以ä¸ã®å ´åã¯ãã¨ã©ã¼ã³ã¼ã */
|
---|
165 | syslog(LOG_NOTICE, "[UEC4:%02u CBR(NBLK)] error: %7lu,%s",
|
---|
166 | cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
|
---|
167 | return nblk_len;
|
---|
168 | }
|
---|
169 |
|
---|
170 | if ((error = udp_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_NBLK)) != E_WBLK) {
|
---|
171 | syslog(LOG_NOTICE, "[UEC4:%02u RCV(NBLK)] error: %7lu,%s",
|
---|
172 | cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
|
---|
173 | return error;
|
---|
174 | }
|
---|
175 |
|
---|
176 | syscall(slp_tsk());
|
---|
177 | get_tim(&time);
|
---|
178 | if (nblk_len < 0) { /* 0 以ä¸ã®å ´åã¯ãã¨ã©ã¼ã³ã¼ã */
|
---|
179 | syslog(LOG_NOTICE, "[UEC4:%02u RCV(NBLK)] error: %7lu,%s",
|
---|
180 | cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
|
---|
181 | return nblk_len;
|
---|
182 | }
|
---|
183 | else {
|
---|
184 | udp_buf[nblk_len] = '\0';
|
---|
185 | get_tim(&time);
|
---|
186 | syslog(LOG_NOTICE, "[UEC4:%02u RCV(NBLK)] recv: %7lu,from: %s.%d\n"
|
---|
187 | " msg: %s",
|
---|
188 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, udp_buf);
|
---|
189 | nblk_len = E_OK;
|
---|
190 | }
|
---|
191 |
|
---|
192 | return nblk_len;
|
---|
193 | }
|
---|
194 |
|
---|
195 | #else /* of #if defined(USE_UDP_NON_BLOCKING) */
|
---|
196 |
|
---|
197 | #if defined(USE_UDP_CALL_BACK)
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * ã³ã¼ã«ããã¯é¢æ°
|
---|
201 | */
|
---|
202 |
|
---|
203 | ER
|
---|
204 | callback_udp4_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
205 | {
|
---|
206 | SYSTIM time;
|
---|
207 | ER_UINT len;
|
---|
208 |
|
---|
209 | get_tim(&time);
|
---|
210 | if ((len = udp_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_FEVR)) >= 0) {
|
---|
211 | *(udp_buf + len) = '\0';
|
---|
212 | syslog(LOG_NOTICE, "[UEC4:%02u RCV(CB)] recv: %7lu,from: %s.%d\n"
|
---|
213 | " msg: %s",
|
---|
214 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, udp_buf);
|
---|
215 | }
|
---|
216 | else
|
---|
217 | syslog(LOG_NOTICE, "[UEC4:%02u RCV(CB)] error: %7lu,%s",
|
---|
218 | cepid, time / SYSTIM_HZ, itron_strerror(len));
|
---|
219 |
|
---|
220 | return E_OK;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * udp4_echo_cli -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ã³ã¼ã«ããã¯é¢æ°ä½¿ç¨)ã
|
---|
225 | */
|
---|
226 |
|
---|
227 | ER
|
---|
228 | udp4_echo_cli (ID cepid, T_IN4_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
229 | {
|
---|
230 | SYSTIM time;
|
---|
231 | ER_UINT len;
|
---|
232 |
|
---|
233 | dst.ipaddr = *ipaddr;
|
---|
234 | dst.portno = portno;
|
---|
235 | len = strlen(line);
|
---|
236 | get_tim(&time);
|
---|
237 | syslog(LOG_NOTICE, "[UEC4:%02u SND(CB)] send: %7lu, to: %s.%d\n"
|
---|
238 | " msg: %s",
|
---|
239 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, line);
|
---|
240 | if ((len = udp_snd_dat(cepid, &dst, line, len, TMO_FEVR)) < 0)
|
---|
241 | syslog(LOG_NOTICE, "[UEC4:%02u SND(CB)] error: %7lu,%s",
|
---|
242 | cepid, time / SYSTIM_HZ, itron_strerror(len));
|
---|
243 |
|
---|
244 | return E_OK;
|
---|
245 | }
|
---|
246 |
|
---|
247 | #else /* of #if defined(USE_UDP_CALL_BACK) */
|
---|
248 |
|
---|
249 | /*
|
---|
250 | * udp4_echo_cli -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ã³ã¼ã«ããã¯é¢æ°æªä½¿ç¨)ã
|
---|
251 | */
|
---|
252 |
|
---|
253 | ER
|
---|
254 | udp4_echo_cli (ID cepid, T_IN4_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
255 | {
|
---|
256 | SYSTIM time;
|
---|
257 | ER_UINT len;
|
---|
258 |
|
---|
259 | dst.ipaddr = *ipaddr;
|
---|
260 | dst.portno = portno;
|
---|
261 | len = strlen(line);
|
---|
262 | get_tim(&time);
|
---|
263 | syslog(LOG_NOTICE, "[UEC4:%02u SND] send: %7lu, to: %s.%d\n"
|
---|
264 | " msg: %s",
|
---|
265 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, line);
|
---|
266 | if ((len = udp_snd_dat(cepid, &dst, line, len, TMO_FEVR)) < 0) {
|
---|
267 | syslog(LOG_NOTICE, "[UEC4:%02u SND] error: %7lu,%s",
|
---|
268 | cepid, time / SYSTIM_HZ, itron_strerror(len));
|
---|
269 | return len;
|
---|
270 | }
|
---|
271 |
|
---|
272 | if ((len = udp_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), 10*1000)) >= 0) {
|
---|
273 | *(udp_buf + len) = '\0';
|
---|
274 | get_tim(&time);
|
---|
275 | syslog(LOG_NOTICE, "[UEC4:%02u RCV] recv: %7lu,from: %s.%d\n"
|
---|
276 | " msg: %s",
|
---|
277 | cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, udp_buf);
|
---|
278 | return E_OK;
|
---|
279 | }
|
---|
280 | else {
|
---|
281 | get_tim(&time);
|
---|
282 | syslog(LOG_NOTICE, "[UEC4:%02u RCV] error: %7lu,%s",
|
---|
283 | cepid, time / SYSTIM_HZ, itron_strerror(len));
|
---|
284 | return len;
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | #endif /* of #if defined(USE_UDP_CALL_BACK) */
|
---|
289 |
|
---|
290 | #endif /* of #if defined(USE_UDP_NON_BLOCKING) */
|
---|
291 |
|
---|
292 | /*
|
---|
293 | * getcomd -- ã³ãã³ããå¾ãã
|
---|
294 | */
|
---|
295 |
|
---|
296 | #if defined(UDP4_ECHO_CLI_AUTO_RUN_STR)
|
---|
297 |
|
---|
298 | static char *
|
---|
299 | getcomd (ID cepid, bool_t retry)
|
---|
300 | {
|
---|
301 | ER error;
|
---|
302 | char *line = NULL;
|
---|
303 | static char auto_run_str[] = UDP4_ECHO_CLI_AUTO_RUN_STR;
|
---|
304 | static int_t count = 0;
|
---|
305 |
|
---|
306 | if (retry || count == 0) {
|
---|
307 | line = auto_run_str;
|
---|
308 | dly_tsk(6 * 1000);
|
---|
309 | }
|
---|
310 | else {
|
---|
311 | while ((error = rcv_dtq(DTQ_UDP4_ECHO_CLI, (intptr_t*)&line)) != E_OK) {
|
---|
312 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] error:%s", cepid, itron_strerror(error));
|
---|
313 | dly_tsk(SLP_ITV);
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | count ++;
|
---|
318 | return line;
|
---|
319 | }
|
---|
320 |
|
---|
321 | #else /* of #if defined(UDP4_ECHO_CLI_AUTO_RUN_STR) */
|
---|
322 |
|
---|
323 | static char *
|
---|
324 | getcomd (ID cepid, bool_t retry)
|
---|
325 | {
|
---|
326 | ER error;
|
---|
327 | char *line = NULL;
|
---|
328 |
|
---|
329 | while ((error = rcv_dtq(DTQ_UDP4_ECHO_CLI, (intptr_t*)&line)) != E_OK) {
|
---|
330 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] error:%s", cepid, itron_strerror(error));
|
---|
331 | dly_tsk(SLP_ITV);
|
---|
332 | }
|
---|
333 | return line;
|
---|
334 | }
|
---|
335 |
|
---|
336 | #endif /* of #if defined(UDP4_ECHO_CLI_AUTO_RUN_STR) */
|
---|
337 |
|
---|
338 | #define MESSAGE_FORMAT "MSG 1000000"
|
---|
339 |
|
---|
340 | /*
|
---|
341 | * UDP4 ECHO ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
342 | */
|
---|
343 |
|
---|
344 | void
|
---|
345 | udp4_echo_cli_task (intptr_t exinf)
|
---|
346 | {
|
---|
347 | static char msg[sizeof(MESSAGE_FORMAT)] = MESSAGE_FORMAT;
|
---|
348 |
|
---|
349 | ID tskid, cepid;
|
---|
350 | ER error = E_OK;
|
---|
351 | SYSTIM time;
|
---|
352 | T_IN4_ADDR addr;
|
---|
353 |
|
---|
354 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
355 | T_IN6_ADDR addr6;
|
---|
356 | #endif
|
---|
357 |
|
---|
358 | char *line, *p;
|
---|
359 | int_t rep;
|
---|
360 | uint32_t count, msgno;
|
---|
361 | bool_t retry = false;
|
---|
362 | uint16_t portno = ECHO_SRV_PORTNO;
|
---|
363 |
|
---|
364 | #if defined(USE_UDP_EXTENTIONS)
|
---|
365 | T_UDP_CCEP ccep;
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | dly_tsk(10*1000);
|
---|
369 | get_tid(&tskid);
|
---|
370 | syslog(LOG_NOTICE, "[UDP4 ECHO CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
371 | while (true) {
|
---|
372 | line = skip_blanks(getcomd((ID)exinf, retry));
|
---|
373 |
|
---|
374 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
375 |
|
---|
376 | line = lookup_ipaddr(&addr6, line, API_PROTO_IPV4);
|
---|
377 | if (line == NULL || !in6_is_addr_ipv4mapped(&addr6)) {
|
---|
378 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] sleep %d.%03u[s], unknown host.",
|
---|
379 | (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
|
---|
380 | dly_tsk(SLP_ITV);
|
---|
381 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] resume.", (ID)exinf);
|
---|
382 | retry = true;
|
---|
383 | continue;
|
---|
384 | }
|
---|
385 | addr = ntohl(addr6.s6_addr32[3]);
|
---|
386 |
|
---|
387 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
388 |
|
---|
389 | if ((line = lookup_ipaddr(&addr, line, DEFAULT_API_PROTO)) == NULL) {
|
---|
390 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] sleep %d.%03u[s], unknown host.",
|
---|
391 | (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
|
---|
392 | dly_tsk(SLP_ITV);
|
---|
393 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] resume.", (ID)exinf);
|
---|
394 | retry = true;
|
---|
395 | continue;
|
---|
396 | }
|
---|
397 |
|
---|
398 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
399 |
|
---|
400 | line = skip_blanks(line);
|
---|
401 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
402 | line = get_int(&rep, line);
|
---|
403 | portno = (uint16_t)rep;
|
---|
404 | }
|
---|
405 | else if (*line == '-')
|
---|
406 | line ++;
|
---|
407 |
|
---|
408 | #if defined(USE_UDP_EXTENTIONS)
|
---|
409 |
|
---|
410 | ccep.cepatr = UINT_C(0);
|
---|
411 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
412 |
|
---|
413 | #if defined(SUPPORT_INET6)
|
---|
414 |
|
---|
415 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
416 |
|
---|
417 | #else /* #if defined(SUPPORT_INET6) */
|
---|
418 |
|
---|
419 | #if defined(SUPPORT_INET4)
|
---|
420 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
421 | #endif
|
---|
422 |
|
---|
423 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
424 |
|
---|
425 | #if defined(USE_UDP_NON_BLOCKING)
|
---|
426 | ccep.callback = (FP)callback_nblk_udp4_echo_cli;
|
---|
427 | #else
|
---|
428 | ccep.callback = NULL;
|
---|
429 | #endif
|
---|
430 |
|
---|
431 | if ((error = alloc_udp4_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
432 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] CEP create error:%s", cepid, itron_strerror(error));
|
---|
433 | continue;
|
---|
434 | }
|
---|
435 |
|
---|
436 | #else/* of #if defined(USE_UDP_EXTENTIONS) */
|
---|
437 |
|
---|
438 | cepid = (ID)exinf;
|
---|
439 |
|
---|
440 | #endif/* of #if defined(USE_UDP_EXTENTIONS) */
|
---|
441 |
|
---|
442 | line = skip_blanks(line);
|
---|
443 | if ('0' <= *line && *line <= '9') { /* Repeat */
|
---|
444 | line = get_int(&rep, line);
|
---|
445 | #if 0
|
---|
446 | if (rep > 1000000)
|
---|
447 | rep = 1000000;
|
---|
448 | #endif
|
---|
449 | udp4_echo_cli_valid = true;
|
---|
450 | count = 0;
|
---|
451 | while (rep == 0 || count < rep) {
|
---|
452 | if (!udp4_echo_cli_valid) {
|
---|
453 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] canceled.", cepid);
|
---|
454 | break;
|
---|
455 | }
|
---|
456 |
|
---|
457 | count ++;
|
---|
458 | p = &msg[sizeof(MESSAGE_FORMAT)] - 1;
|
---|
459 | for (msgno = count; msgno > 0; msgno /= 10)
|
---|
460 | *(-- p) = msgno % 10 + '0';
|
---|
461 | while (*(p - 2) != 'G')
|
---|
462 | *(-- p) = ' ';
|
---|
463 |
|
---|
464 | if ((error = udp4_echo_cli(cepid, &addr, portno, msg)) != E_OK)
|
---|
465 | dly_tsk(30 * SYSTIM_HZ);
|
---|
466 |
|
---|
467 | dly_tsk(25 * SYSTIM_HZ + netapp_rand() % (10 * SYSTIM_HZ));
|
---|
468 | }
|
---|
469 | }
|
---|
470 |
|
---|
471 | else /* Single Message */
|
---|
472 | error = udp4_echo_cli(cepid, &addr, portno, line);
|
---|
473 |
|
---|
474 | if (error != E_OK) {
|
---|
475 | get_tim(&time);
|
---|
476 | syslog(LOG_NOTICE, "[UEC4:%02u SND] error: %7lu,%s",
|
---|
477 | cepid, time / SYSTIM_HZ, itron_strerror(error));
|
---|
478 | }
|
---|
479 |
|
---|
480 | #if defined(USE_UDP_EXTENTIONS)
|
---|
481 |
|
---|
482 | if ((error = free_udp4_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
483 | syslog(LOG_NOTICE, "[UEC4:%02u TSK] CEP delete error:%s", cepid, itron_strerror(error));
|
---|
484 |
|
---|
485 | #endif /* of #if defined(USE_UDP_EXTENTIONS) */
|
---|
486 |
|
---|
487 | }
|
---|
488 | }
|
---|
489 |
|
---|
490 | #endif /* of #if defined(USE_UDP4_ECHO_CLI_TSK) */
|
---|