1 /*
2 * network_data_formats.h
3
4 Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
5 and the "Aleph One" developers.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 This license is contained in the file "COPYING",
18 which is included with this source code; it is available online at
19 http://www.gnu.org/licenses/gpl.html
20
21 * The purpose of this file is to define structures that will be used with exactly the same
22 * padding, byte ordering, etc. on all platforms, and to declare handy functions to copy data
23 * to or from the corresponding "unpacked" structures already used by the code. This approach
24 * requires only minimal changes to the original code.
25 *
26 * Created by Woody Zenfell, III on Thu Oct 11 2001; structures copied from network_private.h.
27
28 Jan 16, 2002 (Loren Petrich) Replaced compiler-specific packing code with generalized wrappers
29
30 Mar 5, 2002 (Woody Zenfell) added network_audio_header
31
32 Mar 9, 2002 (Woody Zenfell) changed some SIZEOF_'s to be more accurate/specific
33 */
34
35 #ifndef NETWORK_DATA_FORMATS_H
36 #define NETWORK_DATA_FORMATS_H
37
38 #include "cseries.h" // Need ALEPHONE_LITTLE_ENDIAN, if appropriate.
39 #include "network.h"
40 #include "network_private.h"
41 #include "network_audio_shared.h"
42
43
44
45 // Note: no further interpretation/manipulation of a packet is attempted here. That's up
46 // to whomever actually deals with receiving and interpreting the packet (though they will
47 // probably make use of the netcpy's for the next couple structures below).
48
49 const int SIZEOF_NetPacketHeader = 6;
50
51 struct NetPacketHeader_NET
52 {
53 uint8 data[SIZEOF_NetPacketHeader];
54 };
55
56 extern void netcpy(NetPacketHeader_NET* dest, const NetPacketHeader* src);
57 extern void netcpy(NetPacketHeader* dest, const NetPacketHeader_NET* src);
58
59
60
61 // Note: we do not attempt any manipulations on the actual action_flags, as we do not claim
62 // to compute the number that would be there. (I suppose, knowing that the only stuff in the
63 // buffer will be action flags, that we could just walk through and swap all of it, but...)
64 // We'll leave it to whomever interprets or writes to the action_flags data segment to do the
65 // necessary manipulations.
66
67 const int SIZEOF_NetPacket = 2*MAXIMUM_NUMBER_OF_NETWORK_PLAYERS + 8;
68
69 struct NetPacket_NET
70 {
71 uint8 data[SIZEOF_NetPacket];
72 };
73
74 extern void netcpy(NetPacket_NET* dest, const NetPacket* src);
75 extern void netcpy(NetPacket* dest, const NetPacket_NET* src);
76
77
78 // For action flags - note length is in bytes, not number of flags. This is 'bidirectional',
79 // i.e. same function is used to copy from _NET to unpacked as the other way around.
80 // Note, since there is no packing to do - only byte swapping - we can pass along to memcpy if we're
81 // on a big-endian architecture.
82 #ifdef ALEPHONE_LITTLE_ENDIAN
83 extern void netcpy(uint32* dest, const uint32* src, size_t length);
84 #else
netcpy(uint32 * dest,const uint32 * src,size_t length)85 __inline__ void netcpy(uint32* dest, const uint32* src, size_t length) { memcpy(dest, src, length); }
86 #endif
87
88
89
90 // Note: we do not attempt any sort of processing on the "data" segment here,
91 // since we may not understand its format. Whoever interprets it will have to
92 // do the necessary packing/unpacking, byte-swapping, etc.
93
94 const int SIZEOF_NetDistributionPacket = 6;
95
96 struct NetDistributionPacket_NET
97 {
98 uint8 data[SIZEOF_NetDistributionPacket];
99 };
100
101 extern void netcpy(NetDistributionPacket_NET* dest, const NetDistributionPacket* src);
102 extern void netcpy(NetDistributionPacket* dest, const NetDistributionPacket_NET* src);
103
104
105 // Note: unlike other _NET structures, neither 'host' nor 'port' here is byte-swapped
106 // in conversion to/from the non-_NET structures.
107 // It is believed that both should ALWAYS be dealt with in network byte order.
108
109 const int SIZEOF_IPaddress = 6;
110
111 struct IPaddress_NET {
112 uint8 data[SIZEOF_IPaddress];
113 };
114
115 extern void netcpy(IPaddress_NET* dest, const IPaddress* src);
116 extern void netcpy(IPaddress* dest, const IPaddress_NET* src);
117
118 const int SIZEOF_network_audio_header = 8;
119
120 struct network_audio_header_NET {
121 uint8 data[SIZEOF_network_audio_header];
122 };
123
124 extern void netcpy(network_audio_header_NET* dest, const network_audio_header* src);
125 extern void netcpy(network_audio_header* dest, const network_audio_header_NET* src);
126
127 #endif//NETWORK_DATA_FORMATS_H
128