Release s3d 0.2.2
[s3d.git] / server / endian.c
blob92803726a5f7b2bb9ea53dd3b4aa8bb82373d48f
1 /*
2 * endian.c
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() */
25 #include <stdint.h>
26 #include "global.h"
28 /* convert buffer with floats from host to network endianess */
29 void htonfb(float *netfloat, int num)
31 int i;
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)
40 int i;
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)
49 int i;
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)
58 int i;
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)
67 int i;
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)
76 int i;
77 for (i = 0; i < num; i++) {
78 netint16[i] = ntohs(netint16[i]);