Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / ep / ep_net.c @ master

History | View | Annotate | Download (2.5 KB)

1 5667bfa5 Eric Allman
/* vim: set ai sw=8 sts=8 ts=8 :*/
2
3
/***********************************************************************
4 055d3009 Eric Allman
**  ----- BEGIN LICENSE BLOCK -----
5
**        LIBEP: Enhanced Portability Library (Reduced Edition)
6
**
7 c87dd166 Eric Allman
**        Copyright (c) 2008-2019, Eric P. Allman.  All rights reserved.
8
**        Copyright (c) 2015-2019, Regents of the University of California.
9 6bd5476b Eric Allman
**        All rights reserved.
10 055d3009 Eric Allman
**
11 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
12
**        license or royalty fees, to use, copy, modify, and distribute this
13
**        software and its documentation for any purpose, provided that the above
14
**        copyright notice and the following two paragraphs appear in all copies
15
**        of this software.
16 055d3009 Eric Allman
**
17 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
18
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
19
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
20
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 055d3009 Eric Allman
**
22 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
23 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
25
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
26
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27
**        OR MODIFICATIONS.
28 055d3009 Eric Allman
**  ----- END LICENSE BLOCK -----
29 5667bfa5 Eric Allman
***********************************************************************/
30
31
#include "ep.h"
32
#include "ep_net.h"
33
34 6ce05103 Eric Allman
/*
35
**  Network support routines.
36
**
37
**        Right now these mostly have to do with endianness.
38
**
39
**        I assume that 64 bits are transmitted in pure big-endian format;
40
**        for example 0x000102030405060708090A0B0C0D0E0F is transmitted as
41
**        00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F.  On 32-bit
42
**        machines we might have a NUXI problem that would transmit as
43
**        08 09 0A 0B 0C 0D 0E 0F 00 01 02 03 04 05 06 07.
44
**
45
**        XXX THIS NEEDS MORE RESEARCH
46
*/
47
48
#ifndef EP_HWCF_64_BIT_NUXI_PROBLEM
49
# define EP_HWCF_64_BIT_NUXI_PROBLEM        0
50
#endif
51
52 5667bfa5 Eric Allman
uint64_t
53
_ep_net_swap64(uint64_t v)
54
{
55
        union
56
        {
57
                uint64_t        i64;
58
                uint32_t        i32[2];
59
        } a, b;
60
61
        a.i64 = v;
62 6ce05103 Eric Allman
63
#if EP_HWCF_64_BIT_NUXI_PROBLEM
64
        b.i32[0] = ep_net_hton32(a.i32[0]);
65
        b.i32[1] = ep_net_hton32(a.i32[1]);
66
#else
67 51bc567e Eric Allman
        b.i32[0] = ep_net_hton32(a.i32[1]);
68
        b.i32[1] = ep_net_hton32(a.i32[0]);
69 6ce05103 Eric Allman
#endif
70 5667bfa5 Eric Allman
        return b.i64;
71
}
72 51bc567e Eric Allman
73
74
int
75
_ep_net_swap_timespec(EP_TIME_SPEC *ts)
76
{
77
        uint32_t *p32;
78
79
        ts->tv_sec = ep_net_hton64(ts->tv_sec);
80
        ts->tv_nsec = ep_net_hton32(ts->tv_nsec);
81
        p32 = (uint32_t *) &ts->tv_accuracy;
82
        *p32 = ep_net_hton32(*p32);
83
        return 0;
84
}