Date: Wed, 14 Sep 2011 12:04:09 -0500 From: Warner Losh <imp@bsdimp.com> To: Julian Elischer <julian@freebsd.org> Cc: freebsd-arch@freebsd.org, Marcel Moolenaar <marcel@xcllnt.net> Subject: Re: ntohq/htonq? Message-ID: <94A8CF2C-432D-43D6-8FB6-ADDAA013CA9D@bsdimp.com> In-Reply-To: <4E70DA7A.7020307@freebsd.org> References: <306FD881-6140-4DE2-AFF1-95C8079E4187@xcllnt.net> <201109140747.21979.jhb@freebsd.org> <B76A2235-C31A-46B6-BB99-EC9A661D83BD@bsdimp.com> <201109141230.51827.jhb@freebsd.org> <4E70DA7A.7020307@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sep 14, 2011, at 11:46 AM, Julian Elischer wrote: > On 9/14/11 9:30 AM, John Baldwin wrote: >> On Wednesday, September 14, 2011 10:39:31 am Warner Losh wrote: >>> On Sep 14, 2011, at 6:47 AM, John Baldwin wrote: >>>=20 >>>> On Tuesday, September 13, 2011 10:36:49 pm Marcel Moolenaar wrote: >>>>> All, >>>>>=20 >>>>> Is there a reason not to add ntohq and htonq to the short >>>>> and long versions we (and everyone else) already has? >>>>>=20 >>>>> Juniper has 64-bit entities that go over the wire in >>>>> network byte order and, while these macros are absolutely >>>>> arcane, I see no reason not to complete them with 64-bit >>>>> variants. >>>>>=20 >>>>> I did some googling and htonq and ntohq seem to be de >>>>> facto names used, but oddly enough no OS has them defined. >>>>> It's surreal. Are there better alternatives we should >>>>> migrate to? >>>> I don't have a better idea. I do wish the names encoded the size = instead like >>>> we do for the [lb]etoh*() and hto[lb]e*() macros (that is ntoh64(), = etc.). >>>> However, given that ntohl() and ntohs() are standardized we've = probably lost >>>> the opportunity to fix that misfeature of ntoh*() and hton*() and a = 'q' suffix >>>> is consistent (though hackish). >>>>=20 >>>> I guess the one other possiblity is to add *16 and *32 aliases for = 's' and 'l' >>>> and then add *64 for the new one if we think that using the names = is better >>>> for the future (e.g. ntoh128() when it comes (or will that be = ntoho() >>>> (octword?))). >>>>=20 >>> Looks like the hotel ate my reply... >>>=20 >>> hton64/ntoh64 is what Linux has in the kernel. htonll and ntohll is = what Solaris and AIX have. >>>=20 >>> So (1) I'd shy away from htonq since that's not as well established = as the other two in the OS (although googling suggests that many = programs use >> it). (2) I'd provide both htonll and hton64 with a note saying that = hton128 is the wave of the future. >>=20 >> Actually, come to think of it, we use *ll rather than *q variants = here at work >> as well. I'd vote for (2). >>=20 > it won't cost us to provide ntoh16, ntoh32, ntoh64 even if we do also = have ntohs, ntohl, ntohll AND ntohq. > just make it clear in the definitions which one we want people to use = in new code. >=20 > ntohs, and ntohl have alway annoyed me just like 'short' and 'long' = and 'long long' > these days I always try use "int32_t" stuff if it's going to be = exported anywhere.. and I think the same > should be true of the ntohXX stuff. I rather like this idea, but they definitely are non-standard. htons = grew up in an era that pre-dated intXX_t by a decade and there's been no = updated, standardized versions since. I'd make a subtle change to the = XX versions: have them operate/return on the uintXX_t variants. But I = think that's also a separate discussion. Warner=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?94A8CF2C-432D-43D6-8FB6-ADDAA013CA9D>