mirror of
https://github.com/vishapoberon/vipak.git
synced 2026-04-05 20:42:26 +00:00
nothing should work. just checking in.
This commit is contained in:
commit
4acd41201c
5 changed files with 242 additions and 0 deletions
11
Makefile
Normal file
11
Makefile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
VOC = /opt/voc/bin/voc
|
||||
|
||||
all:
|
||||
$(VOC) -s types.Mod sockets.Mod s.Mod -m
|
||||
|
||||
clean:
|
||||
rm *.h
|
||||
rm *.c
|
||||
rm *.o
|
||||
rm *.sym
|
||||
43
irc.Mod
Normal file
43
irc.Mod
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
MODULE irc;
|
||||
IMPORT sockets, netdb, Unix, Strings;
|
||||
|
||||
CONST strLen = 1024;
|
||||
|
||||
VAR
|
||||
nick*, channel*, host*, port*, user*, command*, where*, message*, sep*, target*: ARRAY strLen OF CHAR;
|
||||
|
||||
PROCEDURE write(fd: Int32; VAR buf: ARRAY OF CHAR; len: LONGINT);
|
||||
VAR
|
||||
l: LONGINT;
|
||||
BEGIN
|
||||
Unix.Write(fd, buf, len);
|
||||
END raw;
|
||||
|
||||
PROCEDURE connect;
|
||||
VAR hints : netdb.addrInfo;
|
||||
res: netdb.PaddrInfo;
|
||||
tmp32 : netdb.Int32;
|
||||
conn : netdb.Int32;
|
||||
str0, str1: ARRAY 255 OF CHAR;
|
||||
BEGIN
|
||||
hints.aiFamily := sockets.AfInet;
|
||||
hints.aiSockType := sockets.SockStream;
|
||||
hints.aiFlags := 0;
|
||||
hints.aiProtocol := 0;
|
||||
hints.aiAddrLen := 0;
|
||||
hints.aiAddr := 0; hints.aiCanonName := 0; hints.aiNext := 0;
|
||||
|
||||
tmp32 := netdb.getAddrInfo(host, port, hints, res);
|
||||
conn := sockets.Socket(res^.aiFamily, res^.aiSockType, res^.aiProtocol);
|
||||
tmp32 := sockets.Connect(conn, res^.aiAddr, res^.aiAddrlen);
|
||||
|
||||
(* "USER test 0 0 :test\r\n" *)
|
||||
(* "NICK test\r\n\000\060 :test\r\n"*)
|
||||
COPY("USER ", str0);
|
||||
Strings.Append(user, str0)
|
||||
Strings.Append(" 0 0 :", str0);
|
||||
Strings.Append(nick, str0);
|
||||
str1[0] := 0AX; str1[1] := 0DX; str1[2] := 0X;
|
||||
Strings.Append(str1, str0);
|
||||
write(conn, str0, Strings.Length(str0));
|
||||
END connect;
|
||||
28
netdb.Mod
Normal file
28
netdb.Mod
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
MODULE netdb;
|
||||
|
||||
IMPORT SYSTEM;
|
||||
|
||||
TYPE
|
||||
Int32* = INTEGER;
|
||||
Int64* = LONGINT;
|
||||
|
||||
TYPE
|
||||
PaddrInfo = POINTER [1] TO addrInfo;
|
||||
|
||||
addrInfo* = RECORD
|
||||
aiFlags*: Int32;
|
||||
aiFamily*:Int32;
|
||||
aiSockType*: Int32;
|
||||
aiProtocol*: Int32;
|
||||
aiAddrLen*: Int32;
|
||||
aiAddr*, aiCanonName*, aiNext*: LONGINT; (* pointers *)
|
||||
END;
|
||||
|
||||
|
||||
PROCEDURE getAddrInfo*(VAR node, service: ARRAY OF CHAR; VAR hints: addrInfo; res: LONGINT): Int32
|
||||
"getaddrinfo (node, service, hints, res)";
|
||||
|
||||
PROCEDURE freeAddrInfo*(VAR res: addrInfo)
|
||||
"freeaddrinfo(res)";
|
||||
|
||||
END netdb.
|
||||
122
sockets.Mod
Normal file
122
sockets.Mod
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
MODULE sockets;
|
||||
IMPORT types, SYS := SYSTEM;
|
||||
|
||||
TYPE
|
||||
Int16* = types.Int16; (* INTEGER on 32 bit platform *)
|
||||
Int32* = types.Int32;
|
||||
Int64* = types.Int64;
|
||||
|
||||
CONST
|
||||
SockStream* = 1;
|
||||
SockDgram* = 2;
|
||||
SockRaw* = 3;
|
||||
SockRdm* = 4;
|
||||
SockSeqpacket* = 5;
|
||||
SockDccp* = 6;
|
||||
SockPacket* = 10;
|
||||
|
||||
AfUnscec* = 0; (* Unspecified. *)
|
||||
AfLocal* = 1; (* Local to host (pipes and file-domain). *)
|
||||
AfUnix* = 1; (* POSIX name for PF_LOCAL. *)
|
||||
AfFile* = 1; (* Another non-standard name for PF_LOCAL. *)
|
||||
AfInet* = 2; (* IP protocol family. *)
|
||||
AfAx25* = 3; (* Amateur Radio AX.25. *)
|
||||
AfIpx* = 4; (* Novell Internet Protocol. *)
|
||||
AfAppletalk* = 5; (* Appletalk DDP. *)
|
||||
AfNetrom* = 6; (* Amateur radio NetROM. *)
|
||||
AfBridge* = 7; (* Multiprotocol bridge. *)
|
||||
AfAtmpvc* = 8; (* ATM PVCs. *)
|
||||
AfX25* = 9; (* Reserved for X.25 project. *)
|
||||
AfInet6* = 10; (* IP version 6. *)
|
||||
AfRose* = 11; (* Amateur Radio X.25 PLP. *)
|
||||
AfDecnet* = 12; (* Reserved for DECnet project. *)
|
||||
AfNetbeui*= 13; (* Reserved for 802.2LLC project. *)
|
||||
AfSecurity*=14; (* Security callback pseudo AF. *)
|
||||
AfKey* = 15; (* PF_KEY key management API. *)
|
||||
AfNetlink*= 16;
|
||||
AfRoute* = 16; (* Alias to emulate 4.4BSD. *)
|
||||
AfPacket = 17; (* Packet family. *)
|
||||
AfAsh = 18; (* Ash. *)
|
||||
AfEconet* = 19; (* Acorn Econet. *)
|
||||
AfAtmsvc* = 20; (* ATM SVCs. *)
|
||||
AfRds* = 21; (* RDS sockets. *)
|
||||
AfSna = 22; (* Linux SNA Project *)
|
||||
AfIrda* = 23; (* IRDA sockets. *)
|
||||
AfPppox = 24; (* PPPoX sockets. *)
|
||||
AfWanpipe*= 25; (* Wanpipe API sockets. *)
|
||||
AfLlc* = 26; (* Linux LLC. *)
|
||||
AfCan* = 29; (* Controller Area Network. *)
|
||||
AfTipc* = 30; (* TIPC sockets. *)
|
||||
AfBluetooth* = 31; (* Bluetooth sockets. *)
|
||||
AfIucv* = 32; (* IUCV sockets. *)
|
||||
AfRxrpc* = 33; (* RxRPC sockets. *)
|
||||
AfIsdn* = 34; (* mISDN sockets. *)
|
||||
AfPhonet* = 35; (* Phonet sockets. *)
|
||||
AfIeee802154* = 36; (* IEEE 802.15.4 sockets. *)
|
||||
AfCaif* = 37; (* CAIF sockets. *)
|
||||
AfAlg* = 38; (* Algorithm sockets. *)
|
||||
AfNfc* = 39; (* NFC sockets. *)
|
||||
AfVsock* = 40; (* vSockets. *)
|
||||
AfMax* = 41; (* For now.. *)
|
||||
|
||||
InAddrAny* = 0;
|
||||
|
||||
TYPE
|
||||
|
||||
(* /usr/include/netinet/in.h *)
|
||||
InAddr* = RECORD
|
||||
SAddr* : Int32;
|
||||
END;
|
||||
|
||||
SockAddrIn* = RECORD
|
||||
SinFamily* : Int16;
|
||||
SinPort* : Int16;
|
||||
SinAddr* : InAddr;
|
||||
SinZero* : ARRAY 8 OF CHAR;
|
||||
END;
|
||||
(* /usr/include/sys/socket.h *)
|
||||
|
||||
SockAddr* = RECORD
|
||||
SaFamily* : Int16;
|
||||
SaData* : ARRAY 14 OF CHAR
|
||||
END;
|
||||
|
||||
PROCEDURE -socket(domain, type, protocol: Int32): Int32
|
||||
"(int)socket(domain, type, protocol)";
|
||||
|
||||
PROCEDURE Socket*(domain, type, protocol: Int32): Int32;
|
||||
BEGIN
|
||||
RETURN socket(domain, type, protocol)
|
||||
END Socket;
|
||||
|
||||
PROCEDURE -bind(sockfd: Int32; VAR addr: SockAddr; addrlen: Int32): Int32
|
||||
"(int)bind(sockfd, addr, addrlen)";
|
||||
|
||||
PROCEDURE Bind*(sockfd: Int32; VAR addr: SockAddr; addrlen: Int32): Int32;
|
||||
BEGIN
|
||||
RETURN bind(sockfd, addr, addrlen)
|
||||
END Bind;
|
||||
|
||||
PROCEDURE -listen(sockfd, backlog: Int32): Int32
|
||||
"(int)listen(sockfd, backlog)";
|
||||
|
||||
PROCEDURE Listen*(sockfd, backlog: Int32): Int32;
|
||||
BEGIN
|
||||
RETURN listen(sockfd, backlog)
|
||||
END Listen;
|
||||
|
||||
PROCEDURE -accept(sockfd: Int32; VAR addr: SockAddr; VAR addrlen: Int32): Int32
|
||||
"(int)accept(sockfd, addr, addrlen)";
|
||||
|
||||
PROCEDURE Accept*(sockfd: Int32; VAR addr: SockAddr; VAR addrlen: Int32): Int32;
|
||||
BEGIN
|
||||
RETURN accept(sockfd, addr, addrlen)
|
||||
END Accept;
|
||||
(* int connect(int sockfd, const struct sockaddr *addr,
|
||||
socklen_t addrlen); *)
|
||||
PROCEDURE Connect*(sockfd: Int32; VAR addr: SockAddr; addrlen: Int32): Int32 "(socklen_t)(connect(sockfd, addr, addrlen))";
|
||||
|
||||
BEGIN
|
||||
|
||||
|
||||
END sockets.
|
||||
38
types.Mod
Normal file
38
types.Mod
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
MODULE types;
|
||||
IMPORT SYS := SYSTEM;
|
||||
|
||||
|
||||
TYPE
|
||||
intarr64 = ARRAY 8 OF SYS.BYTE; (* to emulate int16 on x86_64; -- noch *)
|
||||
intarr32 = ARRAY 4 OF SYS.BYTE;
|
||||
intarr16 = ARRAY 2 OF SYS.BYTE;
|
||||
Int16* = intarr16; (* INTEGER on 32 bit platform *)
|
||||
Int32* = INTEGER;
|
||||
Int64* = LONGINT;
|
||||
String* = ARRAY 256 OF CHAR;
|
||||
|
||||
PROCEDURE LongintToInt16*(int: LONGINT; VAR int16: Int16);
|
||||
VAR longintarr : intarr64;
|
||||
BEGIN
|
||||
(*RETURN SYS.VAL(Int16, int)*)
|
||||
longintarr := SYS.VAL(intarr64, int);
|
||||
int16[0] := longintarr[0];
|
||||
int16[1] := longintarr[1]; (* this will work for little endian -- noch *)
|
||||
END LongintToInt16;
|
||||
|
||||
PROCEDURE IntegerToInt16*(int: INTEGER; VAR int16: Int16);
|
||||
VAR intarr : intarr32;
|
||||
BEGIN
|
||||
int16 := SYS.VAL(Int16, int)
|
||||
(*intarr := SYS.VAL(intarr32, int);
|
||||
int16[0] := intarr[0];
|
||||
int16[1] := intarr[1];*) (* this will work for little endian -- noch *)
|
||||
END IntegerToInt16;
|
||||
|
||||
PROCEDURE htons*(in: Int16; VAR out : Int16);
|
||||
BEGIN
|
||||
out[0] := in[1];
|
||||
out[1] := in[0];
|
||||
END htons;
|
||||
|
||||
END types.
|
||||
Loading…
Add table
Add a link
Reference in a new issue