Search:

Type: Posts; User: eponymous

Search: Search took 0.00 seconds.

  1. Correct way to pass arguments to this function

    Hi,

    I have a standard Internet Checksum function as follows:


    uint16_t checksum_f(uint16_t *addr, uint32_t length) {


    register long sum = 0;
  2. Replies
    35
    Views
    3,619

    Actually, I think I will make it so that the...

    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...
  3. Replies
    35
    Views
    3,619

    Can you explain what you mean please? Thanks.

    Can you explain what you mean please?

    Thanks.
  4. Replies
    35
    Views
    3,619

    The way it stands I have little choice as the...

    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...
  5. Replies
    35
    Views
    3,619

    Surely I can't use sizeof(message) though... ...

    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...
  6. Replies
    35
    Views
    3,619

    int some_function(char *message) { DATE...

    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 =...
  7. Replies
    35
    Views
    3,619

    that should be fine because in the tx_header,...

    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.
  8. Replies
    35
    Views
    3,619

    hmm, do I actually need to do this then: void*...

    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"...
  9. Replies
    35
    Views
    3,619

    Am I right in assuming the "+ 1" is needed...

    Am I right in assuming the "+ 1" is needed because tx_buffer will have a \0 on the end of it?
  10. Replies
    35
    Views
    3,619

    btw, tx_header is a struct - I made a mistake in...

    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)...
  11. Replies
    35
    Views
    3,619

    Ok, so presumably: tx_buffer will look like...

    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...
  12. Replies
    35
    Views
    3,619

    Both options and message are strings, so I don't...

    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...
  13. Replies
    35
    Views
    3,619

    hmm slight problem: I have this kind of thing:...

    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...
  14. Replies
    12
    Views
    1,551

    Sorry, that getchar() was meant to be removed. It...

    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'...
  15. Replies
    12
    Views
    1,551

    I've tried this: do { printf("Encrypt...

    I've tried this:


    do
    {
    printf("Encrypt (Y / N)");
    while ((key = getchar()) != '\n' && key != EOF);
    getchar();
    } while (!(key == 'N' || key == 'Y'));
  16. Replies
    12
    Views
    1,551

    char key; do { printf("Encrypt (Y /...

    char key;


    do
    {
    printf("Encrypt (Y / N)");
    key = getchar();

    }while(!(key=='N' || key=='Y'));
  17. Replies
    12
    Views
    1,551

    Is there a way to achieve the same thing without...

    Is there a way to achieve the same thing without using scanf?
  18. Replies
    3
    Views
    1,802

    Thanks guys. I'll just use strlen. It seems to...

    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...
  19. Replies
    3
    Views
    1,802

    sizeof / strlen which one?

    Hi,

    I have the following:


    function (char *message) {

    printf("sizeof(message) is: %d", sizeof(message));
    printf("strlen(message) is: %d", strlen(message));
  20. Replies
    12
    Views
    1,551

    Good single character option function

    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...
  21. Replies
    35
    Views
    3,619

    Thanks all! :)

    Thanks all! :)
  22. Replies
    35
    Views
    3,619

    Could you please give me an example of how you...

    Could you please give me an example of how you would do this?
    Thanks!
  23. Replies
    35
    Views
    3,619

    #include ssize_t sendto(int...

    #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...
  24. Replies
    35
    Views
    3,619

    Thanks for your amazingly fast reply! That...

    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...
  25. Replies
    35
    Views
    3,619

    Issue with Structs

    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 {
Results 1 to 25 of 25