Asthe title I am trying to make a linux sms system and was hoping I`d be able to send the data across in a structure. Is this possible or am I going to have to put all the data into a strings?
Asthe title I am trying to make a linux sms system and was hoping I`d be able to send the data across in a structure. Is this possible or am I going to have to put all the data into a strings?
You can send a structure if you want, as long as the receiving end has the same internal representation of the structure (byte alignment etc)
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
You can, but all these issues will hurt you at some point.
- your stucture contains pointers. The socket will not dereference them for you, and they will be meaningless to the receiver. It certainly wouldn't want to dereference it.
- your structure contains floats. The representation of floats are pretty machine specific, though most seem to use IEEE formats.
- your structure contains ints. Whether your machine is big endian or little endian (compared to the receiver) affects how ints are interpreted.
00 00 00 01 may be 1 on your machine, but read in reverse on a different endian machine, it would be 01 00 00 00 (much much bigger than 1)
The amount of padding between a and b is implementation specific. Ensuring the padding is the same at both ends can be tricky (and rarely optimal)Code:struct foo { char a; int b; };
The last 3 you can ignore, IF you're sending to an identical machine running the same code compiled with the same compiler.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The code is using sockets to send the data.
One side will set up a structure which will have an int followed by 3 strings.
sendto(sockfd, command, 180, 0,
(struct sockaddr *)&their_addr, sizeof(struct sockaddr));
THe structure is called command. its saying that the incompatible type for arg 2 of sendto/
any ideas?
Read the manual
&command, sizeof(command)
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
what manual?
do ya mean the man pages in linux?
they dont seem to have much details
> do ya mean the man pages in linux?
Well that would be a start
As would reading your C book again.
I mean, the error message pretty much explains the problem - the types are incompatible.
So you go read the manual page to find out what type the function really expects, and then work out how to get from the type you have to the type you want.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.