help regardin c header file..

v1gnesh

Adept
guys.. im lookin for a header file "in.h" that comes in the folder netinet..
i.e.,
<ur c compiler>/include/netinet/in.h
this "netinet" folder isnt available by default in most of the c compilers i tried..
i was looking for socket.h too..
i got that from some site :|
but i cudnt find "in.h"
can someone guide me as to where i can find it ..
 
Which c compilers did you look at (NOT TCC)? Which OS? Hint: /usr/include/netinet/in.h if you are using a GNU/Linux system. I don't remember the windows path, but it would be simple enough as well if you have visual studio installed, though it should be noted that while Windows sockets are similar to BSD sockets, they aren't the same.
 
^^I doubt he is using windows.we have wininet in windows not in.h .in.h header file comes usually in unix platform.Pls give us the name of the compiler and OS to enable us to help u better.As King Krool said , try in this folder /usr/include/netinet/in.h or find in.h to search the file in linux.
 
yeah. m usin windows xp and ill post in the code i have(which is for converting data to packets ... create a socket.. to bind a socket to a port..and send it to a destination ip using tcp/ip..) im entirely new to usin unix/linux.. so i haev no clue as to which platform i should use the code in ...

ill post the code within 24 hours.. not on my pc for now .. :S

thx for d help..

n yea i tried usin TC..microsoft visual studio 2005..now usin devc++

i have no idea how to use visual c++ n it was too heavy on my system..

basically..

all the compilers i used so far..dint have the header files i was looking for

1.socket.h

2.in.h

i know it wud b much easier fr u guys to decide wht i must do if i had posted the code..

ill get it up ASAP..

thx for d help.

:)
 
Well i think dev c++ uses mingw collection then. Its a windows only collection of header files, and those two headers will be missing. Developing in a linux environment will definitely help cause gcc was originally meant for that platform.

and yea, you can try downloading the header files. Should work if they aren't dependent on other headers/classes
 
yea seems to be a linux only header. So its better you shift to linux for development. And its not that tough actually. You can start with any easy to use distros like ubuntu/suse
 
Any particular reason for using this particular code that you have.you can do the same thing using windows using the link which i posted above.
 
actually im an engg student enterin 2nd yr now..

am doin this thing as an in-plant training

got lucky and had a chance to undergo in-plant training in HCL

wht else can i expect..

endin up wid a project in 4th sem portions :S

and yeah..

the guy in HCL whose incharge of my project..

he suggested tht i used the code he gave us..

i did find other codes ..tht wud work for java n c++ here n there..

but..whn i have the proper code tht he gave..

its better i figure out wht i can do to atleast compile it :p
 
for now .. i have only a hardcopy of the code..
wil get a scan of the code n post it within tonite.. n get the softcopy by tomorrow mornin..
thn maybe i cud help u help me better :p
 
@sandy..

here's the code i was talkin about..

sorry abt the delay..

on the client side..

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#include<netdb.h>

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

#include<unistd.h>

#define SRV_TCP_PORT 27000

#define MAX_MSG 100

void errExit(char *str)

{

puts(str);

exit(0);

}

void main()

{

clrscr();

int sockfd, newsockfd;

struct sockaddr_in cliadr, srvadr;

int clilen, n;

char mesg[MAX_MESG];

if((sockfd = socket(AF_INET, SOCK_STREAM, 0))<0)

errExit(" Can't open stream socket ");
/* bind server port */

memset(&srvadr,0,sizeof(srvadr));

srvadr.sin_family = AF_INET;

srvadr.sin_addr.s_addr = htonl(INADDR_ANY);

srvadr.sin_port = htons9SRV_TCP_PORT);

if(bind(sockfd, (struct sockaddr*) &srvadr, sizeof(srvadr))<0)

errExit(" Can't bind local address");

listen(sockfd,5);

while(1)

