From 341e3ffda6064019a2ae289fb9bc98d0bb2f3c74 Mon Sep 17 00:00:00 2001 From: Alexander Shiryaev Date: Thu, 15 Nov 2012 00:04:18 +0400 Subject: [PATCH] OpenBSD CommTCP implementation added --- Trurl-based/_OpenBSD_/Comm/Mod/TCP.odc | Bin 0 -> 19344 bytes Trurl-based/_OpenBSD_/Lin/Mod/Net.txt | 270 ++++++++++++++++++ .../_OpenBSD_/Lin/Mod/gen-Net/Makefile | 34 +++ .../_OpenBSD_/Lin/Mod/gen-Net/Net.txt.templ | 140 +++++++++ .../_OpenBSD_/Lin/Mod/gen-Net/dumpdefs.py | 1 + .../_OpenBSD_/Lin/Mod/gen-Net/dumphstrerrno.c | 19 ++ .../_OpenBSD_/Lin/Mod/gen-Net/untempl.py | 1 + Trurl-based/build | 3 +- 8 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 Trurl-based/_OpenBSD_/Comm/Mod/TCP.odc create mode 100644 Trurl-based/_OpenBSD_/Lin/Mod/Net.txt create mode 100644 Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/Makefile create mode 100644 Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/Net.txt.templ create mode 120000 Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumpdefs.py create mode 100644 Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumphstrerrno.c create mode 120000 Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/untempl.py diff --git a/Trurl-based/_OpenBSD_/Comm/Mod/TCP.odc b/Trurl-based/_OpenBSD_/Comm/Mod/TCP.odc new file mode 100644 index 0000000000000000000000000000000000000000..3181e5eb2f4a74cbeafd8ca97c752fb56b701948 GIT binary patch literal 19344 zcmdU1-E&*laR+6^3X-zlNz-=Pp3-gv$`DM-v66~*8ju7fG!(!9pk&!&vmkIuUJ1OH zxfc*6$LXX=rjv)X)6Ddt>7>*4G1Hg!rG4o%ZDu;t*Zv3n1Nz|Tp_7MZ+~05aoOAC5 z0aZvKgda5z=JvwIx@j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JH+#2}a2%{txRT(0 z;Cwqc!|Qi?4cs^ka8;lXBg?tRDaOGu^>#!i^_cj>>N%i^Q^(uLGQ`#c0W|{Es{Xc` z$)yL&9KnIlkq&fG_E-vB6e>4lok7X@I17+IYd#87&6;)~>nzxNLPx?~hyEQUDn|XHUcm7cED}Y0!Knv!VWD za}IW)$n0b*sHjL~&DgDdMm_<)qp{!%nS`9P=ED1Y9s%66Fz04CEcY;D@1HtI#hGq^ zP2<2isulE~n|4HI5&m=`R7QdXg7(+)3%4P12g2!eM$siiB(ZLDn%L1n%JG>HDC?8? zx|)mkn4evKPSWuTz*kFl-oHIdt&sGhB2srbKm8(O;La;okUzml7k|)t&7Sbg!z%@G zHkV?#1LbyraUt5@mzkAJL06A?D)SN{NS3?W?xr1nZ*vS+$5e1wb=kGOC8vIj^~~~P zZ;l|iQz=v4?qm)uC?_s0f_=ml-7Z?lkiZ+06Hf)>Pl!iM0)T;hc=O9+et!!_R_+-! z%Q9%19?qp)>ca%q$_j*_{eik*@d*Pg863sBeT^8L0cQFA325#joSPN$+#@4} zCpIgT%L_@vkCzt8vM*1TtI7J$%hm`{Hd%vQhELbzCIs#A2dtj`R37XpFo7Rjie`3> zCP!3G8B`tf`rI*J4=qyg|9h zPGmCD@3lq!gEkwuEt|w6_h)uC#)788H0 z&yW19T8sQ2f3AqXj^?M2FMn43-}=`v&i<;LKmL~wez=Vv(mxtZ?@Ql(t@P0!mOhvNqgm6_mfv{0fq3$V@$!-Rzx^loOMmg^w@Y97&yUFW ${.TARGET} + +Net.txt: Net.txt.templ ${DEFS} + ${PY} ./untempl.py Net.txt.templ ${.TARGET} + +defs-socket: + ./dumpdefs.py 3 1 i /usr/include/sys/socket.h | grep " SOCK_" > ${.TARGET} + ./dumpdefs.py 3 1 i /usr/include/sys/socket.h | grep " AF_" >> ${.TARGET} + ./dumpdefs.py 3 1 i /usr/include/sys/socket.h | grep " SHUT_" >> ${.TARGET} + ./dumpdefs.py 3 1 i /usr/include/sys/socket.h | grep " SOMAXCONN" >> ${.TARGET} + ./dumpdefs.py 3 1 s /usr/include/sys/socket.h | grep " SO_" >> ${.TARGET} + ./dumpdefs.py 3 1 i /usr/include/sys/socket.h | grep " SOL_" >> ${.TARGET} + ./dumpdefs.py 3 1 s /usr/include/sys/socket.h | grep " MSG_" >> ${.TARGET} + +defs-in: + ./dumpdefs.py 3 1 i /usr/include/netinet/in.h | grep " IPPROTO_" > ${.TARGET} + +defs-netdb: + ./dumpdefs.py 3 2 i /usr/include/netdb.h > ${.TARGET} + +clean: + rm -f Net.txt ${DEFS} dumphstrerrno diff --git a/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/Net.txt.templ b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/Net.txt.templ new file mode 100644 index 0000000..fa144c0 --- /dev/null +++ b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/Net.txt.templ @@ -0,0 +1,140 @@ +MODULE LinNet ["libc.so.66.0"]; + + (* + A. V. Shiryaev, 2012.11 + + OpenBSD 5.2 + 32-bit + *) + + IMPORT Libc := LinLibc; + + CONST + INVALID_SOCKET* = -1; + SOCKET_ERROR* = -1; + + (* /usr/include/sys/socket.h *) +%%defs-socket%% + (* /usr/include/netinet/in.h *) + INADDR_NONE* = -1; +%%defs-in%% + (* /usr/include/sys/param.h *) + MAXHOSTNAMELEN* = 256; (* max hostname size *) + + (* /usr/include/netdb.h *) +%%defs-netdb%% + (* /usr/include/sys/select.h *) + FD_SETSIZE = 1024; + __NBBY = 8; + TYPE + SOCKET* = INTEGER; + + (* /usr/include/sys/_types.h *) + socklen_t* = INTEGER; + sa_family_t* = SHORTCHAR; + in_addr_t* = INTEGER; + in_port_t* = SHORTINT; + + (* /usr/include/sys/socket.h *) + sockaddr* = RECORD [untagged] + sa_len*: SHORTCHAR; (* total length *) + sa_family*: sa_family_t; (* address family *) + sa_data*: ARRAY [untagged] 14 OF SHORTCHAR; (* actually longer; address value *) + END; + sockaddr_storage* = RECORD [untagged] + ss_len*: SHORTCHAR; (* total length *) + ss_family*: sa_family_t; (* address family *) + __ss_pad1: ARRAY [untagged] 6 OF SHORTCHAR; (* align to quad *) + __ss_pad2: LONGINT; (* force alignment for stupid compilers *) + __ss_pad3: ARRAY [untagged] 240 OF SHORTCHAR; (* pad to a total of 256 bytes *) + END; + + (* /usr/include/netinet/in.h *) +(* + in_addr* = RECORD [untagged] + s_addr*: in_addr_t; + END; +*) + in_addr* = RECORD [untagged] + S_un*: RECORD [union] + S_un_b*: RECORD [untagged] + s_b1*: SHORTCHAR; + s_b2*: SHORTCHAR; + s_b3*: SHORTCHAR; + s_b4*: SHORTCHAR; + END; + S_un_w*: RECORD [untagged] + s_w1*: SHORTINT; + s_w2*: SHORTINT; + END; + S_addr*: in_addr_t; + END; + END; + + sockaddr_in* = RECORD [untagged] + sin_len*: SHORTCHAR; + sin_family*: sa_family_t; + sin_port*: in_port_t; + sin_addr*: in_addr; + sin_zero*: ARRAY [untagged] 8 OF SHORTCHAR; + END; + + (* /usr/include/netdb.h *) + Ptrhostent* = POINTER TO hostent; + hostent* = RECORD [untagged] + h_name*: Libc.PtrSTR; (* official name of host *) + h_aliases*: POINTER TO ARRAY [untagged] OF Libc.PtrSTR; (* alias list *) + h_addrtype*: INTEGER; (* host address type *) + h_length*: INTEGER; (* length of address *) + h_addr_list*: POINTER TO ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF in_addr; (* list of addresses from name server *) + END; + + (* /usr/include/sys/time.h *) + timeval* = RECORD [untagged] + tv_sec*: INTEGER; (* seconds *) + tv_usec*: INTEGER; (* and microseconds *) + END; + + (* /usr/include/sys/select.h *) + __fd_mask = SET; + fd_set* = ARRAY [untagged] (FD_SETSIZE + (SIZE(__fd_mask) * __NBBY - 1)) DIV (SIZE(__fd_mask) * __NBBY) OF __fd_mask; + + VAR + h_errno*: INTEGER; + + PROCEDURE [ccall] socket* (domain: INTEGER; type: INTEGER; protocol: INTEGER): SOCKET; + PROCEDURE [ccall] accept* (s: SOCKET; VAR addr: sockaddr; VAR addrlen: socklen_t): SOCKET; + PROCEDURE [ccall] bind* (s: SOCKET; VAR name: sockaddr; namelen: socklen_t): INTEGER; + PROCEDURE [ccall] connect* (s: SOCKET; VAR name: sockaddr; namelen: socklen_t): INTEGER; + PROCEDURE [ccall] listen* (s: SOCKET; backlog: INTEGER): INTEGER; + PROCEDURE [ccall] recv* (s: SOCKET; buf: Libc.PtrVoid; len: Libc.size_t; flags: SET): Libc.ssize_t; + PROCEDURE [ccall] send* (s: SOCKET; msg: Libc.PtrVoid; len: Libc.size_t; flags: SET): Libc.ssize_t; + PROCEDURE [ccall] shutdown* (s: SOCKET; how: INTEGER): INTEGER; + PROCEDURE [ccall] getsockopt* (s: SOCKET; level: INTEGER; optname: SET; optval: Libc.PtrVoid; VAR optlen: socklen_t): INTEGER; + PROCEDURE [ccall] setsockopt* (s: SOCKET; level: INTEGER; optname: SET; optval: Libc.PtrVoid; optlen: socklen_t): INTEGER; + + PROCEDURE [ccall] htons* (host16: SHORTINT): SHORTINT; + + PROCEDURE [ccall] gethostbyname* (name: Libc.PtrSTR): Ptrhostent; + PROCEDURE [ccall] inet_addr* (cp: Libc.PtrSTR): in_addr_t; + + PROCEDURE [ccall] getsockname* (s: SOCKET; VAR name: sockaddr; VAR namelen: socklen_t): INTEGER; + + PROCEDURE [ccall] hstrerror* (err: INTEGER): Libc.PtrSTR; + +(* + PROCEDURE FD_ZERO (VAR set: Net.fd_set); + VAR i: INTEGER; + BEGIN + i := 0; WHILE i < LEN(set) DO set[i] := {}; INC(i) END + END FD_ZERO; + + PROCEDURE FD_SET (fd: Net.SOCKET; VAR set: Net.fd_set); + BEGIN + INCL(set[fd DIV 32], fd MOD 32) + END FD_SET; +*) + + PROCEDURE [ccall] select* (nfds: INTEGER; VAR [nil] readfds: fd_set; VAR [nil] writefds: fd_set; VAR [nil] exceptfds: fd_set; VAR timeout: timeval): INTEGER; + +END LinNet. diff --git a/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumpdefs.py b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumpdefs.py new file mode 120000 index 0000000..1730591 --- /dev/null +++ b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumpdefs.py @@ -0,0 +1 @@ +../gen-Libc/dumpdefs.py \ No newline at end of file diff --git a/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumphstrerrno.c b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumphstrerrno.c new file mode 100644 index 0000000..e839256 --- /dev/null +++ b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/dumphstrerrno.c @@ -0,0 +1,19 @@ +#include +#include + +static void D (const char *s, int e) +{ + printf("%s, %s\n", s, hstrerror(e)); +} + +int main (int argc, char *argv[]) +{ + D("NETDB_INTERNAL", NETDB_INTERNAL); + D("NETDB_SUCCESS", NETDB_SUCCESS); + D("HOST_NOT_FOUND", HOST_NOT_FOUND); + D("TRY_AGAIN", TRY_AGAIN); + D("NO_RECOVERY", NO_RECOVERY); + D("NO_DATA", NO_DATA); + + return 0; +} diff --git a/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/untempl.py b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/untempl.py new file mode 120000 index 0000000..5800713 --- /dev/null +++ b/Trurl-based/_OpenBSD_/Lin/Mod/gen-Net/untempl.py @@ -0,0 +1 @@ +../gen-Libc/untempl.py \ No newline at end of file diff --git a/Trurl-based/build b/Trurl-based/build index 14a5504..44a52bd 100755 --- a/Trurl-based/build +++ b/Trurl-based/build @@ -127,5 +127,6 @@ DATA ./run-BlackBox <