![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| IP Networking Questions involving TCP/IP, Routers, Hubs, Network protocols, etc go here. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SCO get MAC Address | jcarter2333 | High Level Programming | 11 | 02-08-2007 05:51 AM |
| How to Achive IP address through MAC(Ethernet) address | krishnacins | IP Networking | 3 | 08-29-2005 05:45 PM |
| ce0 and ce1 have the same mac address | BG_JrAdmin | SUN Solaris | 2 | 07-08-2005 04:30 PM |
| network address and broadcast address? | pnxi | UNIX for Dummies Questions & Answers | 7 | 11-10-2003 07:29 PM |
| IP address | krishna | UNIX for Advanced & Expert Users | 10 | 03-20-2002 01:36 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
That looks all wrong.
The last arg should be the address of a socklen_t, and you are also reusing the variable as a file descriptor. I suggest you compile with maximum warnings, if using gcc use "-Wall -Werror". |
|||
| Google UNIX.COM |