[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Unix byte order

Posted on 1998-11-04
4
Medium Priority
?
188 Views
Last Modified: 2013-11-13
I am writing a small TCP/IP client using the Winsock control.  The client is designed to connect to a particular server which expects a special sequence of bytes during an initial handshake.  I need to send four bytes in "Unix byte order".(In particular, I need to send a four byte sequence containing the number of characters in the string that I am about to send (which is 8)).

The server documentation mentions a C/C++ macro called "htonl" that can be used in those languages.  I'm looking to accomplish the same thing in Visual Basic.

I have a rudimentary understanding of the concepts, but I have no idea how to go about implementing them.

Thank you in advance.
0
Comment
Question by:krouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 800 total points
ID: 1443165
Some systems store data "big endian" where the MS Byte of data is the lower addressed byte. Intel stores data "little endian" where the LS byte of data is the lower addressed byte. This leads to no end of confusion. When you do a bytewise memory dump the addresses normally increase reading left to right. The data values are LS/MS order and you're forever having to swap halves. When you send to the UNIX system you'll have to take this byte ordering problem into account. Normally you'll send the four bytes in MSB/2MS/2LS/LSB order. These will be stored LSB/2LS/2MS/MSB order on an intel box.

M

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1443166
As a learning experience go to the DOS prompt and do the following (ignore the parenthetical comments):

C:\> DEBUG                   (Start DEBUG from DOS prompt)
-f 0,ffff 0                           (fill memory with 0's)
-a 100                             (Assemble at 100H)
xxxx:0100 dw 1234 5678  (Define two words, '1234' and '5678')
xxxx:0104                       (enter on a line by itself to stop assembling)
-d 100                             (Display memory at 100H)
xxxx:0100  34 12 78 56 00 00 00 00-00 00 00 00 00 00 00 00   4.xV............
.

(Note the order that the data was saved in: 34 12 78 56, the MS of each word is at the lower memory address.)

-q                                   (exit debug back to DOS)

M


0
 

Author Comment

by:krouk
ID: 1443167
Thank you for your comments.  They are very helpful.  You will definitely get an "A" for this.  But, I would like to confirm my understanding by giving an example of how I might implement a conversion from intel to unix byte order.

Based on what you said, would I be able to do something like this?

Dim thebytearray () as byte
Dim items as integer
Dim first as byte
Dim second as byte

Thebytearray = "8"

For items = 0 to Ubound (thebytearray) step 2
  first = thebytearray (items)
  second = thebytearray (items + 1)
  thebytearray (items) = second
  thebytearray (items + 1) = first
Next

Thanks again for your time.  Please note that I will be out for the next couple of days, so I may not have a chance to award your points until next week (so there is no rush on your reply).
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1443168
Your example (after a cursory reading) looks ok, but you might want to simplify it:
Dim bytearray(8) as byte
call sendabyte( bytearray( 2 ) )
call sendabyte( bytearray( 1 ) )
call sendabyte( bytearray( 4 ) )
call sendabyte( bytearray( 3 ) )
call sendabyte( bytearray( 6 ) )
call sendabyte( bytearray( 5 ) )
call sendabyte( bytearray( 8 ) )
call sendabyte( bytearray( 7 ) )

This is (perhaps) a little clearer if not as efficient.

M
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question