[fpc-pascal]winsock telnet proxy question #1

ron wilson ron.wilson at coastgames.com
Wed Mar 13 07:21:17 CET 2002


i figured the problem out... it was a silly error on my part - i forgot to
initialize the winsock system.

  if not(wsastartup($2,wsadata)=0) then sock_error(proxy,'wsastartup()')

after that, i had to figure out what the C bcopy() command did and reverse
engineer it.  i don't think freepascal has one of those.  or maybe it
does... can anybody tranlsate this line into freepascal for me?  all the
type-casting got me lost in fp.

  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
server->h_length);

note: server->h_addr is ^pchar and serv_addr.sin_addr.s_addr is u_long.

the code works great now - i have it pretty much compartmentalized, but i am
not bothering to write classes since i don't have any experience doing that
in freepascal.  i have the client and server portions both working in my
proxy program.  i can make multiple connections to any telnet server through
my proxy.

now all i have to do is the user interface and database engine.  i need to
parse all the data as it comes in and mine it for relevant data.  i'm
thinking a simple state-machine would cut down on the overhead a lot.  also,
i want to avoid using the pos() command for speed.  since i'm designing a
proxy for a telnet game, speed and reaction time is very important.  too
many clock cycles on parsing would hurt me.  anybody have any suggestions?

regards,
ron wilson.

-----Original Message-----
From: fpc-pascal-admin at deadlock.et.tudelft.nl
[mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of
adeli at adeli.fr
Sent: Tuesday, March 12, 2002 05:13 PM
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: RE: [fpc-pascal]winsock telnet proxy question #1



i'will try your soft when i'have reinstalled the fpc on my win98!
newly formated! no crash but new computer...

> in a dos window, i can type "ping localhost" and it pings 127.0.0.1
> correctly.  i am also able to connect to my local telnet server via
> telnet to 'localhost'.  i'm pretty sure it is configured correctly.
>
> regards,
> ron wilson.
>
> -----Original Message-----
> From: fpc-pascal-admin at deadlock.et.tudelft.nl
> [mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of
> adeli at adeli.fr
> Sent: Monday, March 11, 2002 11:54 AM
> To: fpc-pascal at deadlock.et.tudelft.nl
> Subject: Re: [fpc-pascal]winsock telnet proxy question #1
>
>
>
>
>
> you have trying  to do this under Windows ?
>
> if your dns is missconfigured there is no correspondance with
> localhost and 127.0.0.1 !
>
>
> > ok, after a lot of homework and some help from this list, i have got
> > my telnet server working correctly - it can accept multiple client
> > connections and pass communication to and from the clients.  (i have
> > only tested it locally, but that is all i need.)  in order to make
> > my proxy complete, the SAME program has to connect to another telnet
> > server and pass the information to the other clients.  so my program
> > needs to be a server AND a client.
> >
> > i tried to write a stand-alone client just to get the feel of how to
> > write functional client code, and i have come to an impasse.  i have
> > a telnet server running on my pc on port 23, and i would like to
> > connect to that server using my client.  so far it compiles fine,
> > and runs fine, but gethostbyname ('localhost') returns nil.  here's
> > my code (the error handling is infantile, i know):
> >
> > __________________________________
> > program client;
> >
> > uses
> >   winsock, crt, strings;
> >
> > var
> >   wsadata : twsadata;
> >   sockfd : tsocket;
> >   server : phostent;
> >   serveraddr : tsockaddr;
> >   n: integer;
> >   name : pchar;
> >   buffer : array[0..256] of char;
> >
> > function buildaddr(family: smallint; port: u_short; addr: u_long):
> > tsockaddr; var
> >   a: tsockaddr;
> > begin
> >   a.sin_family:=family;
> >   a.sin_port:=htons(port);
> >   a.sin_addr.s_addr:=addr;
> >   buildaddr:=a;
> > end;
> >
> > begin
> >   getmem(name,sizeof('localhost')+1);
> >   strcopy(name,'localhost');
> >
> >   writeln('retrieving socket....');
> >   sockfd := socket(AF_INET, SOCK_STREAM, 0);
> >   if (sockfd = INVALID_SOCKET) then halt;
> >
> >   writeln('getting host name....',name);
> >   server := gethostbyname(name);
> >   if server=nil then halt;  // PROGRAM HALTS HERE
> >
> >   writeln('building address....');
> >   serveraddr:=buildaddr(AF_INET, 23, u_long(server^.h_addr));
> >
> >   writeln('connecting socket....');
> >   if (connect(sockfd,serveraddr,sizeof(serveraddr))<0) then halt;
> >
> >   n:=recv(sockfd,buffer,255,0);
> >   writeln(buffer);
> >
> >   closesocket(sockfd);
> >   freemem(name);
> >   wsacleanup;
> > end.
> > __________________________________
> >
> > why doesn't it find the host for 'localhost' - isn't that a correct
> > host name?  also, any other style and/or coding advice not related
> > to gethostbyname would be appreciated.
> >
> > thanks for the help,
> > ron wilson.
> >
> >
> > _______________________________________________
> > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
>
>
>
> Lionel Drevon			ldrevon at adeli.fr
> Adeli				http://www.adeli.fr
> 618 Av. Gal de Gaulle		Tel 04 78 66 11 85
> 69760 Limonest			Fax 04 78 66 04 33
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Lionel Drevon			ldrevon at adeli.fr
Adeli				http://www.adeli.fr
618 Av. Gal de Gaulle		Tel 04 78 66 11 85
69760 Limonest			Fax 04 78 66 04 33

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal






More information about the fpc-pascal mailing list