Loggytronic Forum

VOMP => VOMP General / MVP => Topic started by: wauwau on December 28, 2009, 15:09:26

Title: Vomp on ARM/Marvell
Post by: wauwau on December 28, 2009, 15:09:26
Hi,

my Debian/Squeeze installation with VDR 1.6.0 (standard ARM repostiory) is working stable.
I downloaded the latest version (0.3.1) as source code and compiled it succesfully. The vompserver
does start up but the MVP has some difficulties in getting the channel list.

As a similar configuration on x86 is working without troubles, I assume it is a special issue with
the vompserver running on ARM.

Here is the output of /tmp/vompserver.log

16:00:05.025348 [debug]  Client - Waiting
16:00:05.025721 [debug]  RRProc - thread woken with req, queue size: 1
16:00:05.025837 [debug]  RRProc - Config save: General Last Power State On
16:00:05.026157 [debug]  Config - Config error: Could not write temp config file
16:00:05.026355 [debug]  RRProc - threadMethod waiting
16:00:10.261837 [debug]  Client - Received chan=1, ser=99, op=5, edl=0
16:00:10.262127 [debug]  RRProc - recvReq set req and signalled
16:00:10.262242 [debug]  Client - Waiting
16:00:10.262368 [debug]  RRProc - thread woken with req, queue size: 1
16:00:10.262795 [debug]  Config - Config error: Key Channels not found
16:00:10.262915 [debug]  RRProc - name: 'Das Erste'
16:00:10.263014 [debug]  RRProc - name: 'ZDF'
16:00:10.263109 [debug]  RRProc - name: 'Bayerisches FS Süd'
16:00:10.263201 [debug]  RRProc - name: 'ORF Sport Plus'
16:00:10.263291 [debug]  RRProc - name: 'arte'
16:00:10.263381 [debug]  RRProc - name: 'Phoenix'
16:00:10.263472 [debug]  RRProc - name: 'EinsPlus'
16:00:10.263561 [debug]  RRProc - name: 'arte'
16:00:10.263651 [debug]  RRProc - name: 'SWR Fernsehen'
16:00:10.263741 [debug]  RRProc - name: 'BR-alpha'
16:00:10.263831 [debug]  RRProc - name: 'Phoenix'
16:00:10.263922 [debug]  RRProc - name: '3sat'
16:00:10.264012 [debug]  RRProc - name: 'neo/KiKa'
16:00:10.264102 [debug]  RRProc - name: 'ZDF'
16:00:10.264191 [debug]  RRProc - name: 'ORF1'
16:00:10.264280 [debug]  RRProc - name: 'service_id 10121'
16:00:10.264371 [debug]  RRProc - name: 'service_id 11302'
16:00:10.264461 [debug]  RRProc - name: 'service_id 11303'
16:00:10.264550 [debug]  RRProc - name: 'service_id 11304'
16:00:10.264641 [debug]  RRProc - name: 'ORF2S'
16:00:10.264731 [debug]  RRProc - name: 'ATV'
16:00:10.264821 [debug]  RRProc - name: 'ORF2 O'
16:00:10.264910 [debug]  RRProc - name: 'BBC World'
16:00:10.265001 [debug]  RRProc - name: 'FAB'
16:00:10.265091 [debug]  RRProc - name: 'WDR'
16:00:10.265181 [debug]  RRProc - name: 'Südwest BW/RP'
16:00:10.265271 [debug]  RRProc - name: 'MDR Fernsehen'
16:00:10.265362 [debug]  RRProc - name: 'RTL'
16:00:10.265453 [debug]  RRProc - name: 'RTL2'
16:00:10.265560 [debug]  RRProc - name: 'Super RTL'
16:00:10.265652 [debug]  RRProc - name: 'VOX'
16:00:10.265741 [debug]  RRProc - name: 'RBB Brandenburg'
16:00:10.265962 [debug]  RRProc - name: 'RBB Berlin'
16:00:10.266068 [debug]  RRProc - name: 'Phoenix'
16:00:10.266162 [debug]  RRProc - name: 'Das Erste'
16:00:10.266254 [debug]  RRProc - name: 'Info/3sat'
16:00:10.266346 [debug]  RRProc - name: 'Doku/KiKa'
16:00:10.266436 [debug]  RRProc - name: 'Kabel 1'
16:00:10.266526 [debug]  RRProc - name: 'N24'
16:00:10.266615 [debug]  RRProc - name: 'ProSieben'
16:00:10.266704 [debug]  RRProc - name: 'SAT.1'
16:00:10.266793 [debug]  RRProc - name: 'Testkanal 9live'
16:00:10.266883 [debug]  RRProc - name: 'Eurosport'
16:00:10.266972 [debug]  RRProc - name: 'DSF'
16:00:10.267061 [debug]  RRProc - name: 'VIVA Plus'
16:00:10.267150 [debug]  RRProc - name: 'Testkanal Pro7'
16:00:10.267239 [debug]  RRProc - name: 'EinsPlus'
16:00:10.267328 [debug]  RRProc - name: '3sat'
16:00:10.267418 [debug]  RRProc - name: 'neo/KiKa'
16:00:10.267507 [debug]  RRProc - name: 'ZDFinfokanal'
16:00:10.267596 [debug]  RRProc - name: 'BR-alpha'
16:00:10.267686 [debug]  RRProc - name: 'SWR Fernsehen'
16:00:10.267775 [debug]  RRProc - name: 'Das Erste'
16:00:10.267865 [debug]  RRProc - name: 'Phoenix'
16:00:10.267954 [debug]  RRProc - name: 'EinsPlus'
16:00:10.268043 [debug]  RRProc - name: 'Das Erste'
16:00:10.268199 [debug]  RRProc - name: 'PULS 4'
16:00:10.268291 [debug]  RRProc - name: '3SAT'
16:00:10.268381 [debug]  RRProc - name: 'ServusTV'
16:00:10.268484 [debug]  RRProc - name: 'Bayerisches FS Nord'
16:00:10.268578 [debug]  RRProc - name: 'BR-alpha'
16:00:10.268669 [debug]  RRProc - name: 'hr-fernsehen'
16:00:10.268759 [debug]  RRProc - name: 'MDR Thüringen'
16:00:10.268994 [debug]  RRProc - Written channels list
16:00:10.269117 [debug]  RRProc - threadMethod waiting
16:00:14.267341 [debug]  Client - Received chan=3 kats=1262012411
16:00:14.267749 [debug]  Client - Waiting
16:00:20.267196 [debug]  Client - Received chan=3 kats=1262012417
16:00:20.267604 [debug]  Client - Waiting
16:00:26.267065 [debug]  Client - Received chan=3 kats=1262012423
16:00:26.267475 [debug]  Client - Waiting
16:00:29.739291 [debug]  Client - Received chan=1, ser=100, op=11, edl=29
16:00:29.739565 [debug]  RRProc - recvReq set req and signalled
16:00:29.739676 [debug]  Client - Waiting
16:00:29.739798 [debug]  RRProc - thread woken with req, queue size: 1
16:00:29.739937 [debug]  RRProc - Config save: General Last Power State Off
16:00:29.740403 [debug]  Config - Config error: Could not write temp config file
16:00:29.740687 [debug]  RRProc - threadMethod waiting
16:00:29.742160 [debug]  TCP - TCP has closed socket
16:00:29.742286 [debug]  Client - Disconnection detected
16:00:29.742455 [debug]  Client - Vomp client destructor
16:00:29.742640 [info]   RRProc - threadMethod err 2 or quit


