1 msggcc-4.1.2 build help
2 msgGcc build error
2 msgregarding optimization flags
2 msgrelocation errors
4 msghelp for math fuctions
2 msgError in GCC build
10 msgIs fixinclude needed on modern systems?
2 msgHi can you please help me
1 msgto: Unable to compile large projects
1 msgBuilding gcc 4.1.2 - gengtype can't find files

need help with DGRAM socket
\ Meitham (23 Feb 2007)
. \ Bud Davis (23 Feb 2007)

4 msgWhat happens when -O1 flag is used?
3 msgBest mcpu option for amcc440 with fpu ?
1 msgmakedepend.c error
9 msglist of optimizations done by -O1 level
1 msgWinPorts GCC 4.1.2 is out [win32 build]
4 msgstrange floating point problem
1 msgRe: 'Error: suffix or operands invalid for `pus...
2 msgproblem with 'nanosleep()'
5 msgg++ compile time calculations
Subject:need help with DGRAM socket
Group:Gcc-help
From:Meitham
Date:23 Feb 2007


Hi,

I am trying to use a datagram socket in the client side to send a pocket
but with no luck. I have a server running on the machine listening on
port 5000. What is wrong with this code? And, does anyone please can
write a simpler code to send a packet to DGRAM socket on localhost.
I keep getting this error:

lamp.c: In function ‘chgStatus’:
lamp.c:62: warning: assignment makes pointer from integer without a cast
lamp.c:65: error: dereferencing pointer to incomplete type
lamp.c:67: error: dereferencing pointer to incomplete type
lamp.c:75: warning: passing argument 5 of ‘sendto’ from incompatible
pointer type


Thanks in advance
~Meitham


Code of the method in lamp.c

void chgStatus (short status) {
int sock, length, n;
struct sockaddr_in server;
struct hostent *hp;
int portno = 5000;
char buffer[256];
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) error("ERROR opening socket");

server.sin_family = AF_INET;
hp = gethostbyname("localhost");
if (hp==0) error("Unknown host");
bzero((char *) &server, sizeof(server));
bcopy((char *)hp->h_addr,
(char *)&server.sin_addr,
hp->h_length);
server.sin_port = htons(portno);
length = sizeof(struct sockaddr_in);

if (status) strcpy(buffer, "C1");
else strcpy(buffer, "C0");
n = sendto(sock, buffer,
strlen(buffer),
0, &server, length);

if (n < 0) error("ERROR sending to socket");
printf("%s\n",buffer);
return;
}



© 2004-2008 readlist.com