CI opt-test: Drop Python2 & Bash in Fedora latest.
[ntpsec.git] / libntp / numtoa.c
blob34de1321e824cd95a47ecb7b61f420296b9e969a
1 /*
2 * numtoa - return asciized network numbers store in local array space
3 */
4 #include "config.h"
6 #include <sys/types.h>
7 #include <netinet/in.h> /* ntohl */
9 #include <stdio.h>
11 #include "ntp_fp.h"
12 #include "lib_strbuf.h"
13 #include "ntp_stdlib.h"
15 /* Convert a refid & stratum to a string
16 * Only used by record_raw_stats
18 const char *
19 refid_str(
20 uint32_t refid,
21 int stratum
24 char * text;
25 size_t tlen;
27 if (stratum > 1) {
28 struct in_addr in4;
29 in4.s_addr = refid;
30 return inet_ntoa(in4);
33 text = lib_getbuf();
34 memcpy(&text[0], &refid, sizeof(refid));
35 text[1 + sizeof(refid)] = '\0';
36 // Chop off trailing spaces. Facebook was sending "FB "
37 for (int i=sizeof(refid)-1; i>0; i--) {
38 if (text[i] != ' ') break;
39 text[i] = '\0';
41 tlen = strlen(text);
42 if (0 == tlen) {
43 strlcat(text, "?", LIB_BUFLENGTH);
46 return text;