The channel-list seems to be transmitted correctly, However on the MVP client only

"Das Erst" (without e!) is listed as first channels and then a lot of others (the second channel "ZDF") are omitted completly.

Any idea?

Best regards,
Michael
Title: Re: Vomp on ARM/Marvell
Post by: MartenR on December 28, 2009, 15:28:21
I would assume that the length information of the strings is not transmitted correctly. May be the same thing that was reported before with the numbers:
http://forum.loggytronic.com/index.php?topic=426.0

Btw, why is everyone trying these days to let vdr and vompserver run on an arm platform, what is the new fancy device that triggers these requests?

Marten
Title: Re: Vomp on ARM/Marvell
Post by: wauwau on December 28, 2009, 18:14:05
Ok, I'll try to firgure out whether there is a problem with the lenght.

The Marvell 6281 (Sheeva Platform) seems to be a valuable platform for SoHo video recorder - so why not.

Title: Re: Vomp on ARM/Marvell
Post by: AndersF on December 28, 2009, 20:45:48
Hi,

I'm running on the same Marvell SoC, like the sheevaplug, except that I have some extra hardware like eSATA, VGA port, etc.
My previous i86 server broke so I had to find another one. I'm tired of noisy 150 Watt monsters so I bought this Marvell based one instead.
6 Watt + 12 for the Disk, no problem running  24x7.

