home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sibdemo3.zip
/
SAMPLES.DAT
/
SAMPLES
/
TCPIP
/
TCPTEST.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1997-08-17
|
4KB
|
158 lines
Program tcptest;
{Current Bugs}
{GetHostByAddr returns Nil. :(
Need to determine method to get the Longint address
from the HostEnt structure. }
Uses Tcpip, scstring;
Const Serv = 'sidney.ml.org'; {walnutcreek.ca.us.chatnet.org}
portst = '6667';
Nick = 'HWIRCTEST';
crlf = #13#10;
var rc: integer;
nym : string;
Port:word;
ircnick:pchar;
TmpMsg: cstring;
srbuf:array[0..511] of char;
RcBuf: Array[0..511] of char;
SrSz: integer;
Csocket: Integer;
CnameLength: integer;
Server: SockAddr_in;
HostName : PhostEnt;
HostNym : PHostEntInet;
ServAddr: Longword;
Tmpptr: PLongword;
TmpHost: HostEntInet;
tmplen: integer;
x,x2:integer;
Pc:Pchar;
servname: cstring;
Rre: Rrec;
Rretmpst : array[0..7] of cstring;
TmpLw:Longword;
{Tracer}
var Tx: file of char;
{end tracer}
Function NsLookup(HostNym:Cstring):LongWord;
Var Rc: integer;
srbuf:array[0..511] of char;
RcBuf: Array[0..511] of char;
Header: Prrechead;
Answer: Plrrec;
Trace1 : Lrrec;
Tmpst : Cstring;
TmpLW: Longword;
begin
rc := res_MkQuery(R_Query, @HostNym, C_IN, T_A, nil, 0, nil, @SrBuf, Sizeof(srbuf));
rc := Res_Send(@srbuf,rc,@rcbuf, Sizeof(rcbuf));
Header := Splitrrec(rcbuf,rc);
Answer := Header^.Answer;
Trace1 := answer^;
TmpSt := Answer^.rdata;
assign(tx,'cavewal.txt');
rewrite(tx);
For x2 := 0 to length(tmpst) do write(tx, tmpst[x2]);
close(tx);
TmpLw := longword(tmpst[0]) shl 24 + longword(tmpst[1]) shl 16 +
longword(tmpst[2]) shl 8 + longword(tmpst[3]);
NsLookup := TmpLw;
end;
Begin
If Paramstr(1) = '' then
Begin
Writeln('Usage: TCPTest ServerName');
halt(1);
End;
ServName := ParamStr(1);
{ If paramcount <> 3 then
begin
Writeln('Insufficent Parameters');
Writeln('Proper Format, '+Paramstr(0)+' <server> <port> <yernick>');
Readln;
Halt(3);
end;}
Res_init;
Ircnick := 'NICK '+nick+crlf;
If Sock_init <> 0 then
begin
Writeln('TCP Not Loaded.');
readln;
Halt(1);
end;
port := String2Word(Portst);
server.sin_port := htons(port);
If not checkIpaddress(servname) then
begin
TmpLw := nslookup(servname);
Write(GetDotted(Tmplw));
Readln;
end else
begin
ServAddr := Inet_addr(serv);
end;
csocket := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if Csocket < 0 then
begin
writeln('Socket Error');
readln;
Halt(2);
end;
server.sin_family := AF_INET;
server.sin_Addr := ServAddr;
rc := Connect(csocket, sockaddr(Server), Sizeof(server));
If Rc < 0 then
begin
psock_errno('Connect()');
readln;
Halt(5);
end;
Writeln('Connected');
TmpMsg := 'NICK '+Nick+CRLF;
//Tmpmsg := nym;
rc := send(csocket, @tmpmsg, length(tmpmsg), 0);
If RC < 0 then
Begin
Psock_errno('Send()');
Readln;
halt(7);
end;
Write(tmpmsg);
TmpMsg := 'USER kzinti host.name us.undernet.org :Kzinti RedClaw'+CRLF;
rc := send(csocket, @tmpmsg, sizeof(tmpmsg), 0);
If RC < 0 then
Begin
Psock_errno('Send()');
Readln;
halt(7);
end;
Write(tmpmsg);
rc := Recv(csocket, srbuf, Sizeof(srbuf), 0);
If Rc < 0 then
Begin
Psock_errno('Recv()');
readln;
halt(6);
end;
Writeln(srbuf);
Soclose(csocket);
Write('no errors, '); Readln;
end.