Mercurial > pidgin
annotate plugins/icq/icqbyteorder.h @ 1367:ad346597b7b2
[gaim-migrate @ 1377]
fesnel's one line patch :)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 03 Jan 2001 04:19:07 +0000 |
parents | 0a766047b4fd |
children | b167222b5c93 |
rev | line source |
---|---|
1152 | 1 /* |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
2 * $Id: icqbyteorder.h 1319 2000-12-19 10:08:29Z warmenhoven $ |
1152 | 3 * |
4 * This header defines macros to handle ICQ protocol byte order conversion. | |
5 * | |
6 * Vadim Zaliva <lord@crocodile.org> | |
7 * http://www.crocodile.org/ | |
8 * | |
9 * Copyright (C) 1999 Vadim Zaliva | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 */ | |
26 | |
27 /* | |
28 * From ICQ protocol description: | |
29 * "Integers consisting of more than one byte is stored | |
30 * with the least significant byte first, and the most significant byte last | |
31 * (as is usual on the PC/Intel architecture)". | |
32 * | |
33 * whereas the network byte order, as used on the | |
34 * Internet, is Most Significant Byte first. (aka. Big Endian) | |
35 */ | |
36 | |
37 #ifndef ICQ_BYTEORDER_H_FLAG | |
38 #define ICQ_BYTEORDER_H_FLAG | |
39 | |
40 #ifdef HAVE_CONFIG_H | |
41 #include <config.h> | |
42 #endif | |
43 | |
44 /* linux way */ | |
45 #ifdef HAVE_ENDIAN_H | |
46 # include <endian.h> | |
47 #endif | |
48 #ifdef HAVE_BYTESWAP_H | |
49 # include <byteswap.h> | |
50 #endif | |
51 | |
52 /* bsd way */ | |
53 #ifdef HAVE_MACHINE_ENDIAN_H | |
54 # include <machine/endian.h> | |
55 #endif | |
56 | |
57 /* | |
58 * Kind of portable way. this common header, at least I found it on BSD and Solaris. | |
59 * On Solaris this is only place where endiannes is defined. | |
60 */ | |
61 #ifdef HAVE_ARPA_NAMESER_COMPAT_H | |
62 # include <arpa/nameser_compat.h> | |
63 #endif | |
64 | |
65 /* | |
66 * I am really trying to use builtin optimized byte swap routines. | |
67 * they are highly optimised on some platforms. | |
68 * But as last resort this simple code is used. | |
69 */ | |
70 #ifndef HAVE_BYTESWAP_H | |
71 # ifndef bswap_32 | |
72 extern unsigned long bswap_32(unsigned long v); | |
73 # endif | |
74 # ifndef bswap_16 | |
75 extern unsigned short bswap_16(unsigned short v); | |
76 # endif | |
77 #endif | |
78 | |
79 #ifdef BYTE_ORDER_LITTLE_ENDIAN | |
80 # define htoicql(x) (x) | |
81 # define icqtohl(x) (x) | |
82 # define htoicqs(x) (x) | |
83 # define icqtohs(x) (x) | |
84 #else | |
85 | |
86 #ifndef BYTE_ORDER | |
87 # error "Unknown byte order!" | |
88 #endif | |
89 | |
90 #if BYTE_ORDER == BIG_ENDIAN | |
91 /* host is different from ICQ byte order */ | |
92 # define htoicql(x) bswap_32(x) | |
93 # define icqtohl(x) bswap_32(x) | |
94 # define htoicqs(x) bswap_16(x) | |
95 # define icqtohs(x) bswap_16(x) | |
96 #else | |
97 # if BYTE_ORDER == LITTLE_ENDIAN | |
98 /* host byte order match ICQ byte order */ | |
99 # define htoicql(x) (x) | |
100 # define icqtohl(x) (x) | |
101 # define htoicqs(x) (x) | |
102 # define icqtohs(x) (x) | |
103 # else | |
104 # error "Unsupported byte order!" | |
105 # endif | |
106 #endif | |
107 | |
108 #endif | |
109 | |
110 /* ICQ byte order is always different from network byte order. */ | |
111 # define ntoicql(x) bswap_32(x) | |
112 # define icqtonl(x) bswap_32(x) | |
113 # define ntoicqs(x) bswap_16(x) | |
114 # define icqtons(x) bswap_16(x) | |
115 | |
116 #endif |