Fix byte order when retrieve address from filedescriptor
Motivation: When create address from filedescriptor we may use incorrect byte order and so end up with an incorrect InetAddress. Modification: Not manually shift bytes Result: Correct address in all cases.
This commit is contained in:
parent
269695d043
commit
6293b0579c
@ -197,17 +197,13 @@ static inline void initInetSocketAddressArray(JNIEnv* env, struct sockaddr_stora
|
|||||||
port = ntohs(s->sin_port);
|
port = ntohs(s->sin_port);
|
||||||
|
|
||||||
// Encode address and port into the array
|
// Encode address and port into the array
|
||||||
unsigned char a[8];
|
unsigned char a[4];
|
||||||
a[0] = s->sin_addr.s_addr >> 24;
|
a[0] = port >> 24;
|
||||||
a[1] = s->sin_addr.s_addr >> 16;
|
a[1] = port >> 16;
|
||||||
a[2] = s->sin_addr.s_addr >> 8;
|
a[2] = port >> 8;
|
||||||
a[3] = s->sin_addr.s_addr;
|
a[3] = port;
|
||||||
a[4] = port >> 24;
|
(*env)->SetByteArrayRegion(env, bArray, offset, 4, (jbyte*) &s->sin_addr.s_addr);
|
||||||
a[5] = port >> 16;
|
(*env)->SetByteArrayRegion(env, bArray, offset + 4, 4, (jbyte*) &a);
|
||||||
a[6] = port >> 8;
|
|
||||||
a[7] = port;
|
|
||||||
|
|
||||||
(*env)->SetByteArrayRegion(env, bArray, offset, 8, (jbyte*) &a);
|
|
||||||
} else {
|
} else {
|
||||||
struct sockaddr_in6* s = (struct sockaddr_in6*) &addr;
|
struct sockaddr_in6* s = (struct sockaddr_in6*) &addr;
|
||||||
port = ntohs(s->sin6_port);
|
port = ntohs(s->sin6_port);
|
||||||
|
Loading…
Reference in New Issue
Block a user