Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:06:33+00:00 2026-06-16T05:06:33+00:00

I have the following struct and I’m trying to send over the network to

  • 0

I have the following struct and I’m trying to send over the network to another application

 struct protocol
  {

     char protocol;
     char field1;
     char field2;
     char field3;
     char field4;
     char field5;
     char field6;
     char field7;
     char field8;
     char msg_id;
     char msg_length;
     char *msg;

  };

The problem I’m having is that I’m not sure how to send this struct over the network as there is a pointer pointing to a string in it, and memcpy the struct to buffer won’t work, is the below the only way to do it?

memcpy (buffer, protocol->protocol, char)
memcpy (buffer, protocol->field1, char)
...
memcpy (buffer, protocol->msg, protocol->length)

then send the buffer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:06:35+00:00Added an answer on June 16, 2026 at 5:06 am

    You will need to serialize the structure into a buffer of some sort. Your sequence of copies is correct in concept only; there are a myriad details to resolve:

    char buffer[sizeof(struct protocol) + protocol->msg_length]; // Over-allocation
    
    buffer[0] = protocol->protocol;
    buffer[1] = protocol->field1;
    ...
    buffer[8] = protocol->field8;
    buffer[9] = protocol->msg_id;
    buffer[10] = protocol->msg_len;
    memcpy(&buffer[11], protocol->msg, protocol->msg_len);
    

    Now you can write the correct length of buffer (11 + protocol->msg_len) to send.

    This is particularly simple; there are no endian-ness issues to worry about. Generally, with multi-byte values like short or int or long long, you have to worry about the transmitted byte order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have declared the following struct: typedef struct _RECOGNITIONRESULT { int begin_time_ms, end_time_ms; char*
I have the following struct: struct Records { int Number; char Name[20]; float Salary;
I have following structure typedef struct List_Node { struct File_Descriptor *data; char *key; struct
I have the following structure: struct hashItem { char userid[8]; char name[30]; struct hashItem
I have the following struct: struct foo { int a; char b; }; It
I have the following struct: typedef struct{ int vin; char* make; char* model; int
I have the following struct : struct NODE { char username[50]; char password[50]; char
VC++ 2010 Lets say I have the following: struct person { char * name;
I have following struct defination: typedef union U08_16_t { unsigned long s32;//message32 unsigned char
I have the following struct typedef char String[256]; typedef struct { String name; int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.