Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCP/Ip error question (kinda simple)

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
Hi,

I compliled a piece of code today but when I do I get the following warnings..
server.c:43: warning: passing arg 2 of `bind' from incompatible pointer type
server.c:45: warning: passing arg 5 of `recvfrom' from incompatible pointer type
server.c: In function `SendMessage':
server.c:122: warning: passing arg 2 of `bind' from incompatible pointer type
server.c:130: warning: passing arg 5 of `sendto' from incompatible pointer type
gcc -o server server.o -lm -lsocket -lnsl

I kinda want to get rid of them any ideas?

The code is as follows:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORTNUM 2222 //Change after...

char buf[20];

main()
{
int sid, rstat, fromlen;
struct sockaddr_in insock, from;
sid=socket(AF_INET, SOCK_DGRAM, 0); //creates a communications endpoint
insock.sin_family=AF_INET;
insock.sin_addr.s_addr=INADDR_ANY;
insock.sin_port=PORTNUM;
bind(sid, &insock, sizeof(insock));
fromlen=sizeof(from);
rstat=recvfrom(sid,buf,sizeof(buf),0,&from,&fromlen);
printf(&quot;Server received a messafe\n&quot;);
printf(&quot;from: %s\n&quot;, buf);
printf(&quot;from: %s\n&quot;, from);
printf(&quot;port: %d \n&quot;,from.sin_port);
printf(&quot;size: %d \n&quot;, rstat);
strcpy(buf, &quot;This is my message&quot;);
sendto(sid,buf,sizeof(buf),0,&from,sizeof(from));
close(sid);
}



Smilee
 
The reason I suggested that is because my man page prototypes bind, recvfrom and sendto as needing pointer to a struct sockaddr in the places where you're passing a pointer to a struct sockaddr_in. Look over your documentation, do the prototypes for those functions _exactly_ match how you're trying to call them?

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top