{

printf(" Server waiting for new connection : \n");

//clilen = sizeof(cliaddr);

newsockfd = accept(sockfd, (struct sockaddr*) &cliadr, &clilen);

if(newsockfd<0)

errExit(" Accept Error \n");

printf("connected to the client \n");

/* receive segments */

while(1)

{

n = recv(newsockfd,mesg,MAX_MSG,0)

if(n<0)

errExit(" Receive Error \n");

if(n==0)

{

close(newsockfd);

break;

}

if(send(newsockfd,mesg,n,0) != n)

errExit(" Send Error \n");

printf(" Received ans sent the following message : %s \n", mesg);

} /* while(read_line) */

} /* while(1) */

getch();

}

and for the server....

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#include<netdb.h>

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

#include<unistd.h> /* close */

#define SRV_IP_ADRS "10.102.11.20"

#define SRV_TCP_PORT 27000

#define MAX_MSG 100

void errExit(char *str)

{

puts(str);

exit(0);

}

int main()

{

int sockFd;

struct sockaddr_in srvAdr;

char txmsg[MAX_MSG];

char rxmsg[MAX_MSG];

int n;

if((sockfd = socket(AF_INET,SOCK_STREAM,0))<0)

errExit(" Can't open socket ");
memset(&srvAdr,0,sizeof(srvAdr));

srvAdr.sin_family = AF_INET;

srvAdr.sin_addr.s_addr = inet_addr(SRV_IP_ADRS);

srvAdr.sin_port = htons(SRV_TCP_PORT);

if(connect(sockFd, (struct sockaddr *) &srvAdr, sizeof(srvAdr))<0)

errExit(" Can't connect to server");

while(1)

{

printf(" Enter the message to send , Enter # to exit : \n");

fgets(txmsg,MAX_MSG,stdin);

if(txmsg[0]=='#')

break;

n = strlen(txmsg)+1;

if(send(sockFd,txmsg,n,0) != n)

errExit(" Send Error \n ");

n=recv(sockFd,rxmsg,MAX_MSG,0);

if(n<0)

errExit(" Receive Error \n");



printf(" Received following message : %s \n",rxmsg);

}

close(sockFd);

getch();

return(0);

}

lookin forward for some reply n help..:(

thx in advance..
 
The headers are recognized on linux. I've been through the client program, and there were a few typos. Im attaching the modified code

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#include<netdb.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<unistd.h>

#define SRV_TCP_PORT 27000

#define MAX_MSG 100

void errExit(char *str)

{

puts(str);

exit(0);

}

int main()

{

int sockfd, newsockfd;

struct sockaddr_in cliadr, srvadr;

int clilen, n;

char mesg[MAX_MSG];

if((sockfd = socket(AF_INET, SOCK_STREAM, 0))<0)

errExit(" Can't open stream socket ");

/* bind server port */

memset(&srvadr,0,sizeof(srvadr));

srvadr.sin_family = AF_INET;

srvadr.sin_addr.s_addr = htonl(INADDR_ANY);

srvadr.sin_port = htons(SRV_TCP_PORT);
if(bind(sockfd, (struct sockaddr*) &srvadr, sizeof(srvadr))<0)

errExit(" Can't bind local address");

listen(sockfd,5);

while(1)

{

printf(" Server waiting for new connection : \n");
//clilen = sizeof(cliaddr);

newsockfd = accept(sockfd, (struct sockaddr*) &cliadr, &clilen);

if(newsockfd<0)

errExit(" Accept Error \n");

printf("connected to the client \n");

/* receive segments */

while(1)

{

n = recv(newsockfd,mesg,MAX_MSG,0);

if(n<0)

errExit(" Receive Error \n");

if(n==0)

{

close(newsockfd);

break;

}

if(send(newsockfd,mesg,n,0) != n)

errExit(" Send Error \n");

printf(" Received ans sent the following message : %s \n", mesg);

} /* while(read_line) */

} /* while(1) */

return 0;

}

I dont know how the bind() function works. There is an error in that. Maybe you can fix it :)
 
Back
Top