S
S
sddvxd2019-05-14 13:10:07
C++ / C#
sddvxd, 2019-05-14 13:10:07

Why does send allow little-endian data to be sent?

Good afternoon!
I'm trying to figure out why, if it is indicated that the network works only in network byte order (big-endian), and I have little-endian encoding on my computer, then why does this kind of code work successfully?

const char* request = "GET / HTTP/1.1\r\n\Host: site.ru\r\n\r\n";
//... creating socket and connection ...
send(socket, request, lenData, 0);
recv(socket, buffer, 1024*10, 0); //code 200 [OK]


Why does this work well? Because when I try to get data from the server in the same way using nasma, the server does not understand me:

msgRequest db "GET / HTTP/1.1\r\n\Host: site.ru\r\n\r\n"
lenMsgRequest $-msgRequest
; ... creating socket and connection ...
    push 0
  push lenMsgRequest
  push msgRequest
  push dword [socket]
  call [email protected]
  cmp eax, -1
  je error
  
  push 0
  push 8128
  push buffer
  push dword [socket]
  call [email protected] //code 400 [Bad Request]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2019-05-14
@z3apa3a

The concept of big endian and little endian is for fixed-length multibyte types (usually integer) in the address space. There is no data addressing in the network, therefore there is no concept of big endian and little endian, there is the concept of big endian and reverse network byte order.
The send/recv functions do not operate on multibyte integers, but on an arbitrary-length memory buffer and know nothing about what kind of data is in these buffers and about the representation of the integer data stored in them, if any. Therefore, data over the network will be sent in the order in which they are in the address space in the send buffer.
However, in the code fragment you saw, there is no transmission of integer data over the network, so your question is basically not correct. Your problems are most likely that you are sending extra data after the text string, because incorrectly calculate the number of characters in it, or incorrectly put an integer variable on the stack, without taking into account its size (for example, there should be a 64-bit number, but you put only 32 bits).
PS but in general you have an extra backslash before H in the text constant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question