8 #include <sys/iosupport.h>
9 #include "lwip/ip_addr.h"
11 int netio_open(struct _reent
*r
, void *fileStruct
, const char *path
,int flags
,int mode
);
12 int netio_close(struct _reent
*r
,int fd
);
13 int netio_write(struct _reent
*r
,int fd
,const char *ptr
,size_t len
);
14 int netio_read(struct _reent
*r
,int fd
,char *ptr
,size_t len
);
16 //---------------------------------------------------------------------------------
17 const devoptab_t dotab_stdnet
= {
18 //---------------------------------------------------------------------------------
19 "stdnet", // device name
20 0, // size of file structure
21 netio_open
, // device open
22 netio_close
, // device close
23 netio_write
, // device write
24 netio_read
, // device read
29 NULL
, // device unlink
31 NULL
, // device rename
34 NULL
, // device diropen_r
35 NULL
, // device dirreset_r
36 NULL
, // device dirnext_r
37 NULL
, // device dirclose_r
38 NULL
// device statvfs_r
41 int netio_open(struct _reent
*r
, void *fileStruct
, const char *path
,int flags
,int mode
)
44 int optval
= 1,nport
= -1,udp_sock
= INVALID_SOCKET
;
45 struct sockaddr_in name
;
46 socklen_t namelen
= sizeof(struct sockaddr
);
48 if(net_init()==SOCKET_ERROR
) return -1;
50 udp_sock
= net_socket(AF_INET
,SOCK_STREAM
,IPPROTO_TCP
);
51 if(udp_sock
==INVALID_SOCKET
) return -1;
53 cport
= strchr(path
,':');
58 if(nport
==-1) nport
= 7; //try to connect to the well known port 7
60 name
.sin_addr
.s_addr
= inet_addr(path
);
61 name
.sin_port
= htons(nport
);
62 name
.sin_family
= AF_INET
;
63 if(net_connect(udp_sock
,(struct sockaddr
*)&name
,namelen
)==-1) {
67 net_setsockopt(udp_sock
,IPPROTO_TCP
,TCP_NODELAY
,&optval
,sizeof(optval
));
72 int netio_close(struct _reent
*r
,int fd
)
81 int netio_write(struct _reent
*r
,int fd
,const char *ptr
,size_t len
)
87 ret
= net_write(fd
,(void*)ptr
,len
);
92 int netio_read(struct _reent
*r
,int fd
,char *ptr
,size_t len
)
98 ret
= net_read(fd
,ptr
,len
);