Questions tagged [htonl]

htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian).

Shortcut for Host TO Network translation

The htonl function can be used to convert an IPv4 address in host byte order to the IPv4 address in network byte order.

Docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ms738556(v=vs.85).aspx

Answer: When and how to use C++ htonl function

42 questions
0
votes
4 answers

Converting dotted IP to integer using htonl(inet_addr(IP_str)) return negative values for IP Adresses of Class B and C

I am trying to convert dotted IP to integer using htonl(inet_addr(IP_str)). The problem is the function returns negative results for IP address of class B and C. here is some of my code (simplified): int main() { const char IP1[] = "10.0.0.0"; …
Rezaeimh7
  • 1,467
  • 2
  • 23
  • 40
0
votes
2 answers

Htons byte order conversion

Am new to socket programming and I came up to this Network Byte Conversion mechanisms the htons and the htonl methods. The documentations said that they convert either a 16-bit or a 32-bit network number from a host network byte order to an Internet…
shaddyshad
  • 217
  • 4
  • 15
0
votes
1 answer

Converting from void * to use htonl

I have a void * value in a structure and I need to send it through a socket to a server. I know I need to use int value = htonl(kv->value); but the compiler is throwing errors passing argument 1 of ‘htonl’ makes integer from pointer without a cast…
0
votes
2 answers

Does any uniform function exists instead of htons htonl

I am trying new the C++ socket programming. I am having some difficulty for understanding functionality of htons, htonl and related functions. I read some documents but still my questions are as follows, for a single server and and single client I…
sandy
  • 283
  • 1
  • 7
  • 27
0
votes
1 answer

Can Someone give an actual implementation of the pseudo code to convert Host byte order to network byte Order

The Stable Pseudo Code is this mentioned on the following link. I would like to implement it in c++. I am not able to understand and perform these signof and exponentof and mantissaof operations. how to convert double between host and network byte…
Hiesenberg
  • 415
  • 1
  • 8
  • 12
0
votes
1 answer

having trouble transfer arrays over socket

i am haveing trouble transferring int array over socket in c. what is the correct use of htonl()? lets say i have : int arra[3]={6000,7000,8000}; and socket called new_socket how do i transfer it correctly to the other end of socket? client is…
Ohad Gerrassy
  • 116
  • 11
0
votes
1 answer

Using ntohl and htonl problems on iPhone

I have an NSDATA object which I create and then send over the network. I have having trouble getting the correct values out of the received NSDATA stream. Here is some quick code to reproduce my problem. No network transmission required. …
Johnne
  • 143
  • 10
0
votes
0 answers

converting uint32_t htonl to char[4] using memcpy does not give output

My question is kind of similar to the one in this link use htonl convert a int number, and memcpy to a char*, but nothing , and there are some other similar questions, but the reason Im asking a new one is because I have not been able to find a…
Dhruv
  • 38
  • 8
0
votes
2 answers

Windows sockets htons(80) vs 0x5000

When I am writing port to SOCKADDR_IN structure, can I use 0x5000 instead of htons(80)? (Why 0x5000? -- I debugged htons(80) and it returned 0x5000)
RIscRIpt
  • 163
  • 3
  • 12
0
votes
4 answers

How to send c++ doubles from one system to another Sender: Winsock Receiver: Java

The sending C-side double tmp = htonl(anydouble); send(socket, (char *) &tmp, sizeof(tmp), 0); On the Java side, im reading the network data into a char[8] What is the proper way of performing the conversion back to double? Is it the way to go to…
Simbi
  • 992
  • 3
  • 13
  • 29
0
votes
1 answer

Behavior of ntohl and htonl different between Python and C

I'm trying to imitate the behavior of some parts of a C program in Python. They are both reading a binary file where each record is length->data. The C program will pull the length byte from the file, and regardless of whether it's positive or…
Dave
  • 1,420
  • 3
  • 17
  • 25
-1
votes
2 answers

Python socket: cannot receive int array

I try to make a inter process communication between a Python and c program via winsockets. Sending a string does work, but now I try to send an int array from the c socket to the python socket. I already found out that I have to use htonl() to…
Gora
  • 61
  • 12
1 2
3