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

  • SEARCH
  • Home
  • 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 7864361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:45:52+00:00 2026-06-02T23:45:52+00:00

I have a TCP server developed on x86 architecture using C under Linux using

  • 0

I have a TCP server developed on x86 architecture using C under Linux using berkley socker API. The server runs fine without any problems. But now for some reasons I have to run the server on MIPS architecture which has a big-endian architecture.

The server and the clients communicate through a set of predefined protocol. I will give an example of how a server sends a simple message to the clients:

struct echo_req req;

  req.header.version = OFP_VERSION;
  req.header.type = OFPT_ECHO_REQUEST;
  req.header.length = htons (sizeof req);
  req.header.xid = htonl(y);
  req.data = htonl (456);

char data[sizeof (req)];
data[0] = req.header.version;
data[1] = req.header.type;
memcpy (data + 2, &req.header.length, 2);
memcpy (data + 4, &req.header.xid, 4);
memcpy (data + 8, &req.data, 4);

  if ((send (sock_fd, &data, sizeof (data), 0) == -1))
    {
      printf ("Error in sending echo request message\n");
      exit (-1);
    }
printf("Echo Request sent!\n");

As you can see I use htonl and htons for any type longer than a byte to convert it to network byte order. After making up a packet I serialize and pack the data in char array and finally send it over to the netowrk.

Now before I run my server on Big-endian architecture I wanted to clear out a few things. In my perception as I memcpy the data and pack it, if I send it over the network it shouldn’t cause any problems on the big-endian architecture as memcpy will perform a byte by byte copy of the data into the array and hence there shouldn’t be any problem with the byte ordering when running on Big-endian. Yet I wanted to get the opinion of you people out there which I persume know a lot more than I do as I am still a beginner in network programming :). Please guide me in this whether I am on the right track or not. All help much appreciated.

Thanks

  • 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-02T23:45:53+00:00Added an answer on June 2, 2026 at 11:45 pm

    Yes, memcpy just copies bytes in order from a source to a destination.

    Without seeing the rest of your code, it’s impossible to say that you’ve used hton(l|s) everywhere you should. It’s also possible that you’ve done something like copying a floating point number byte for byte, which doesn’t necessarily work, independent of endianness issues.

    I don’t see any obvious problems in the code you’ve posted above though.

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

Sidebar

Related Questions

I have developed a TCP server by async pattern under .net4 in c# that
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create
I have a server that connects to multiple clients using TCP/IP connections, using C
I have a java server which is using TCP and sockets to connect to
I have developed a small server that recives connections (using basically the example here:
I have TCP server , what recieve big data without a break. And I
I have a Java app, connecting through TCP socket to a server developed in
I have developed a TCP server according to your advises: High performance TCP server
I have developed a server to listen in a TCP port .. and i
I have developed (TCP) server to listen to a client and interact with it.

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.