12-20-2007
1,
0
Join Date: Dec 2007
Last Activity: 20 December 2007, 4:46 AM EST
Posts: 1
Thanks Given: 0
Thanked 0 Times in 0 Posts
Bad Address
I am trying to write a C server code that will handle WWW request from client. i am very new to socket programming. i can very well setup the socket...but when an incomin request comes from a browser, the progrom exits with an error message "Bad address". the following is the code. please do help me at the earliest. thank you.I am woring in USS environment in MVS
#define _OPEN_THREADS
#define _OE_SOCKETS
#define _NO_PRAGMA
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "conv.c"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <xti.h>
int main()
{
int sd,bindval,listval,csd,counter;
int iNoDelay;
char buf<:50:>;
struct sockaddr_in server,client;
pthread_t tid;
printf("\nsocket abount to be created");
sd=socket(AF_INET,1,0);
perror(" ");
iNoDelay=1;
setsockopt(sd,IPPROTO_TCP,TCP_NODELAY,(char *) &iNoDelay,
sizeof(iNoDelay));
printf("\nsocket created with id %d",sd);
server.sin_family=AF_INET;
server.sin_addr.s_addr=174861723;
server.sin_addr.s_addr=inet_addr("10.108.45.155");
server.sin_port=9090;
bindval=bind(sd,(struct sockeaddr_in *) &server,sizeof(server));
printf("\nbind success with rc=%d",bindval);
perror(" ");
printf("%d",bindval);
bindval=listen(sd,5);
printf("\nlisten done rc=%d",bindval);
counter=0;
counter=0;
{
printf("\nwaiting for connections");
csd=sizeof(client);
csd=accept(sd,(struct sockaddr_in *) &client,csd);
perror(" ");
printf("\nconnection accepted rc=%d",csd);
read(csd,buf,49);
ASCII_to_EBCDIC(sizeof(buf),buf);
printf("%s\n",buf);
strcpy(buf,"HTTP/1.1 404 NOT FOUND \n \n");
EBCDIC_to_ASCII(sizeof(buf),buf);
send(csd,buf,sizeof(buf),0);
printf("\nwrite performed");
counter=counter+1;
}
perror(" ");
}
thank you