The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
Google UNIX.COM
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Dec 2007
Posts: 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by shankarramv View Post
csd=accept(sd,(struct sockaddr_in *) &client,csd);
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".
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 02:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102