Linux TCP/IP programming : Nai, alla...
The Reverant
reverant at freemail.gr
Mon Jun 19 12:39:35 EEST 2000
On Mon, 19 Jun 2000, Stelios Xanthakis wrote:
> To proto sigoura tha ginete me kapio tropo. getsockname(3) prepei na kanei
> ti douleia. To sockaddr_in pou tha peraseis san sockaddr* tha prepei
> telika na exei ti dieftinsi tou allou host tin opia mporis meta na kaneis
> lookup. Afto tha ginei META to accept.
> Stelios
AND
Elias Athanasopoulos wrote:
> Mporeis na kaneis accept(), na deis apo th sockaddr_in pou 8a
> peraseis apo pou hr8e h aithsh, kai an 8es na ton apporipseis na
> tou kleiseis amesws to file descriptor tou.
Simfoni, ta ekana ta parapano kai kanontas rip gia na min pnigo ton
server, paratheto ton kodika, pou DEN doulevei sosta:
*** CUT HERE ***********************************
#include <fstream>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
extern int h_errno;
int main()
{
struct sockaddr_in address;
struct sockaddr_in remote;
struct hostent * remoteHost;
int sock, conn, i;
size_t addrLength=sizeof(struct sockaddr_in);
if((sock=socket(PF_INET, SOCK_STREAM, 0)) < 0)
cout << "Sock err\n";
i=1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
address.sin_family=AF_INET;
address.sin_port=htons(1234);
memset(&address.sin_addr, 0, sizeof(address.sin_addr));
bind(sock, (struct sockaddr *) &address, sizeof(address));
listen(sock,5);
while((conn=accept(sock, (struct sockaddr *) &address, &addrLength))>=0)
{
getsockname(sock, (struct sockaddr *) &remote, &addrLength);
remoteHost = gethostbyaddr((char *) &remote.sin_addr, sizeof(remote.sin_addr), AF_INET);
if(!remoteHost)
{
herror("Error");
}
close(conn);
}
close(sock);
return 0;
}
*** CUT HERE *************************************************
to trexo me:
./test
afou to kano compile kai prospatho na sindetho me telnet apo to idio mixanima
sto port 1234, kai afou kanei accept, mou leei:
Error: Host name lookup failure
o named doulevei sosta kai to /etc/hosts einai sosta simpliromeno
Help?
--
linux-greek-users mailing list -- http://lists.hellug.gr
More information about the Linux-greek-users
mailing list