Mercurial > pidgin.yaz
annotate plugins/icq/icqbyteorder.h @ 1432:4c510ca3563f
[gaim-migrate @ 1442]
icqlib 1.1.5
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 28 Jan 2001 01:52:27 +0000 |
parents | b167222b5c93 |
children | 7f7857c5036e |
rev | line source |
---|---|
1152 | 1 /* |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
2 * $Id: icqbyteorder.h 1442 2001-01-28 01:52:27Z 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 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
57 /* hpux way */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
58 #ifdef hpux |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
59 #include <arpa/nameser.h> |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
60 #endif |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1375
diff
changeset
|
61 |
1152 | 62 /* |
63 * Kind of portable way. this common header, at least I found it on BSD and Solaris. | |
64 * On Solaris this is only place where endiannes is defined. | |
65 */ | |
66 #ifdef HAVE_ARPA_NAMESER_COMPAT_H | |
67 # include <arpa/nameser_compat.h> | |
68 #endif | |
69 | |
70 /* | |
71 * I am really trying to use builtin optimized byte swap routines. | |
72 * they are highly optimised on some platforms. | |
73 * But as last resort this simple code is used. | |
74 */ | |
75 #ifndef HAVE_BYTESWAP_H | |
76 # ifndef bswap_32 | |
77 extern unsigned long bswap_32(unsigned long v); | |
78 # endif | |
79 # ifndef bswap_16 | |
80 extern unsigned short bswap_16(unsigned short v); | |
81 # endif | |
82 #endif | |
83 | |
84 #ifdef BYTE_ORDER_LITTLE_ENDIAN | |
85 # define htoicql(x) (x) | |
86 # define icqtohl(x) (x) | |
87 # define htoicqs(x) (x) | |
88 # define icqtohs(x) (x) | |
89 #else | |
90 | |
91 #ifndef BYTE_ORDER | |
92 # error "Unknown byte order!" | |
93 #endif | |
94 | |
95 #if BYTE_ORDER == BIG_ENDIAN | |
96 /* host is different from ICQ byte order */ | |
97 # define htoicql(x) bswap_32(x) | |
98 # define icqtohl(x) bswap_32(x) | |
99 # define htoicqs(x) bswap_16(x) | |
100 # define icqtohs(x) bswap_16(x) | |
101 #else | |
102 # if BYTE_ORDER == LITTLE_ENDIAN | |
103 /* host byte order match ICQ byte order */ | |
104 # define htoicql(x) (x) | |
105 # define icqtohl(x) (x) | |
106 # define htoicqs(x) (x) | |
107 # define icqtohs(x) (x) | |
108 # else | |
109 # error "Unsupported byte order!" | |
110 # endif | |
111 #endif | |
112 | |
113 #endif | |
114 | |
115 /* ICQ byte order is always different from network byte order. */ | |
116 # define ntoicql(x) bswap_32(x) | |
117 # define icqtonl(x) bswap_32(x) | |
118 # define ntoicqs(x) bswap_16(x) | |
119 # define icqtons(x) bswap_16(x) | |
120 | |
121 #endif |