From e8c580bd24a9fd447532921a2a2bbff8186d14c6 Mon Sep 17 00:00:00 2001 From: norayr Date: Thu, 13 Apr 2017 18:42:03 +0400 Subject: [PATCH] smth --- Makefile | 2 +- irc.Mod | 35 ++++++++++++++++++++++++++++++----- netdb.Mod | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.Mod | 15 +++++++++++---- 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 0b65e19..827b6e4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VOC = /opt/voc/bin/voc all: - $(VOC) -s types.Mod sockets.Mod netdb.Mod irc.Mod + $(VOC) -s types.Mod sockets.Mod netdb.Mod irc.Mod test.Mod -m clean: rm *.h diff --git a/irc.Mod b/irc.Mod index f7e81ef..aea818c 100644 --- a/irc.Mod +++ b/irc.Mod @@ -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"*) diff --git a/netdb.Mod b/netdb.Mod index 3ed15e0..f036694 100644 --- a/netdb.Mod +++ b/netdb.Mod @@ -2,6 +2,57 @@ MODULE netdb; IMPORT SYSTEM; +CONST + ipprotoIP* = 0; + + ipprotoICMP* = 1; + + ipprotoIGMP* = 2; + + ipprotoIPIP* = 4; + + ipprotoTCP* = 6; + + ipprotoEGP* = 8; + + ipprotoPUP* = 12; + + ipprotoUDP* = 17; + + ipprotoIDP* = 22; + + ipprotoTP* = 29; + + ipprotoDCCP* = 33; + + ipprotoIPV6* = 41; + + ipprotoRSVP* = 46; + + ipprotoGRE* = 47; + + ipprotoESP* = 50; + + ipprotoAH* = 51; + + ipprotoMTP* = 92; + + ipprotoBEETPH* = 94; + + ipprotoENCAP* = 98; + + ipprotoPIM* = 103; + + ipprotoCOMP* = 108; + + ipprotoSCTP* = 132; + + ipprotoUDPLITE* = 136; + + ipprotoMPLS* = 137; + + ipprotoRAW* = 255; + TYPE Int32* = LONGINT; Int64* = HUGEINT; diff --git a/test.Mod b/test.Mod index 8d1f073..0588bbb 100644 --- a/test.Mod +++ b/test.Mod @@ -1,20 +1,27 @@ MODULE test; +IMPORT irc; + VAR -botOwner, nick, serv, chan: ARRAY 32 OF CHAR; +owner, nick, serv, port, chan: ARRAY 32 OF CHAR; PROCEDURE testBot; BEGIN - - +irc.nick := nick; +irc.host := serv; +irc.port := port; +irc.channel := chan; +irc.user := owner; +irc.connect; END testBot; BEGIN -botOwner := "norayr"; +owner := "norayr"; nick := "norayr"; serv := "irc.freenode.net"; +port := "6667"; chan := "#oberon"; testBot;