Oh, and yes, you need to apply the patches that I posted on the thread referred to in a previous post in this thread.

Regards
Anders
Title: Re: Vomp on ARM/Marvell
Post by: wauwau on December 29, 2009, 12:06:36
Hi,

thank you very much for your batch which solved obviously my troubles.

Keep you up to date whether other difficulties occur - my parents are for sure the most ciritcal testers ;-)

btw, which device have you bouht, the Marvell 1.2 GHz OpenRD board for 149 US$?

Thanks
Title: Re: Vomp on ARM/Marvell
Post by: Harry on December 30, 2009, 07:24:27
Quote from: AndersF on December 28, 2009, 20:45:48
Hi,

I'm running on the same Marvell SoC, like the sheevaplug, except that I have some extra hardware like eSATA, VGA port, etc.
My previous i86 server broke so I had to find another one. I'm tired of noisy 150 Watt monsters so I bought this Marvell based one instead.
6 Watt + 12 for the Disk, no problem running  24x7.

Oh, and yes, you need to apply the patches that I posted on the thread referred to in a previous post in this thread.

Regards
Anders

hi Anders,

this sounds promising.
i wonder though, what kind (and how many) DVB devices you've connected
to your ARM based product.

can you enlighten me?
is this worth opening up a new thread?

cheers and happy new year
Harry
Title: Re: Vomp on ARM/Marvell
Post by: AndersF on January 01, 2010, 20:27:07
Hi,

