I will be very thankful if someone could give me help
I have one linux server(RedHat 9.0) running Apache 2.40.40, I configure it
with ipv6, the ipv6 address is fec0::2. another linux machine(RedHat 9.0)
run as the client with the ipv6 address of fec0::3
I use a small c program to use socket to connect to port 80 of the linux
server, send a GET http request and want to receive on the socket to get
the requested file. But it blocked when read from the socket.
The following is the client program:
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
int main(void)
{
int sockfd;
FILE *fp;
int n;
char buf[256];
struct sockaddr_in6 serv_addr;
bzero(&serv_addr, sizeof(struct sockaddr_in6));
fp=fopen("lgl.txt", "wb");
serv_addr.sin6_family=AF_INET6;
serv_addr.sin6_port=htons(80);
inet_pton(AF_INET6, "fec0::2", &(serv_addr.sin6_addr));
sockfd=socket(PF_INET6, SOCK_STREAM, 0);
if(socket < 0) {
perror("socket");
exit(1);
}
if(connect(sockfd, (struct sockaddr *)&serv_addr, \
sizeof(struct sockaddr_in6))<0) {
perror("connect");
exit(1);
}
n=write(sockfd,"GET /lll.txt\r\n", 16);
printf("GET sent %d\n",n);
while((n=read(sockfd, buf, 256)) > 0) {
printf("recv %d:%s\n", n, buf);
fwrite(buf, n, 1, fp);
}
fclose(fp);
return 0;
}
the file 111.txt is in /var/www/html directory. I use ethereal to capture
the traffic, and found that the connection is established between fec0::2
and fec0::3 successfully, and the server received the "GET /111.txt\r\n"
request, then the server begin to send back the content of 111.txt, But
problem is that the client didn't send ACK now, so the server send the
content again and again, and the client blocked at read.
I changed the ipv6 address with ipv4 address, and all worked very well.
I write a server instead of using Apache, and the communication between
the server and the client seems very good.
Could anyone tell me the reason?
|