[www-lib] <none>

hi! all, 

here is a program that i am wirting to access URL's from c program
it is connecting to the IP address that I am giviing but not getting 
any data from it.

It is also not working with URL's , that means i am not able to 
give "www.xxxxx" type of things here can any one please suggest any way 
for me any modification to be specific, I will be glad to accept any 
suggestion from you,

with regards,
Sudipto.


You can give reply to( donot reply to the address froom which I am mailing)


 sudipto74@yahoo.com


here is the programe that I am writing.


#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define SERVER_PORT 80
#define SERV_HOST_ADDR "203.163.50.62"
int readline(int fd, char *ptr,int maxlen)
{
	int n,rc;
	char c;

	for(n=1;n<maxlen;n++)
	{
		if ( (rc = read (fd,&c,1)) == 1 )
 		{
			*ptr++=c;
			if ( c =='\n') break;
		} else if  ( rc ==0 ) {
			 	if ( n==1) return(0);
				else break;	
			} else return(-1);
		
	}
	*ptr = 0;
	return(n);
}


int writen(int fd, char * ptr,int nbytes)
{
	int nleft, nwritten;

	nleft = nbytes;
	while (nleft > 0)
 	{
		nwritten = write (fd, ptr, nleft);
		if ( nwritten <= 0 ) return(nwritten);
		nleft -= nwritten;
		ptr += nwritten;
	}
	return(nbytes - nleft);
}

int str_cli(fp,sockfd)
FILE *fp;
int sockfd;
{
	int n;
	char sendline[80], recvline[81];

	while(fgets(sendline, 80,fp) != NULL )
	{
		n = strlen(sendline);
		if (writen(sockfd,sendline,n) != n )
		printf("written error on socket\n");
		
		n = readline(sockfd,recvline,80);
		if ( n<0) printf("readline error\n");
		recvline[n] = 0;
		fputs(recvline,stdout);
	}
	if (ferror(fp)) printf("error reading file\n");

}
int main(int argc, char *argv[])
{
	int sd;
	struct sockaddr_in serv_addr;


	
	
	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(SERVER_PORT);

	sd = socket(AF_INET, SOCK_STREAM,0 );
	
	if ( sd < 0 )
	{
		 printf("cannot open the socket");
		 exit(1);
	}

	if (connect(sd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0 )
	printf("cannot be connected\n");
	else {
		printf("connection established");
	}	
	str_cli(stdin,sd);
	close(sd);

	exit(0);

}

Received on Thursday, 19 October 2000 02:50:39 UTC