Hi,
I have a standard Internet Checksum function as follows:
uint16_t checksum_f(uint16_t *addr, uint32_t length) {
register long sum = 0;
Type: Posts; User: eponymous
Hi,
I have a standard Internet Checksum function as follows:
uint16_t checksum_f(uint16_t *addr, uint32_t length) {
register long sum = 0;
Actually, I think I will make it so that the message is no longer passed in as an argument and I could just get the message inside the function and that way, both options and message will be local...
Can you explain what you mean please?
Thanks.
The way it stands I have little choice as the program I'm communicating with is already made and cannot be changed.
I need to send one buffer in the form:
[<- 12 bytes of header->][<- variable...
Surely I can't use sizeof(message) though...
That's going to be 4 bytes wihch is wrong as the message could be up to 300 bytes long...
int some_function(char *message) {
DATE tx_header;
uint8_t options[64]; // this isn't always totally full (normally only the first two elements) so hence the strlen below:
void* tx_buffer =...
that should be fine because in the tx_header, there is a an offset field and a length_of_message field which tell the receiver where everything is.
hmm, do I actually need to do this then:
void* tx_buffer = malloc(sizeof(tx_header) + strlen(options) + 1 + strlen(message) + 1);
"sizeof(tx_header) + strlen(options) + 1 + strlen(message) + 1"...
Am I right in assuming the "+ 1" is needed because tx_buffer will have a \0 on the end of it?
btw, tx_header is a struct - I made a mistake in my prev post.
corrected to : "DATE tx_header"
Ok, so I need to pass the size of tx_header to function.
Shall I just pass: "sizeof(tx_header)...
Ok, so presumably:
tx_buffer will look like this:
options[0] = 0;
options[1] = 1;
[<-12 bytes of header->][<- 2 bytes of options ->][<-10 bytes of message->]
so what function will get...
Both options and message are strings, so I don't see the problem. I pass in a char line_buf[300] as the argument to the function, so I'd assume strlen would be ok for this?
The point I'm trying to...
hmm slight problem:
I have this kind of thing:
int some_function(char *message) {
DATE tx_header;
uint8_t options[64]; // this isn't always totally full (normally only the first two...
Sorry, that getchar() was meant to be removed. It actually looks like:
do
{
printf("Encrypt (Y / N)");
while ((key = getchar()) != '\n' && key != EOF);
} while (!(key == 'N'...
I've tried this:
do
{
printf("Encrypt (Y / N)");
while ((key = getchar()) != '\n' && key != EOF);
getchar();
} while (!(key == 'N' || key == 'Y'));
char key;
do
{
printf("Encrypt (Y / N)");
key = getchar();
}while(!(key=='N' || key=='Y'));
Is there a way to achieve the same thing without using scanf?
Thanks guys. I'll just use strlen. It seems to work.
I just made up the example in my post. I didn't bother to copy my actual program as it would take too long, so just ignore the lack of return...
Hi,
I have the following:
function (char *message) {
printf("sizeof(message) is: %d", sizeof(message));
printf("strlen(message) is: %d", strlen(message));
Hi,
I want to have the following in my program:
"Encrypt message ? (Y / N):"
If the user enters Y then a boolean variable is set to true and if they enter N a boolean variable is set to...
Thanks all! :)
Could you please give me an example of how you would do this?
Thanks!
#include <sys/socket.h>
ssize_t sendto(int socket, const void *message, size_t length,
int flags, const struct sockaddr *dest_addr,
socklen_t dest_len);
With that definition, I...
Thanks for your amazingly fast reply!
That make perfect sense now.
Do you also know how I could string together the following to make one argument
to pass to sendto() which takes a message in...
Hi,
I just wanted to clear something up regarding structs.
Why is it that I can declare a strut like this:
typedef struct date_header {