as this is fixed .... might not be needed if taken care of in unpacker
127{
128#define MAX_PXD_FRAMES 256
129 const int headerlen = 8;
130 int* pxdheader = (int*) data;
131 int* pxdheadertable = (int*) &data[headerlen];
132 int framenr = 0, tablelen = 0, datalen = 0;
133 int br = read_data(sock, data, headerlen);
134 if (br <= 0) return br;
135 if (static_cast<uint>(pxdheader[0]) != htonl(0xCAFEBABE)) {
136 printf("pxdheader wrong : Magic %X , Frames %X \n", pxdheader[0], ntohl(pxdheader[1]));
137 exit(0);
138 }
139 pxdheader[0] = ntohl(pxdheader[0]);
140 framenr = pxdheader[1] = ntohl(pxdheader[1]);
141 if (framenr > MAX_PXD_FRAMES) {
142 printf("MAX_PXD_FRAMES too small : %d(%d) \n", framenr, MAX_PXD_FRAMES);
143 exit(0);
144 }
145 tablelen = 4 * framenr;
146 br = read_data(sock, (char*)&data[headerlen], tablelen);
147 if (br <= 0) return br;
148 for (int i = 0; i < framenr; i++) {
149 pxdheadertable[i] = ntohl(pxdheadertable[i]);
150 datalen += (pxdheadertable[i] + 3) & 0xFFFFFFFC;
151 }
152
153 if (datalen + headerlen + tablelen > len) {
154 printf("buffer too small : %d %d %d(%d) \n", headerlen, tablelen, datalen, len);
155 exit(0);
156 }
157 int bcount = read_data(sock, data + headerlen + tablelen, datalen);
158 return (headerlen + tablelen + bcount);
159}