Linux program to fetch file from Apache Server

/* Linux program to fetch file from Apache Server */


#include"/usr/include/linux/inet.h"
#include"isc/socket.h"
#include"stdio.h"
#define SERV_TCP_PORT 80
#define SERV_HOST_ADDR "10.0.1.106"
#define MAXLINE 30000
main()
{
int i,sockfd;
FILE *fn;
char *line;
struct sockaddr_in serv_addr;
char sendline[MAXLINE] = { "GET /rcert.html /HTTP/1.0 \n\n" };
char recvline[MAXLINE];
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
serv_addr.sin_port = htons(SERV_TCP_PORT);
printf("Creating Socket.........\n");
sockfd = socket(AF_INET, SOCK_STREAM, 0);
printf("Socket Created..........\n");
if(i = connect (sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))<0)
printf("Unable to connect............\n");
printf("Connected to the server = %d...........", i);
send(sockfd, sendline, 512, 0);
recv(sockfd, recvline, 30000, 0);
i=0;
while(i<=30000)
{
printf("%c", recvline[i]);
i++;
}
}
Previous
Next Post »