SmileeTiger
Programmer
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("Server received a messafe\n"
;
printf("from: %s\n", buf);
printf("from: %s\n", from);
printf("port: %d \n",from.sin_port);
printf("size: %d \n", rstat);
strcpy(buf, "This is my message"
;
sendto(sid,buf,sizeof(buf),0,&from,sizeof(from));
close(sid);
}
Smilee
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("Server received a messafe\n"
printf("from: %s\n", buf);
printf("from: %s\n", from);
printf("port: %d \n",from.sin_port);
printf("size: %d \n", rstat);
strcpy(buf, "This is my message"
sendto(sid,buf,sizeof(buf),0,&from,sizeof(from));
close(sid);
}
Smilee