4 * Copyright (C) 2004-2011 S3D contributors
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <arpa/inet.h> /* htonl(),htons() */
28 /* convert buffer with floats from host to network endianess */
29 void htonfb(float *netfloat
, int num
)
32 for (i
= 0; i
< num
; i
++) {
33 *(uint32_t *) & netfloat
[i
] = htonl(*(uint32_t *) & netfloat
[i
]);
37 /* convert buffer with floats from network to host endianess */
38 void ntohfb(float *netfloat
, int num
)
41 for (i
= 0; i
< num
; i
++) {
42 *(uint32_t *) & netfloat
[i
] = ntohl(*(uint32_t *) & netfloat
[i
]);
46 /* convert buffer with uint32_ts from host to network endianess */
47 void htonlb(uint32_t * netint32
, int num
)
50 for (i
= 0; i
< num
; i
++) {
51 netint32
[i
] = htonl(netint32
[i
]);
55 /* convert buffer with uint32_ts from network to host endianess */
56 void ntohlb(uint32_t * netint32
, int num
)
59 for (i
= 0; i
< num
; i
++) {
60 netint32
[i
] = ntohl(netint32
[i
]);
64 /* convert buffer with uint16_ts from host to network endianess */
65 void htonsb(uint16_t * netint16
, int num
)
68 for (i
= 0; i
< num
; i
++) {
69 netint16
[i
] = htons(netint16
[i
]);
73 /* convert buffer with uint16_ts from network to host endianess */
74 void ntohsb(uint16_t * netint16
, int num
)
77 for (i
= 0; i
< num
; i
++) {
78 netint16
[i
] = ntohs(netint16
[i
]);