Is player can use negative port?

Forum concernant ce jeu et les serveurs que j'héberge. (ce sous-forum remplace conseiljedi.com)
Post Reply
User avatar
Unknown Jedi
Posts: 5
Joined: Sun Jul 26, 2009 8:13 pm

Is player can use negative port?

Post by Unknown Jedi »

I'm always thinking that a port number is a 16-bit unsigned integer, thus ranging from 0 to 65535. But when I'm analyse player's full userinfo, I've founded some players with negative port, like \ip\77.252.227.44:-9144\. How it's possible?
Gamall
Hic sunt dracones
Posts: 4174
Joined: Fri May 26, 2006 11:09 pm
Contact:

Re: Is player can use negative port?

Post by Gamall »

Port numbers are 16 bits integers, yes. Unsigned, yes in theory.

But from the computer's perspective it does not really matter whether an N-bits integer is signed or unsigned, until the value is read; what matters is the binary representation of it, and the same representation may encode two different numbers depending on the value of the Most Significant Bit. That's known as the Two's complement.

Here, the same 16 bits binary blob, let's call it B is read twice: once by the networking apparatus of the client and the server, which read it as unsigned: unsigned(B) = 32768 + signed(B) = 32768 - 9144 = 23624; and a second time by the application which wrote the player's userinfo; and this one read it as signed, probably because the programmer felt too lazy to type the "unsigned" keyword.

It does not really matter because if you read this signed number and stored it in a 16bits int, signed or unsigned, you'd get the same binary representation anyway. And this applies even if you are out of signed bounds. Signed range for 16bits is −32768 to 32767 (total 65536 distinct values, of course); but if you read a bigger unsigned value, 32768 for instance, it will just wrap around and become −32768, which has the same binary representation.

Hope that served to clear things for you, and not muddle them further :)
Last edited by Gamall on Sun Aug 23, 2009 8:05 pm, edited 2 times in total.
Reason: typo
{<§ Gamall Wednesday Ida §>}
{ Mods and Programs - Mods TES-IV Oblivion }
User avatar
Unknown Jedi
Posts: 5
Joined: Sun Jul 26, 2009 8:13 pm

Re: Is player can use negative port?

Post by Unknown Jedi »

Thanks. I'm think about signed value, but I've think that unsigned(B) = signed(B)-32768, and this mistake confused me.
My server auto-banned two players, because they used negative port - I've thinking that negative port can be used only by fakes Image
Post Reply

Who is online

Users browsing this forum: No registered users and 183 guests