Coverage Report

Created: 2023-05-19 06:16

/src/ntp-dev/libntp/numtoa.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * numtoa - return asciized network numbers store in local array space
3
 */
4
#include <config.h>
5
6
#include <sys/types.h>
7
#ifdef HAVE_NETINET_IN_H
8
#include <netinet/in.h>   /* ntohl */
9
#endif
10
11
#include <stdio.h>
12
13
#include "ntp_fp.h"
14
#include "lib_strbuf.h"
15
#include "ntp_stdlib.h"
16
17
char *
18
numtoa(
19
  u_int32 num
20
  )
21
0
{
22
0
  register u_int32 netnum;
23
0
  register char *buf;
24
25
0
  netnum = ntohl(num);
26
0
  LIB_GETBUF(buf);
27
0
  snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
28
0
     ((u_long)netnum >> 24) & 0xff,
29
0
     ((u_long)netnum >> 16) & 0xff,
30
0
     ((u_long)netnum >> 8) & 0xff,
31
0
     (u_long)netnum & 0xff);
32
0
  return buf;
33
0
}
34
35
36
/* Convert a refid & stratum to a string */
37
const char *
38
refid_str(
39
  u_int32 refid,
40
  int stratum
41
  )
42
0
{
43
0
  char *  text;
44
0
  size_t  tlen;
45
46
0
  if (stratum > 1)
47
0
    return numtoa(refid);
48
49
0
  LIB_GETBUF(text);
50
0
  text[0] = '.';
51
0
  memcpy(&text[1], &refid, sizeof(refid));
52
0
  text[1 + sizeof(refid)] = '\0';
53
0
  tlen = strlen(text);
54
0
  text[tlen] = '.';
55
0
  text[tlen + 1] = '\0';
56
57
0
  return text;
58
0
}
59