[fpc-pascal]winsock telnet proxy question #1
ron wilson
ron.wilson at coastgames.com
Mon Mar 11 21:10:59 CET 2002
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
More information about the fpc-pascal
mailing list