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