For maximum versatility and simplicity, I bought the OpenRD client (http://www.globalscaletechnologies.com/p-24-openrd-client-openrd-client-board-with-enclosure.aspx)
I have connected the TV receiver and the hard disk to the USB connectors. I will move the disk to eSATA later.
The OS is debian Linux. No otimization is performed with regards, to performance.
There's only 18 MB left of the 512 MB RA. 9% of the memory is used by vdr-kbd. What's it used for?
The load when recording one channel, and viewing another one, is approximately 0.9 (as shown by top)

BR
Anders
Title: Re: Vomp on ARM/Marvell
Post by: Harry on January 03, 2010, 18:17:05
wow!

thanks for the insight.
AFAICR there's only one (USB) DVB-S device supported by VDR.
(i have DVB-S only)
if i'd eventually switch to an ARM based solution, it'd have to handle
no less than three DVB devices. looking at your "top" value.. this shouldn't
be a problem, though.

thx again and cheers
Harry
Title: Re: Vomp on ARM/Marvell
Post by: champpain on November 22, 2010, 15:36:11
QuoteHi,

my Debian/Squeeze installation with VDR 1.6.0 (standard ARM repostiory) is working stable.
I downloaded the latest version (0.3.1) as source code and compiled it succesfully.
Hi.
Can anyone help me compiling vompserver on a dockstar (ARM) including the PATCH that is mentioned in this thread?
The dockstar is my first debian-system and i really don`t know how to compile it the right way....
:(
Title: Re: Vomp on ARM/Marvell
Post by: champpain on December 09, 2010, 20:14:14
Hi.
I have the same problem like wauwau, but the patch did not improved the situation.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
11:01:13.542963 [debug]  RRProc - threadMethod waiting
11:01:19.542119 [debug]  Client - Received chan=3 kats=1291888876
11:01:19.542349 [debug]  Client - Waiting
11:01:20.850028 [debug]  Client - Received chan=1, ser=47, op=5, edl=0
11:01:20.850149 [debug]  RRProc - recvReq set req and signalled
11:01:20.850209 [debug]  Client - Waiting
11:01:20.850281 [debug]  RRProc - thread woken with req, queue size: 1
11:01:20.850610 [debug]  Config - Config error: Key Channels not found
11:01:20.850677 [debug]  RRProc - name: 'Das Erste'
11:01:20.850730 [debug]  RRProc - name: 'ZDF'
11:01:20.850778 [debug]  RRProc - name: 'rbb Berlin'
11:01:20.850826 [debug]  RRProc - name: 'MDR Sachsen'
11:01:20.850873 [debug]  RRProc - name: 'NDR FERNSEHEN'
11:01:20.850919 [debug]  RRProc - name: 'arte'
11:01:20.850966 [debug]  RRProc - name: '3sat'
11:01:20.851012 [debug]  RRProc - name: 'neo/KiKa'
11:01:20.851059 [debug]  RRProc - name: 'ZDFinfokanal'
11:01:20.851105 [debug]  RRProc - name: 'Phoenix'
11:01:... RRProc - thread woken with req, queue size: 1
11:01:24.724075 [debug]  RRProc - req->dataLength = 4
11:01:24.724167 [debug]  Client - Looking for channel 1::: number: 1 name: 'Das Erste'
11:01:24.724222 [debug]  Client - Found channel number 1, vpid = 1401, apid1 = 1402
11:01:24.724480 [debug]  RRProc - Config: Live TV priority: 1
11:01:24.724543 [debug]  RRProc - Using live TV priority 1
11:01:24.725672 [debug]  MVPReceiver - VDR active
11:01:24.725833 [debug]  MVPReceiver - num mvp receivers now up to 1
11:01:24.725976 [debug]  RRProc - threadMethod waiting
11:01:30.721427 [debug]  Client - Received chan=3 kats=1291888888
11:01:30.721632 [debug]  Client - Waiting
11:01:36.721046 [debug]  Client - Received chan=3 kats=1291888894
11:01:36.721224 [debug]  Client - Waiting
11:01:42.720668 [debug]  Client - Received chan=3 kats=1291888900
11:01:42.720847 [debug]  Client - Waiting
11:01:48.720291 [debug]  Client - Received chan=3 kats=1291888906
11:01:48.720469 [debug]  Client - Waiting

Any other ideas?
Title: Re: Vomp on ARM/Marvell
Post by: mauwag on February 07, 2011, 22:08:50
Hallo,

how do I compile the current vompserver for a QNAP TS-119, firmware version 3.3.9 Build0120.

Greetings
mauwag

Title: Re: Vomp on ARM/Marvell
Post by: meinetwegen on February 21, 2011, 22:14:43
Hi,

This patch fixes the problems described in this thread. They are caused by ARM5 being
incapable of handling unaligned data access. Details can be found here:

http://infocenter.arm.com/help/topic/com.arm.doc.dui0473c/Cihdbfje.html

This patch should be applied to vompserver 0.3.1-3 since the debian-kirkwood system
seems to be especially susceptible to the problem described in the thread below which
has been fixed in 0.3.1-3.

http://forum.loggytronic.com/index.php?topic=528.0



Index: defines.h
===================================================================
--- defines.h (revision 7)
+++ defines.h (working copy)
@@ -32,4 +32,25 @@

typedef int32_t INT;

+/* serializes a numeric host data type into a byte stream in network order (big endian) */
+template<typename T>
+UCHAR* htoncpy(UCHAR* dest, T src)
+{
+  int len = sizeof(T);
+  while (len--)
+    *dest++ = src >> (len * 8);
+  return dest;
+}
+
+/* decodes a byte stream in network order (big endian) into a numeric host data type */
+template<typename T>
+UCHAR* ntohcpy(T& dest, UCHAR* src)
+{
+  dest = *src++;
+  int len = sizeof(T);
+  while (--len)
+    dest = (dest << 8) | *src++;
+  return src;
+}
+
#endif
Index: mvpreceiver.c
===================================================================
--- mvpreceiver.c (revision 7)
+++ mvpreceiver.c (working copy)
@@ -133,10 +133,10 @@
      amountReceived = processed.get(buffer+headerLength, streamChunkSize);
      pthread_mutex_unlock(&processedRingLock);
   
-      *(ULONG*)&buffer[0] = htonl(2); // stream channel
-      *(ULONG*)&buffer[4] = htonl(streamID);
-      *(ULONG*)&buffer[8] = htonl(0); // here insert flag: 0 = ok, data follows
-      *(ULONG*)&buffer[12] = htonl(amountReceived);
+      htoncpy(&buffer[0], 2); // stream channel
+      htoncpy(&buffer[4], streamID);
+      htoncpy(&buffer[8], 0); // here insert flag: 0 = ok, data follows
+      htoncpy(&buffer[12], amountReceived);

      tcp->sendPacket(buffer, amountReceived + headerLength);
    } while(processed.getContent() >= streamChunkSize);
@@ -147,10 +147,10 @@
{
  ULONG bufferLength = sizeof(ULONG) * 4;
  UCHAR buffer[bufferLength];
-  *(ULONG*)&buffer[0] = htonl(2); // stream channel
-  *(ULONG*)&buffer[4] = htonl(streamID);
-  *(ULONG*)&buffer[8] = htonl(1); // stream end
-  *(ULONG*)&buffer[12] = htonl(0); // zero length, no more data
+  htoncpy(&buffer[0], 2); // stream channel
+  htoncpy(&buffer[4], streamID);
+  htoncpy(&buffer[8], 1); // stream end
+  htoncpy(&buffer[12], 0); // zero length, no more data
  tcp->sendPacket(buffer, bufferLength);
}

Index: mvprelay.c
===================================================================
--- mvprelay.c (revision 7)
+++ mvprelay.c (working copy)
@@ -73,7 +73,8 @@

    // Check incoming packet magic number

-    ULONG inMagic = ntohl(*(ULONG*)&in[4]);
+    ULONG inMagic;
+    ntohcpy(inMagic, &in[4]);
    if (inMagic != 0xbabefafe)
    {
      Log::getInstance()->log("MVPRelay", Log::DEBUG, "inMagic not correct");
@@ -81,10 +82,13 @@
    }

    // Get peer info
-    USHORT peerPort = ntohs(*(USHORT*)&in[20]);
+    USHORT peerPort;
+    ntohcpy(peerPort, &in[20]);

    // Get my IP for this connection
-    ULONG myIP = ds.getMyIP(*(ULONG*)&in[16]);
+    ULONG myIP;
+    memcpy(&myIP, &in[16], sizeof(myIP));
+    myIP = ds.getMyIP(myIP);
    Log::getInstance()->log("MVPRelay", Log::DEBUG, "Sending my IP as %x", ntohl(myIP));

    // Required return parameters:
@@ -102,13 +106,13 @@
    memcpy(out, in, 4);

    // Return magic number is 0xfafebabe
-    *(ULONG*)&out[4] = htonl(0xfafebabe);
+    htoncpy(&out[4], 0xfafebabe);

    // Copy client IP and port to reply
    memcpy(&out[16], &in[16], 6);

    // Insert server address
-    *(ULONG*)&out[24] = myIP;
+    memcpy(&out[24], &myIP, sizeof(myIP));

    // Send it
    ds.send(ds.getFromIPA(), peerPort, (char*)out, 52);
Index: responsepacket.c
===================================================================
--- responsepacket.c (revision 7)
+++ responsepacket.c (working copy)
@@ -53,9 +53,9 @@
  buffer = (UCHAR*)malloc(bufSize);
  if (!buffer) return false;
 
-  *(ULONG*)&buffer[0] = htonl(1); // RR channel
-  *(ULONG*)&buffer[4] = htonl(requestID);
-  *(ULONG*)&buffer[userDataLenPos] = 0;
+  htoncpy(buffer, 1);  // RR channel
+  htoncpy(buffer+4, requestID);
+  htoncpy(buffer+userDataLenPos, 0);
  bufUsed = headerLength;

  return true;
@@ -63,7 +63,7 @@

void ResponsePacket::finalise()
{
-  *(ULONG*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+  htoncpy(buffer + userDataLenPos, bufUsed - headerLength);
  //Log::getInstance()->log("Client", Log::DEBUG, "RP finalise %lu", bufUsed - headerLength);
}

@@ -87,46 +87,41 @@
bool ResponsePacket::addULONG(ULONG ul)
{
  if (!checkExtend(sizeof(ULONG))) return false;
-  *(ULONG*)&buffer[bufUsed] = htonl(ul);
-  bufUsed += sizeof(ULONG);
+  bufUsed = htoncpy(buffer + bufUsed, ul) - buffer;
  return true;
}  

bool ResponsePacket::addUCHAR(UCHAR c)
{
  if (!checkExtend(sizeof(UCHAR))) return false;
-  buffer[bufUsed] = c;
-  bufUsed += sizeof(UCHAR);
+  buffer[bufUsed++] = c;
  return true;
}  
 
bool ResponsePacket::addLONG(LONG l)
{
  if (!checkExtend(sizeof(LONG))) return false;
-  *(LONG*)&buffer[bufUsed] = htonl(l);
-  bufUsed += sizeof(LONG);
+  bufUsed = htoncpy(buffer + bufUsed, l) - buffer;
  return true;
}

bool ResponsePacket::addULLONG(ULLONG ull)
{
  if (!checkExtend(sizeof(ULLONG))) return false;
-  *(ULLONG*)&buffer[bufUsed] = htonll(ull);
-  bufUsed += sizeof(ULLONG);
+  bufUsed = htoncpy(buffer + bufUsed, ull) - buffer;
  return true;
}

bool ResponsePacket::adddouble(double d)
{
-  if (!checkExtend(sizeof(double))) return false;
-  ULLONG ull;
-  memcpy(&ull,&d,sizeof(double));
-  *(ULLONG*)&buffer[bufUsed] = htonll(ull);
-  bufUsed += sizeof(ULLONG);
-  return true;
+  union {
+    double d;
+    ULLONG ull;
+  } u;
+  u.d = d;
+  return addULLONG(u.ull);
}

-
bool ResponsePacket::checkExtend(ULONG by)
{
  if ((bufUsed + by) < bufSize) return true;
@@ -138,23 +133,3 @@
  return true;
}

-ULLONG ResponsePacket::htonll(ULLONG a)
-{
-  #if BYTE_ORDER == BIG_ENDIAN
-    return a;
-  #else
-    ULLONG b = 0;
-
-    b = ((a << 56) & 0xFF00000000000000ULL)
-      | ((a << 40) & 0x00FF000000000000ULL)
-      | ((a << 24) & 0x0000FF0000000000ULL)
-      | ((a <<  8) & 0x000000FF00000000ULL)
-      | ((a >>  8) & 0x00000000FF000000ULL)
-      | ((a >> 24) & 0x0000000000FF0000ULL)
-      | ((a >> 40) & 0x000000000000FF00ULL)
-      | ((a >> 56) & 0x00000000000000FFULL) ;
-
-    return b;
-  #endif
-}
-
Index: responsepacket.h
===================================================================
--- responsepacket.h (revision 7)
+++ responsepacket.h (working copy)
@@ -49,8 +49,7 @@
    ULONG bufUsed;

    bool checkExtend(ULONG by);
-    ULLONG htonll(ULLONG a);
-    
+
    const static ULONG headerLength = 12;
    const static ULONG userDataLenPos = 8;
};
Index: serialize.c
===================================================================
--- serialize.c (revision 7)
+++ serialize.c (working copy)
@@ -97,28 +97,22 @@

int SerializeBuffer::encodeLong(ULONG data) {
  if (checkSpace( (int)sizeof(ULONG))!=0) return -1;
-  *((ULONG *)(current))=htonl(data);
-  current+=sizeof(ULONG);
+  current = htoncpy(current, data);
  return 0;
}
int SerializeBuffer::encodeShort(USHORT data) {
  if (checkSpace( (int)sizeof(USHORT))!=0) return -1;
-  *((USHORT *)(current))=htons(data);
-  current+=sizeof(USHORT);
+  current = htoncpy(current, data);
  return 0;
}
int SerializeBuffer::encodeByte(UCHAR data) {
  if (checkSpace( (int)sizeof(UCHAR))!=0) return -1;
-  *((UCHAR *)(current))=data;
-  current+=sizeof(UCHAR);
+  current = htoncpy(current, data);
  return 0;
}
int SerializeBuffer::encodeLongLong(ULLONG data) {
  if (checkSpace( (int)sizeof(ULLONG))!=0) return -1;
-  *((ULONG *)(current))=htonl((data>>32) & 0xffffffff);
-  current+=sizeof(ULONG);
-  *((ULONG *)(current))=htonl(data & 0xffffffff);
-  current+=sizeof(ULONG);
+  current = htoncpy(current, data);
  return 0;
}
//string: 4 len, string with 0
@@ -126,8 +120,7 @@
  if (checkSpace( (int)sizeof(ULONG))!=0) return -1;
  ULONG len=0;
  if (str) len=strlen(str)+1;
-  *((ULONG *)(current))=htonl(len);
-  current+=sizeof(ULONG);
+  current = htoncpy(current, len);
  if (len == 0) return 0;
  if (checkSpace((int)len)!=0) return -1;
  strcpy((char *) current,str);
@@ -136,35 +129,27 @@
}
int SerializeBuffer::decodeLong( int &data) {
  if (checkSpace( (int)sizeof(ULONG))!=0) return -1;
-  data=(int)ntohl(*((ULONG *)(current)));
-  current+=sizeof(ULONG);
+  current = ntohcpy(data, current);
  return 0;
}
int SerializeBuffer::decodeLong(ULONG &data) {
  if (checkSpace( (int)sizeof(ULONG))!=0) return -1;
-  data=ntohl(*((ULONG *)(current)));
-  current+=sizeof(ULONG);
+  current = ntohcpy(data, current);
  return 0;
}
int SerializeBuffer::decodeShort(USHORT &data) {
  if (checkSpace( (int)sizeof(USHORT))!=0) return -1;
-  data=ntohs(*((USHORT *)(current)));
-  current+=sizeof(USHORT);
+  current = ntohcpy(data, current);
  return 0;
}
int SerializeBuffer::decodeByte(UCHAR &data) {
  if (checkSpace( (int)sizeof(UCHAR))!=0) return -1;
-  data=*((UCHAR *)current);
-  current+=sizeof(UCHAR);
+  current = ntohcpy(data, current);
  return 0;
}
int SerializeBuffer::decodeLongLong(ULLONG &data) {
  if (checkSpace( (int)sizeof(ULLONG))!=0) return -1;
-  ULLONG hd=ntohl(*((ULONG *)(current)));
-  current+=sizeof(ULONG);
-  ULLONG ld=ntohl(*((ULONG *)(current)));
-  current+=sizeof(ULONG);
-  data=(hd << 32) | ld;
+  current = ntohcpy(data, current);
  return 0;
}
//string: 4 len, string with 0
@@ -172,8 +157,7 @@
  strbuf=NULL;
  len=0;
  if (checkSpace( (int)sizeof(ULONG))!=0) return -1;
-  len=ntohl(*((ULONG *)(current)));
-  current+=sizeof(ULONG);
+  current = ntohcpy(len, current);
  if (len == 0) return 0;
  if (checkSpace((int)len)!=0) return -1;
  strbuf=new char[len];
Index: tftpclient.c
===================================================================
--- tftpclient.c (revision 7)
+++ tftpclient.c (working copy)
@@ -156,8 +156,8 @@
//  dump(data, (USHORT)length);

  if ((UINT)length < sizeof(USHORT)) return 0;
-  USHORT opcode = ntohs(*(USHORT*)data);
-  data += sizeof(USHORT);
+  USHORT opcode;
+  data = ntohcpy(opcode, data);
  length -= sizeof(USHORT);

  switch(opcode)
@@ -232,7 +232,8 @@

  if (length != 2) return 0;

-  USHORT ackBlock = ntohs(*(USHORT*)data);
+  USHORT ackBlock;
+  ntohcpy(ackBlock, data);

  if (ackBlock == (blockNumber - 1))
  {
@@ -290,8 +291,8 @@

int TftpClient::sendBlock()
{
-  *(USHORT*)&buffer[0] = htons(3);
-  *(USHORT*)&buffer[2] = htons(blockNumber++);
+  htoncpy<USHORT>(&buffer[0], 3);
+  htoncpy<USHORT>(&buffer[2], blockNumber++);
  bufferLength = 4 + fread(&buffer[4], 1, 512, file);

  if (bufferLength < 516) // 512 + 4 header
Index: vompclient.c
===================================================================
--- vompclient.c (revision 7)
+++ vompclient.c (working copy)
@@ -289,10 +289,10 @@

      log->log("Client", Log::DEBUG, "Received chan=%lu kats=%lu", channelID, kaTimeStamp);    

-      UCHAR buffer[8];
-      *(ULONG*)&buffer[0] = htonl(3); // KA CHANNEL
-      *(ULONG*)&buffer[4] = htonl(kaTimeStamp);
-      if (!tcp.sendPacket(buffer, 8))
+      ULONG buffer[2];
+      buffer[0] = htonl(3); // KA CHANNEL
+      buffer[1] = htonl(kaTimeStamp);
+      if (!tcp.sendPacket((UCHAR*)buffer, 8))
      {
        log->log("Client", Log::ERR, "Could not send back KA reply");
        break;
@@ -328,31 +328,6 @@
  }
}

-ULLONG VompClient::ntohll(ULLONG a)
-{
-  return htonll(a);
-}
-
-ULLONG VompClient::htonll(ULLONG a)
-{
-  #if BYTE_ORDER == BIG_ENDIAN
-    return a;
-  #else
-    ULLONG b = 0;
-
-    b = ((a << 56) & 0xFF00000000000000ULL)
-      | ((a << 40) & 0x00FF000000000000ULL)
-      | ((a << 24) & 0x0000FF0000000000ULL)
-      | ((a <<  8) & 0x000000FF00000000ULL)
-      | ((a >>  8) & 0x00000000FF000000ULL)
-      | ((a >> 24) & 0x0000000000FF0000ULL)
-      | ((a >> 40) & 0x000000000000FF00ULL)
-      | ((a >> 56) & 0x00000000000000FFULL) ;
-
-    return b;
-  #endif
-}
-
#ifndef VOMPSTANDALONE

cChannel* VompClient::channelFromNumber(ULONG channelNumber)
Index: vompclient.h
===================================================================
--- vompclient.h (revision 7)
+++ vompclient.h (working copy)
@@ -81,9 +81,6 @@
    static void incClients();
    static void decClients();

-    static ULLONG ntohll(ULLONG a);
-    static ULLONG htonll(ULLONG a);
-    
    VompClientRRProc rrproc;
    pthread_t runThread;
    int initted;
Index: vompclientrrproc.c
===================================================================
--- vompclientrrproc.c (revision 7)
+++ vompclientrrproc.c (working copy)
@@ -952,7 +952,8 @@

int VompClientRRProc::processGetChannelPids()
{
-  ULONG channelNumber = ntohl(*(ULONG*)req->data);
+  ULONG channelNumber;
+  ntohcpy(channelNumber, req->data);

  cChannel* channel = x.channelFromNumber(channelNumber);
  if (!channel)
@@ -1076,7 +1077,8 @@
  }
 
  log->log("RRProc", Log::DEBUG, "req->dataLength = %i", req->dataLength);
-  ULONG channelNumber = ntohl(*(ULONG*)req->data);
+  ULONG channelNumber;
+  ntohcpy(channelNumber, req->data);

  cChannel* channel = x.channelFromNumber(channelNumber);

@@ -1172,9 +1174,10 @@

  UCHAR* data = req->data;

-  ULLONG position = x.ntohll(*(ULLONG*)data);
-  data += sizeof(ULLONG);
-  ULONG amount = ntohl(*(ULONG*)data);
+  ULLONG position;
+  data = ntohcpy(position, data);
+  ULONG amount;
+  ntohcpy(amount, data);

  log->log("RRProc", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);

@@ -1239,7 +1242,8 @@
{
  ULLONG retval = 0;

-  ULONG frameNumber = ntohl(*(ULONG*)req->data);
+  ULONG frameNumber;
+  ntohcpy(frameNumber, req->data);

  if (!x.recplayer)
  {
@@ -1262,7 +1266,8 @@
{
  ULONG retval = 0;

-  ULLONG position = x.ntohll(*(ULLONG*)req->data);
+  ULLONG position;
+  ntohcpy(position, req->data);

  if (!x.recplayer)
  {
@@ -1285,11 +1290,12 @@
{
  bool success = false;

-  ULONG* data = (ULONG*)req->data;
+  UCHAR* data = req->data;

-  ULONG frameNumber = ntohl(*data);
-  data++;
-  ULONG direction = ntohl(*data);
+  ULONG frameNumber;
+  data = ntohcpy(frameNumber, data);
+  ULONG direction;
+  ntohcpy(direction, data);

  ULLONG rfilePosition = 0;
  ULONG rframeNumber = 0;
@@ -1326,14 +1332,17 @@

int VompClientRRProc::processGetChannelSchedule()
{
-  ULONG* data = (ULONG*)req->data;
+  UCHAR* data = req->data;

-  ULONG channelNumber = ntohl(*data);
-  data++;
-  ULONG startTime = ntohl(*data);
-  data++;
-  ULONG duration = ntohl(*data);
+  ULONG channelNumber;
+  data = ntohcpy(channelNumber, data);

+  ULONG startTime;
+  data = ntohcpy(startTime, data);
+
+  ULONG duration;
+  ntohcpy(duration, data);
+
  log->log("RRProc", Log::DEBUG, "get schedule called for channel %lu", channelNumber);

  cChannel* channel = x.channelFromNumber(channelNumber);
@@ -1570,13 +1579,22 @@
  log->log("RRProc", Log::DEBUG, "Delete timer called");
  // get timer
 
-  int position = 0;
+  UCHAR* data = req->data;
 
-  INT delChannel = ntohl(*(ULONG*)&req->data[position]); position += 4;
-  INT delWeekdays = ntohl(*(ULONG*)&req->data[position]); position += 4;
-  INT delDay = ntohl(*(ULONG*)&req->data[position]); position += 4;  
-  INT delStart = ntohl(*(ULONG*)&req->data[position]); position += 4;  
-  INT delStop = ntohl(*(ULONG*)&req->data[position]); position += 4;
+  INT delChannel;
+  data = ntohcpy(delChannel, data);
+
+  INT delWeekdays;
+  data = ntohcpy(delWeekdays, data);
+
+  INT delDay;
+  data = ntohcpy(delDay, data);
+
+  INT delStart;
+  data = ntohcpy(delStart, data);
+
+  INT delStop;
+  data = ntohcpy(delStop, data);
   
  cTimer* ti = NULL;
  for (ti = Timers.First(); ti; ti = Timers.Next(ti))