diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-09-28 21:20:40 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-09-28 21:33:03 +0200 |
commit | 8e7e029114c59341ec793dc9e96ee410a5f37e2b (patch) | |
tree | ac196b359c93716158dedd767f425d9e093c9b71 /src/ip4.c | |
parent | f9a8fff2f90626aadd915178d04ece49d8c4884a (diff) |
update to version 25meson
Diffstat (limited to 'src/ip4.c')
-rw-r--r-- | src/ip4.c | 116 |
1 files changed, 55 insertions, 61 deletions
@@ -5,19 +5,18 @@ /** @file ip4.c - @author djb, fefe, feh, kp - @source ucspi-tcp, ucspi-tcp6 + @authors djb, fefe, feh, kp + @ref ucspi-tcp, ucspi-tcp6 @brief handling of IPv4 addresses */ /** - @brief ip4_fmt - converts IPv4 address to dotted decimal string format - @param input: IPv4 char array - output: IPv4 address string - @return int length of address (ok > 0) - */ - + * @brief ip4_fmt + * converts IPv4 address to dotted decimal string format + * @param input: IPv4 char array + * output: IPv4 address string + * @return int length of address (ok > 0) + */ unsigned int ip4_fmt(char *s, char ip[4]) { unsigned int len; @@ -25,25 +24,24 @@ unsigned int ip4_fmt(char *s, char ip[4]) len = 0; // clang-format off - i = fmt_ulong(s,(unsigned long) (unsigned char) ip[0]); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)(unsigned char)ip[0]); len += i; if (s) s += i; if (s) { *s++ = '.'; } ++len; - i = fmt_ulong(s,(unsigned long) (unsigned char) ip[1]); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)(unsigned char)ip[1]); len += i; if (s) s += i; if (s) { *s++ = '.'; } ++len; - i = fmt_ulong(s,(unsigned long) (unsigned char) ip[2]); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)(unsigned char)ip[2]); len += i; if (s) s += i; if (s) { *s++ = '.'; } ++len; - i = fmt_ulong(s,(unsigned long) (unsigned char) ip[3]); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)(unsigned char)ip[3]); len += i; if (s) s += i; // clang-format on return len; } /** - @brief ia4_fmt - converts IPv4 address into DNS inverse nibble format - @param input: IPv4 char array - output: IPv4 address string - @return int length of address (ok > 0) - */ - + * @brief ia4_fmt + * converts IPv4 address into DNS inverse nibble format + * @param input: IPv4 char array + * output: IPv4 address string + * @return int length of address (ok > 0) + */ unsigned int ia4_fmt(char *s, char ip[4]) { unsigned int i; @@ -51,26 +49,25 @@ unsigned int ia4_fmt(char *s, char ip[4]) len = 0; // clang-format off - i = fmt_ulong(s,(unsigned long) ip[3]); len += i; if (s) s += i; - i = fmt_str(s,"."); len += i; if (s) s += i; - i = fmt_ulong(s,(unsigned long) ip[2]); len += i; if (s) s += i; - i = fmt_str(s,"."); len += i; if (s) s += i; - i = fmt_ulong(s,(unsigned long) ip[1]); len += i; if (s) s += i; - i = fmt_str(s,"."); len += i; if (s) s += i; - i = fmt_ulong(s,(unsigned long) ip[0]); len += i; if (s) s += i; - i = fmt_str(s,".in-addr.arpa."); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)ip[3]); len += i; if (s) s += i; + i = fmt_str(s, "."); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)ip[2]); len += i; if (s) s += i; + i = fmt_str(s, "."); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)ip[1]); len += i; if (s) s += i; + i = fmt_str(s, "."); len += i; if (s) s += i; + i = fmt_ulong(s, (unsigned long)ip[0]); len += i; if (s) s += i; + i = fmt_str(s, ".in-addr.arpa."); len += i; if (s) s += i; // clang-format on return len; } /** - @brief ip4_scan - parse IPv4 address string and convert to IP address array - @param input: IPv4 address string - output: IPv4 char array - @return int length of ip_address (ok > 0) - */ - + * @brief ip4_scan + * parse IPv4 address string and convert to IP address array + * @param input: IPv4 address string + * output: IPv4 char array + * @return int length of ip_address (ok > 0) + */ unsigned int ip4_scan(const char *s, char ip[4]) { unsigned int i; @@ -80,25 +77,24 @@ unsigned int ip4_scan(const char *s, char ip[4]) byte_zero(ip, 4); len = 0; // clang-format off - i = scan_ulong((char *)s,&u); if (!i) { return 0; } ip[0] = u; s += i; len += i; + i = scan_ulong((char *)s, &u); if (!i) { return 0; } ip[0] = u; s += i; len += i; if (*s != '.') { return 0; } ++s; ++len; - i = scan_ulong((char *)s,&u); if (!i) { return 0; } ip[1] = u; s += i; len += i; + i = scan_ulong((char *)s, &u); if (!i) { return 0; } ip[1] = u; s += i; len += i; if (*s != '.') { return 0; } ++s; ++len; - i = scan_ulong((char *)s,&u); if (!i) { return 0; } ip[2] = u; s += i; len += i; + i = scan_ulong((char *)s, &u); if (!i) { return 0; } ip[2] = u; s += i; len += i; if (*s != '.') { return 0; } ++s; ++len; - i = scan_ulong((char *)s,&u); if (!i) { return 0; } ip[3] = u; s += i; len += i; + i = scan_ulong((char *)s, &u); if (!i) { return 0; } ip[3] = u; s += i; len += i; // clang-format on return len; } /** - @brief ip4_scanbracket - parse IPv4 address string enclosed in brackets and convert to IP address array - @param input: IPv4 char array - output: IPv4 char array - @return int length of ip_address (ok > 0) - */ - + * @brief ip4_scanbracket + * parse IPv4 address string enclosed in brackets and convert to IP address array + * @param input: IPv4 char array + * output: IPv4 char array + * @return int length of ip_address (ok > 0) + */ unsigned int ip4_scanbracket(const char *s, char ip[4]) { unsigned int len; @@ -111,14 +107,13 @@ unsigned int ip4_scanbracket(const char *s, char ip[4]) } /** - @brief ip4_cidr - parse IPv4 address string - concatinated with the prefix length: 192.168.1/24 - @param input: IPv6 char array - output: IPv6 char array, long plen - @return int length of ip6_address/ip - */ - + * @brief ip4_cidr + * parse IPv4 address string + * concatinated with the prefix length: 192.168.1/24 + * @param input: IPv6 char array + * output: IPv6 char array, long plen + * @return int length of ip6_address/ip + */ unsigned int ip4_cidr(char *s, char ip[4], unsigned long *plen) { unsigned int j = 0; @@ -133,13 +128,12 @@ unsigned int ip4_cidr(char *s, char ip[4], unsigned long *plen) } /** - @brief ip4_bytestring - parse IPv4 address and represent as char string with length prefix - @param input: IPv4 char array, prefix length - output: pointer to stralloc bytestring - @return n: number of bytes, if ok; -1: memory shortage; -2: input error - */ - + * @brief ip4_bytestring + * parse IPv4 address and represent as char string with length prefix + * @param input: IPv4 char array, prefix length + * output: pointer to stralloc bytestring + * @return n: number of bytes, if ok; -1: memory shortage; -2: input error + */ unsigned int ip4_bytestring(stralloc *ipstring, char ip[4], int prefix) { int i, j, n = 0; |