This commit is contained in:
norayr 2017-04-13 18:42:03 +04:00
parent 2e4b60252a
commit e8c580bd24
4 changed files with 93 additions and 10 deletions

35
irc.Mod
View file

@ -1,5 +1,5 @@
MODULE irc;
IMPORT sockets, netdb, Platform, Strings, types, SYSTEM;
IMPORT sockets, netdb, Platform, Strings, types, Out, SYSTEM;
CONST strLen = 1024;
@ -19,25 +19,50 @@ VAR
BEGIN
l := SYSTEM.ADR(buf);
r := Platform.Write(fd, l, len);
IF r = -1 THEN
Out.String("write() failed."); Out.Ln;
HALT(1);
ELSE
Out.String("write() success."); Out.Ln;
END;
END rawWrite;
PROCEDURE connect;
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.aiFamily := sockets.AfInet;*)
hints.aiFamily := sockets.AfUnspec;
hints.aiSockType := sockets.SockStream;
hints.aiFlags := 0;
hints.aiProtocol := 0;
hints.aiProtocol := netdb.ipprotoTCP;
hints.aiAddrLen := 0;
hints.aiAddr := 0; hints.aiCanonName := 0; hints.aiNext := 0;
NEW(res);
tmp32 := netdb.getAddrInfo(host, port, hints, res);
conn := sockets.Socket(res^.aiFamily, res^.aiSockType, res^.aiProtocol);
IF tmp32 # 0 THEN
Out.String("getaddrinfo() failed"); Out.Ln;
HALT(1);
ELSE
Out.String("getaddrinfo() returned 0, success"); Out.Ln;
END;
conn := sockets.Socket(res^.aiFamily, res^.aiSockType, res^.aiProtocol);
IF conn = -1 THEN
Out.String("socket() returned -1, error"); Out.Ln;
HALT(1);
ELSE
Out.String("socket() succeeded."); Out.Ln;
END;
tmp32 := sockets.Connect(conn, res^.aiAddr, res^.aiAddrLen);
IF tmp32 = 0 THEN
Out.String("connect() succeeded."); Out.Ln;
ELSE
Out.String("connect() failed."); Out.Ln; HALT(1);
END;
(* "USER test 0 0 :test\r\n" *)
(* "NICK test\r\n\000\060 :test\r\n"*)