File: ip4atos.c

package info (click to toggle)
rbldnsd 0.998b~pre1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 744 kB
  • ctags: 1,132
  • sloc: ansic: 8,212; python: 549; sh: 502; makefile: 249; awk: 33
file content (31 lines) | stat: -rw-r--r-- 661 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
/* ip4atos() converts binary IP4 address into textual printable
 * dotted-quad form.
 */

#include "ip4addr.h"

/* helper routine for ip4atos() */

static char *oct(char *s, unsigned char o, char e) {
  if (o >= 100) {
    *s++ = o / 100 + '0', o %= 100;
    *s++ = o / 10 + '0', o %= 10;
  }
  else if (o >= 10)
    *s++ = o / 10 + '0', o %= 10;
  *s++ = o + '0';
  *s++ = e;
  return s;
}

/* return printable representation of ip4addr like inet_ntoa() */

const char *ip4atos(ip4addr_t a) {
  static char buf[16];
  oct(oct(oct(oct(buf,
    (a >> 24) & 0xff, '.'),
    (a >> 16) & 0xff, '.'),
    (a >>  8) & 0xff, '.'),
    a & 0xff, '\0');
  return buf;
}