THIS CODE through a segmentation fault at PC= 0x80485e9 "from GDB"
and I donot know why ?? can any one help ?
#include<stdio.h>
#include<unistd.h>
#include<sys/socket.h>
#include<stdlib.h>
#include<netdb.h>
#include<string.h>
#define execption_handler(msg) \
do { perror(msg) ;} while(0)
void client_side_work(int sfd)
{
// This is just a get_handler function
// fdopen(sfd,"r+");
//char* message[100]; //This just for testing if sprintf() use malloc()
or not
char* message;
sprintf(message,"GET /index.html\n");
write(sfd,message,sizeof(message));
int nread;char buffer[1000];
nread = read(sfd,buffer,sizeof(buffer));
if (nread == 0)
return ;
if (!close(sfd) )
execption_handler("close()");
}
int main()
{
int sfd;
struct addrinfo myAddrInfo,*serverAddr;
myAddrInfo.ai_family = AF_UNSPEC;
myAddrInfo.ai_socktype = SOCK_STREAM ;
// myAddrInfo.ai_addr !! struct sockaddr
if (getaddrinfo("localhost","80",&myAddrInfo,&serverAddr))
execption_handler("getaddrinfo()");
if ( (sfd = socket(serverAddr->ai_family, serverAddr->ai_socktype,
serverAddr->ai_protocol)) == -1 )
execption_handler("socket()");
if ( connect(sfd,serverAddr->ai_addr ,serverAddr->ai_addrlen) == -1 )
execption_handler("connect()");
client_side_work(sfd);
return 0;
}