Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting IPV4 Address from bytes to String

I currently am trying to create a chat server as an assignment and want each message to contain a header. It will contain ipv4 address followed by a letter then a username

I can easily decode string letters from bytes but now I am struggling to decode an ipv4 address from bytes

the representation so far from the bytes is this

[-64, -88, 1, 5]

which in the ipv4 dotted quad format would be 192.168.1.5

I just need a way to try and decode the four bytes of integers to a string or something along those lines

THANKS :D

like image 671
Brandon Thomas Avatar asked Sep 15 '13 00:09

Brandon Thomas


People also ask

How do you convert bytes to strings?

One method is to create a string variable and then append the byte value to the string variable with the help of + operator. This will directly convert the byte value to a string and add it in the string variable. The simplest way to do so is using valueOf() method of String class in java.

How do you convert numbers to bytes?

Use int.Call int. to_bytes(length, byteorder) on an int with desired length of the array as length and the order of the array as byteorder to convert the int to bytes. If byteorder is set to "big" , the order of most significant bytes starts at the beginning of the array.


1 Answers

InetAddress.getByAddress(bytes).getHostAddress()?

like image 199
chrylis -cautiouslyoptimistic- Avatar answered Sep 28 '22 10:09

chrylis -cautiouslyoptimistic-