File: binio.c

package info (click to toggle)
ntpsec 1.2.3%2Bdfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,960 kB
  • sloc: ansic: 62,004; python: 32,017; sh: 1,553; yacc: 1,293; makefile: 190; javascript: 138
file content (94 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright Frank Kardel <kardel <AT> ntp.org>
 * Copyright the NTPsec project contributors
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "config.h"
#include "binio.h"

int16_t
get_lsb_int16(
	unsigned char **bufpp
	)
{
	int16_t retval;

	retval  = *((*bufpp)++);
	retval |= *((*bufpp)++) << 8;

	return retval;
}

void
put_lsb_uint16(
	unsigned char **bufpp,
	uint16_t val
	)
{
	*((*bufpp)++) = (unsigned char) (val        & 0xFF);
	*((*bufpp)++) = (unsigned char) ((val >> 8) & 0xFF);
}

int32_t
get_lsb_int32(
	unsigned char **bufpp
	)
{
	int32_t retval;

	retval  = *((*bufpp)++);
	retval |= *((*bufpp)++) << 8;
	retval |= *((*bufpp)++) << 16;
	retval |= *((*bufpp)++) << 24;

	return retval;
}

unsigned short
get_msb_ushort(
	 unsigned char *p
	 )
{
	return (unsigned short) get_msb_short(&p);
}

short
getmsb_short(
	 unsigned char *p
	 )
{
	return (short) get_msb_short(&p);
}

long
get_msb_short(
	unsigned char **bufpp
	)
{
	long retval;

	retval  = *((*bufpp)++) << 8;
	retval |= *((*bufpp)++);

	return (retval & 0x8000) ? (~0xFFFF | retval) : retval;
}

/*
 * binio.c,v
 * Revision 4.2  1999/02/21 12:17:34  kardel
 * 4.91f reconciliation
 *
 * Revision 4.1  1998/06/28 16:47:50  kardel
 * added {get,put}_msb_{short,long} functions
 *
 * Revision 4.0  1998/04/10 19:46:16  kardel
 * Start 4.0 release version numbering
 *
 * Revision 1.1  1998/04/10 19:27:46  kardel
 * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
 *
 * Revision 1.1  1997/10/06 21:05:46  kardel
 * new parse structure
 *
 */