source: EcnlProtoTool/trunk/ntshell/src/socket_stub.c@ 286

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

各ソフトウェアのライセンスを整理

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 18.6 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2017 Cores Co., Ltd. Japan
5 *
6 * 上記著作権者
7は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
8 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
9 * 変・再é…
10å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
11 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
12 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
13 * スコード中に含まれていること.
14 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
15 * 用できる形で再é…
16å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
17å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
18 * 者
19マニュアルなど)に,上記の著作権表示,この利用条件および下記
20 * の無保証規定を掲載すること.
21 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22 * 用できない形で再é…
23å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
24 * と.
25 * (a) 再é…
26å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
27マニュアルなど)に,上記の著
28 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
29 * (b) 再é…
30å¸ƒã®å½¢æ…
31‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
32 * 報告すること.
33 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
34 * 害からも,上記著作権者
35およびTOPPERSプロジェクトをå…
36è²¬ã™ã‚‹ã“と.
37 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
38 * 由に基づく請求からも,上記著作権者
39およびTOPPERSプロジェクトを
40 * å…
41è²¬ã™ã‚‹ã“と.
42 *
43 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
44お
45 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
46 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
47 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
48 * の責任を負わない.
49 *
50 * @(#) $Id: socket_stub.c 286 2017-05-02 15:25:33Z coas-nagasima $
51 */
52#include <sys/types.h>
53#include <stdint.h>
54#if 0
55#include <sys/socket.h>
56#include <sys/un.h>
57#include <netinet/in.h>
58#include <netinet/tcp.h>
59#include <arpa/inet.h>
60#include <netdb.h>
61#endif
62#include <fcntl.h>
63#include "sys/unistd.h"
64#include <stddef.h>
65#include <string.h>
66#include <stdlib.h>
67#include <kernel.h>
68#include <t_syslog.h>
69#include <t_stdlib.h>
70#include <sil.h>
71#include <stdlib.h>
72#include <string.h>
73#include <stdio.h>
74#include <setjmp.h>
75#include "syssvc/syslog.h"
76#include <tinet_config.h>
77#include <netinet/in.h>
78#include <netinet/in_itron.h>
79#include <tinet_nic_defs.h>
80#include <tinet_cfg.h>
81#include <netinet/in_var.h>
82#include <net/ethernet.h>
83#include <net/if6_var.h>
84#include <net/net.h>
85#include <net/if_var.h>
86#include <netinet/udp_var.h>
87//#include <netinet/tcp_var.h>
88extern const ID tmax_tcp_cepid;
89#include "ff.h"
90#include "socket_stub.h"
91#define SO_REUSEADDR 2
92
93typedef struct id_table_t {
94 int used;
95 ID id;
96} id_table_t;
97
98id_table_t tcp_repid_table[] = {
99 {0, USR_TCP_REP1}, {0, USR_TCP_REP2}, {0, USR_TCP_REP3}, {0, USR_TCP_REP4}
100};
101#define tcp_repid_table_count (sizeof(tcp_repid_table) / sizeof(tcp_repid_table[0]))
102
103id_table_t tcp_cepid_table[] = {
104 {0, USR_TCP_CEP1}, {0, USR_TCP_CEP2}, {0, USR_TCP_CEP3}, {0, USR_TCP_CEP4}, {0, USR_TCP_CEP5}, {0, USR_TCP_CEP6}, {0, USR_TCP_CEP7}, {0, USR_TCP_CEP8}
105};
106#define tcp_cepid_table_count (sizeof(tcp_cepid_table) / sizeof(tcp_cepid_table[0]))
107
108id_table_t udp_cepid_table[] = {
109 {0, USR_UDP_CEP1}, {0, USR_UDP_CEP2}, {0, USR_UDP_CEP3}, {0, USR_UDP_CEP4}
110};
111#define udp_cepid_table_count (sizeof(udp_cepid_table) / sizeof(udp_cepid_table[0]))
112
113ID new_id(id_table_t *table, int count)
114{
115 for (int i = 0; i < count; i++) {
116 id_table_t *item = &table[i];
117 if (item->used != 0)
118 continue;
119
120 item->used = 1;
121 return item->id;
122}
123
124 return -1;
125}
126
127int delete_id(id_table_t *table, int count, ID id)
128{
129 for (int i = 0; i < count; i++) {
130 id_table_t *item = &table[i];
131 if ((item->used == 0) || (item->id != id))
132 continue;
133
134 item->used = 0;
135 return 0;
136 }
137 return -1;
138}
139
140int delete_tcp_rep(int repid)
141{
142 delete_tcp_fd(tmax_tcp_cepid + repid);
143}
144
145unsigned char tcp_buf[tcp_cepid_table_count][2 * 512];
146
147unsigned char *id_to_buff(ID id)
148{
149 for (int i = 0; i < tcp_cepid_table_count; i++) {
150 id_table_t *item = &tcp_cepid_table[i];
151 if ((item->used == 0) || (item->id != id))
152 continue;
153
154 return tcp_buf[i];
155 }
156
157 return NULL;
158}
159
160typedef struct _IO_FILE SOCKET;
161
162int socket(int family, int type, int protocol)
163{
164 SOCKET *fp;
165
166 switch (family) {
167 case AF_INET:
168 case AF_INET6:
169 break;
170 default:
171 return -1;
172 }
173
174 switch (type) {
175 case SOCK_STREAM:
176 fp = new_tcp_fd(0);
177 break;
178 case SOCK_DGRAM:
179 fp = new_udp_fd(0);
180 break;
181 default:
182 return -1;
183 }
184
185 if (fp == NULL) {
186 return -1;
187 }
188
189 fp->socket.family = family;
190 fp->socket.type = type;
191 fp->socket.protocol = protocol;
192
193 return fp->fd;
194}
195
196int bind(int fd, const struct sockaddr *addr, socklen_t len)
197{
198 SOCKET *fp = fd_to_fp(fd);
199 if (fp == NULL) {
200 return -1;
201 }
202
203 if (fp->socket.family != addr->sa_family) {
204 return -1;
205 }
206
207 ER ret;
208 switch (addr->sa_family) {
209 case AF_INET: {
210 if (len < 8) {
211 return -1;
212 }
213 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
214 memcpy(&fp->socket.laddr4, addr, len);
215 switch (fp->socket.type) {
216 case SOCK_STREAM: {
217 ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
218 if (cepid < 0)
219 return -1;
220
221 fp->socket.buf_size = 512 + 512;
222 fp->socket.buf = id_to_buff(cepid);
223 T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
224 ret = tcp_cre_cep(cepid, &ccep);
225 if (ret != E_OK) {
226 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
227 return -1;
228 }
229 fp->handle = cepid;
230 fp->socket.cepid = cepid;
231 break;
232 }
233 case SOCK_DGRAM: {
234 ID cepid = new_id(udp_cepid_table, udp_cepid_table_count);
235 if (cepid < 0)
236 return -1;
237
238 T_UDP_CCEP ccep = { 0, {ntohl(addr_in->sin_addr.s_addr), ntohs(addr_in->sin_port)}, socket_udp_callback };
239 ret = udp_cre_cep(cepid, &ccep);
240 if (ret != E_OK) {
241 delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
242 return -1;
243 }
244 fp->handle = cepid;
245 fp->socket.cepid = cepid;
246 break;
247 }
248 default:
249 return -1;
250 }
251 break;
252 }
253 case AF_INET6: {
254 if (len < 20) {
255 return -1;
256 }
257 memcpy(&fp->socket.laddr4, addr, len);
258 break;
259 }
260 }
261
262 return 0;
263}
264
265int listen(int fd, int backlog)
266{
267 SOCKET *fp = fd_to_fp(fd);
268 if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
269 return -1;
270 }
271
272 fp->socket.backlog = backlog;
273
274 ER ret;
275 switch (fp->socket.family) {
276 case AF_INET: {
277 ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
278 if (repid < 0)
279 return -1;
280
281 struct sockaddr_in *laddr = &fp->socket.laddr4;
282 T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
283 ret = tcp_cre_rep(repid, &crep);
284 if (ret != E_OK) {
285 delete_id(tcp_repid_table, tcp_repid_table_count, repid);
286 return -1;
287 }
288 fp->socket.repid = repid;
289 break;
290 }
291 case AF_INET6: {
292 break;
293 }
294 }
295
296 return 0;
297}
298
299int connect(int fd, const struct sockaddr *addr, socklen_t len)
300{
301 SOCKET *fp = fd_to_fp(fd);
302 if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
303 return -1;
304 }
305
306 ER ret;
307 switch (fp->socket.family) {
308 case AF_INET: {
309 if (len < 8) {
310 return -1;
311 }
312 if (fp->socket.cepid == 0) {
313 ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
314 if (cepid < 0)
315 return -1;
316
317 fp->socket.buf_size = 512 + 512;
318 fp->socket.buf = id_to_buff(cepid);
319 T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
320 ret = tcp_cre_cep(cepid, &ccep);
321 if (ret != E_OK) {
322 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
323 return -1;
324 }
325 fp->handle = cepid;
326 fp->socket.cepid = cepid;
327 }
328 struct sockaddr_in *laddr = &fp->socket.laddr4;
329 struct sockaddr_in *raddr = &fp->socket.raddr4;
330 memset(raddr, 0, sizeof(*raddr));
331 memcpy(raddr, addr, len);
332 T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
333 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
334 ret = tcp_con_cep(fp->socket.cepid, &lep, &rep, TMO_FEVR);
335 if (ret < 0) {
336 return -1;
337 }
338 break;
339 }
340 case AF_INET6: {
341 break;
342 }
343 }
344
345 return 0;
346}
347
348int accept(int fd, struct sockaddr *addr, socklen_t *len)
349{
350 SOCKET *lfp = fd_to_fp(fd);
351 if ((lfp == NULL) || (lfp->socket.type != SOCK_STREAM)) {
352 return -1;
353 }
354
355 SOCKET *fp = new_tcp_fd(0);
356 if (fp == NULL) {
357 return -1;
358 }
359
360 memcpy(&fp->socket, &lfp->socket, sizeof(fp->socket));
361
362 ER ret;
363 switch (fp->socket.family) {
364 case AF_INET: {
365 ID cepid;
366 if (fp->socket.cepid == 0) {
367 cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
368 if (cepid < 0)
369 return -1;
370
371 fp->socket.buf_size = 512 + 512;
372 fp->socket.buf = id_to_buff(cepid);
373 T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
374 ret = tcp_cre_cep(cepid, &ccep);
375 if (ret != E_OK) {
376 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
377 return -1;
378 }
379 fp->handle = cepid;
380 fp->socket.cepid = cepid;
381 }
382 else {
383 cepid = lfp->socket.cepid;
384 lfp->handle = tmax_tcp_cepid + lfp->socket.repid;
385 lfp->socket.cepid = 0;
386 lfp->socket.buf_size = 0;
387 lfp->socket.buf = 0;
388 }
389 T_IPV4EP rep = { 0, 0 };
390 ret = tcp_acp_cep(fp->socket.cepid, fp->socket.repid, &rep, TMO_FEVR);
391 if (ret < 0) {
392 return -1;
393 }
394 struct sockaddr_in *raddr = &fp->socket.raddr4;
395 memset(raddr, 0, sizeof(*raddr));
396 raddr->sin_family = AF_INET;
397 raddr->sin_port = htons(rep.portno);
398 raddr->sin_addr.s_addr = htonl(rep.ipaddr);
399 break;
400 }
401 case AF_INET6: {
402 break;
403 }
404 }
405
406 if (addr != NULL && len != NULL) {
407 int sz = *len;
408 if (sz < 8) {
409 return -1;
410 }
411 struct sockaddr_in *raddr = &fp->socket.raddr4;
412 if (sz > sizeof(*raddr))
413 sz = sizeof(*raddr);
414 memcpy(addr, raddr, sz);
415 *len = sizeof(*raddr);
416 }
417
418 return fp->fd;
419}
420
421ssize_t send(int fd, const void *buf, size_t len, int flags)
422{
423 SOCKET *fp = fd_to_fp(fd);
424 if (fp == NULL) {
425 return -1;
426 }
427
428 int ret = 0;
429 switch (fp->socket.family) {
430 case AF_INET: {
431 switch (fp->socket.type) {
432 case SOCK_STREAM: {
433 if (flags & MSG_OOB) {
434 ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
435 if (ret < 0) {
436 return -1;
437 }
438 }
439 else {
440 ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
441 if (ret < 0) {
442 return -1;
443 }
444 }
445 break;
446 }
447 case SOCK_DGRAM: {
448 return -1;
449 }
450 }
451 break;
452 }
453 case AF_INET6: {
454 break;
455 }
456 }
457
458 return ret;
459}
460
461ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
462{
463 SOCKET *fp = fd_to_fp(fd);
464 if (fp == NULL) {
465 return -1;
466 }
467
468 int ret = 0;
469 switch (fp->socket.family) {
470 case AF_INET: {
471 switch (fp->socket.type) {
472 case SOCK_STREAM: {
473 if ((addr != NULL) && (alen != 0)) {
474 return -1;
475 }
476
477 if (flags & MSG_OOB) {
478 ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
479 if (ret < 0) {
480 return -1;
481 }
482 }
483 else {
484 ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
485 if (ret < 0) {
486 return -1;
487 }
488 }
489 break;
490 }
491 case SOCK_DGRAM: {
492 int sz = alen;
493 if (sz < 8) {
494 return -1;
495 }
496 struct sockaddr_in *raddr = &fp->socket.raddr4;
497 memset(raddr, 0, sizeof(*raddr));
498 memcpy(raddr, addr, sz);
499 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
500 ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len, TMO_FEVR);
501 if (ret < 0) {
502 return -1;
503 }
504 break;
505 }
506 }
507 break;
508 }
509 case AF_INET6: {
510 break;
511 }
512 }
513
514 return ret;
515}
516
517ssize_t recv(int fd, void *buf, size_t len, int flags)
518{
519 SOCKET *fp = fd_to_fp(fd);
520 if (fp == NULL) {
521 return -1;
522 }
523
524 int ret = 0;
525 switch (fp->socket.family) {
526 case AF_INET: {
527 switch (fp->socket.type) {
528 case SOCK_STREAM: {
529 if (flags & MSG_OOB) {
530 ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
531 if (ret < 0) {
532 return -1;
533 }
534 }
535 else {
536 ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
537 if (ret < 0) {
538 return -1;
539 }
540 }
541 break;
542 }
543 case SOCK_DGRAM: {
544 T_IPV4EP rep = { 0, 0 };
545 ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
546 if (ret < 0) {
547 return -1;
548 }
549 }
550 }
551 break;
552 }
553 case AF_INET6: {
554 break;
555 }
556 }
557
558 return ret;
559}
560
561ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
562{
563 SOCKET *fp = fd_to_fp(fd);
564 if (fp == NULL) {
565 return -1;
566 }
567
568 int ret = 0;
569 switch (fp->socket.family) {
570 case AF_INET: {
571 switch (fp->socket.type) {
572 case SOCK_STREAM: {
573 if (flags & MSG_OOB) {
574 ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
575 if (ret < 0) {
576 return -1;
577 }
578 }
579 else {
580 ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
581 if (ret < 0) {
582 return -1;
583 }
584 }
585 break;
586 }
587 case SOCK_DGRAM: {
588 T_IPV4EP rep = { 0, 0 };
589 ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
590 if (ret < 0) {
591 return -1;
592 }
593 int sz = *alen;
594 struct sockaddr_in raddr;
595 memset(&raddr, 0, sizeof(raddr));
596 raddr.sin_family = AF_INET;
597 raddr.sin_port = htons(rep.portno);
598 raddr.sin_addr.s_addr = htonl(rep.ipaddr);
599 if (sz > sizeof(raddr))
600 sz = sizeof(raddr);
601 memcpy(addr, &raddr, sz);
602 }
603 }
604 break;
605 }
606 case AF_INET6: {
607 break;
608 }
609 }
610
611 return ret;
612}
613
614int shutdown(int fd, int how)
615{
616 SOCKET *fp = fd_to_fp(fd);
617 if (fp == NULL) {
618 return -1;
619 }
620
621 ER ret;
622 switch (fp->socket.family) {
623 case AF_INET: {
624 switch (fp->socket.type) {
625 case SOCK_STREAM: {
626 ret = tcp_sht_cep(fp->socket.cepid);
627 if (ret < 0) {
628 return -1;
629 }
630 break;
631 }
632 }
633 break;
634 }
635 case AF_INET6: {
636 break;
637 }
638 }
639
640 return 0;
641}
642
643int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
644{
645 SOCKET *fp = fd_to_fp(fd);
646 if (fp == NULL) {
647 return -1;
648 }
649
650 ER ret;
651 switch (fp->socket.family) {
652 case AF_INET: {
653 switch (fp->socket.type) {
654 case SOCK_STREAM: {
655 switch (optname) {
656 case SO_REUSEADDR:
657 if (fp->socket.flags & SO_REUSEADDR) {
658 *(bool *)optval = true;
659 }
660 else {
661 *(bool *)optval = false;
662 }
663 break;
664 default:
665 ret = tcp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
666 if (ret < 0) {
667 return -1;
668 }
669 *optlen = ret;
670 break;
671 }
672 break;
673 }
674 case SOCK_DGRAM: {
675 ret = udp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
676 if (ret < 0) {
677 return -1;
678 }
679 *optlen = ret;
680 break;
681 }
682 }
683 break;
684 }
685 case AF_INET6: {
686 break;
687 }
688 }
689
690 return 0;
691}
692
693int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
694{
695 SOCKET *fp = fd_to_fp(fd);
696 if (fp == NULL) {
697 return -1;
698 }
699
700 ER ret;
701 switch (fp->socket.family) {
702 case AF_INET: {
703 switch (fp->socket.type) {
704 case SOCK_STREAM: {
705 switch (optname) {
706 case SO_REUSEADDR:
707 if (*(bool *)optval) {
708 fp->socket.flags |= SO_REUSEADDR;
709 }
710 else {
711 fp->socket.flags &= ~SO_REUSEADDR;
712 }
713 break;
714 default:
715 ret = tcp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
716 if (ret < 0) {
717 return -1;
718 }
719 break;
720 }
721 break;
722 }
723 case SOCK_DGRAM: {
724 ret = udp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
725 if (ret < 0) {
726 return -1;
727 }
728 break;
729 }
730 }
731 break;
732 }
733 case AF_INET6: {
734 break;
735 }
736 }
737
738 return 0;
739}
740
741int tcp_fd_close(struct _IO_FILE *fp)
742{
743 ER ret;
744 switch (fp->socket.family) {
745 case AF_INET: {
746 if (fp->socket.cepid != 0) {
747 ID cepid = fp->socket.cepid;
748 ret = tcp_sht_cep(cepid);
749 if (ret < 0) {
750 //return -1;
751 }
752 ret = tcp_cls_cep(cepid, TMO_FEVR);
753 if (ret < 0) {
754 //return -1;
755 }
756 ret = tcp_del_cep(cepid);
757 delete_tcp_fd(cepid);
758 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
759 if (ret < 0) {
760 return -1;
761 }
762 }
763 else if (fp->socket.repid != 0) {
764 ID repid = fp->socket.repid;
765 ret = tcp_del_rep(repid);
766 delete_tcp_fd(tmax_tcp_cepid + repid);
767 delete_id(tcp_repid_table, tcp_repid_table_count, repid);
768 if (ret < 0) {
769 return -1;
770 }
771 }
772 else {
773 return -1;
774 }
775 break;
776 }
777 case AF_INET6: {
778 break;
779 }
780 }
781
782 return 0;
783}
784
785size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
786{
787 return recv(fp->fd, dst, dstsz, 0);
788}
789
790size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
791{
792 return send(fp->fd, src, srcsz, 0);
793}
794
795off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
796{
797 return -1;
798}
799
800int udp_fd_close(struct _IO_FILE *fp)
801{
802 ER ret;
803 ID cepid;
804 switch (fp->socket.family) {
805 case AF_INET: {
806 cepid = fp->socket.cepid;
807 ret = udp_del_cep(cepid);
808 delete_udp_fd(cepid);
809 delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
810 if (ret < 0) {
811 return -1;
812 }
813 break;
814 }
815 case AF_INET6: {
816 break;
817 }
818 }
819
820 return 0;
821}
822
823size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
824{
825 return recv(fp->fd, dst, dstsz, 0);
826}
827
828size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
829{
830 return send(fp->fd, src, srcsz, 0);
831}
832
833off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
834{
835 return -1;
836}
837
838#ifndef TCP_CFG_EXTENTIONS
839ER tcp_cre_rep(ID repid, T_TCP_CREP *pk_crep)
840{
841 syslog(LOG_ERROR, "tcp_cre_rep not implement");
842 shell_abort();
843 return E_SYS;
844}
845
846ER tcp_cre_cep(ID cepid, T_TCP_CCEP *pk_ccep)
847{
848 syslog(LOG_ERROR, "tcp_cre_cep not implement");
849 shell_abort();
850 return E_SYS;
851}
852#endif
853
854#ifndef UDP_CFG_EXTENTIONS
855ER udp_cre_cep(ID cepid, T_UDP_CCEP *pk_ccep)
856{
857 syslog(LOG_ERROR, "udp_cre_cep not implement");
858 shell_abort();
859 return E_SYS;
860}
861#endif
862
863#ifndef TCP_CFG_EXTENTIONS
864ER_UINT tcp_snd_oob(ID cepid, void *data, int_t len, TMO tmout)
865{
866 syslog(LOG_ERROR, "tcp_snd_oob not implement");
867 shell_abort();
868 return E_SYS;
869}
870
871ER_UINT tcp_rcv_oob(ID cepid, void *data, int_t len)
872{
873 syslog(LOG_ERROR, "tcp_rcv_oob not implement");
874 shell_abort();
875 return E_SYS;
876}
877
878ER tcp_set_opt(ID cepid, int_t optname, void *optval, int_t optlen)
879{
880 syslog(LOG_ERROR, "tcp_set_opt not implement");
881 shell_abort();
882 return E_SYS;
883}
884
885ER tcp_get_opt(ID cepid, int_t optname, void *optval, int_t optlen)
886{
887 syslog(LOG_ERROR, "tcp_get_opt not implement");
888 shell_abort();
889 return E_SYS;
890}
891#endif
892
893#ifndef UDP_CFG_EXTENTIONS
894ER udp_get_opt(ID cepid, int_t optname, void *optval, int_t optlen)
895{
896 syslog(LOG_ERROR, "udp_get_opt not implement");
897 shell_abort();
898 return E_SYS;
899}
900
901ER udp_set_opt(ID cepid, int_t optname, void *optval, int_t optlen)
902{
903 syslog(LOG_ERROR, "udp_set_opt not implement");
904 shell_abort();
905 return E_SYS;
906}
907#endif
Note: See TracBrowser for help on using the repository browser.