zhangzengfei
2022-07-20 c90c3e794bdd95127d0c34ff1d9e8759d18a0445
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/****************************************************************************
 *
 *  Copyright (C) 2000-2001 RealNetworks, Inc. All rights reserved.
 *
 *  This program is free software.  It may be distributed under the terms
 *  in the file LICENSE, found in the top level of the source distribution.
 *
 */
 
#include <netinet/in.h>
#include "types.h"
 
//TODO: assembly-optimize these, for example use multiple registers
//      and convert blocks to avoid stalling the cpu pipeline
 
void htons_buf( UINT16* pnbuf, const void* phbuf, UINT32 cnt )
{
    register UINT16 tmp;
    while( cnt )
    {
        memcpy( &tmp, phbuf, 2 );
        *pnbuf = htons( tmp );
        phbuf = (char*)phbuf + 2; pnbuf++; cnt--;
    }
}
 
void ntohs_buf( UINT16* phbuf, const void* pnbuf, UINT32 cnt )
{
    register UINT16 tmp;
    while( cnt )
    {
        memcpy( &tmp, pnbuf, 2 );
        *phbuf = ntohs( tmp );
        pnbuf = (char*)pnbuf + 2; phbuf++; cnt--;
    }
}
 
void htonl_buf( UINT32* pnbuf, const void* phbuf, UINT32 cnt )
{
    register UINT32 tmp;
    while( cnt )
    {
        memcpy( &tmp, phbuf, 4 );
        *pnbuf = htonl( tmp );
        phbuf = (char*)phbuf + 4; pnbuf++; cnt--;
    }
}
 
void ntohl_buf( UINT32* phbuf, const void* pnbuf, UINT32 cnt )
{
    register UINT32 tmp;
    while( cnt )
    {
        memcpy( &tmp, pnbuf, 4 );
        *phbuf = ntohl( tmp );
        pnbuf = (char*)pnbuf + 4; phbuf++; cnt--;
    }
}