Subject: Re: lib/1610:
To: None <andrew@wipux2.wifo.uni-mannheim.de>
From: Chris G Demetriou <Chris_G_Demetriou@BALVENIE.PDL.CS.CMU.EDU>
List: netbsd-bugs
Date: 10/17/1995 19:29:07
> >Description:
> 	I was writing a program to scan ports when it started
> 	outputing something different than I expected:
> 	i.e. something goes wrong when you go above 1023.
> >How-To-Repeat:
> 
> void main(void)
> {
> 	printf("This number %d is different from this number %d\n",
> 			ntohs(htons(1020) + htons(4)),1024);
> 	printf("This number %d is the same as this number %d\n",
> 			ntohs(htons(1020) + htons(3)),1023);
> 	printf("This number %d is the same as this number %d\n",
> 			ntohs(htons(1030) + htons(3)),1033);
> }


Think about it for a minute.

	1020 =	0x3fc		htons(1020) =	0xfc03
      +	   4 =	0x004	      +	htons(4) =	0x0400
	----    -----				------
        1024 =  0x400			       0x10003 which is
							truncated to 0x3

If you change the byte order, how can 'normal' carry possibly work as
as it normally does?



cgd