summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-11-11 19:20:42 +0100
committerlaforge <laforge@osmocom.org>2019-11-23 07:58:47 +0000
commitdf22b006333d67a17b6627fba3ce468a11daa8b1 (patch)
tree23139f5413d35eb83ab5aceb4d5599cab7261193 /src
parente883de54f8ab54ab84ffb75d68a5d5e100438d6f (diff)
osmo_sockaddr_str: API doc: fix 32bit addr mixup of host/network byte order
Of course both v4 and v6 addresses are kept in network byte order when represented in bytes, but when writing, I somehow must have assumed that inet_pton() returns host byte order. Fix that mixup in the API docs: osmo_sockaddr_str_from_32() and osmo_sockaddr_str_to_32() actually use network byte order. osmo_sockaddr_str_from_32n() and osmo_sockaddr_str_to_32n() actually use host byte order, though reflecting 'n' in their name. sockaddr_str_test: use hexdump instead of %x to show the osmo_sockaddr_str_to_32*() conversions so that the error becomes obvious. (Printing %x reverses the bytes again and made it look correct.) Change-Id: I3cf150cc0cc06dd36039fbde091bc71b01697322
Diffstat (limited to 'src')
-rw-r--r--src/sockaddr_str.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/sockaddr_str.c b/src/sockaddr_str.c
index 5c548b40..304363d9 100644
--- a/src/sockaddr_str.c
+++ b/src/sockaddr_str.c
@@ -255,7 +255,7 @@ int osmo_sockaddr_str_from_in6_addr(struct osmo_sockaddr_str *sockaddr_str, cons
return 0;
}
-/*! Convert IPv4 address from 32bit host-byte-order to osmo_sockaddr_str, and set port.
+/*! Convert IPv4 address from 32bit network-byte-order to osmo_sockaddr_str, and set port.
* \param[out] sockaddr_str The instance to copy to.
* \param[in] addr 32bit IPv4 address data.
* \param[in] port Port number.
@@ -270,7 +270,8 @@ int osmo_sockaddr_str_from_32(struct osmo_sockaddr_str *sockaddr_str, uint32_t i
return osmo_sockaddr_str_from_in_addr(sockaddr_str, &addr, port);
}
-/*! Convert IPv4 address from 32bit network-byte-order to osmo_sockaddr_str, and set port.
+/*! Convert IPv4 address from 32bit host-byte-order to osmo_sockaddr_str, and set port.
+ * For legacy reasons, this function has a misleading 'n' in its name.
* \param[out] sockaddr_str The instance to copy to.
* \param[in] addr 32bit IPv4 address data.
* \param[in] port Port number.
@@ -376,9 +377,9 @@ int osmo_sockaddr_str_to_in6_addr(const struct osmo_sockaddr_str *sockaddr_str,
return 0;
}
-/*! Convert osmo_sockaddr_str address string to IPv4 address data in host-byte-order.
+/*! Convert osmo_sockaddr_str address string to IPv4 address data in network-byte-order.
* \param[in] sockaddr_str The instance to convert the IP of.
- * \param[out] dst IPv4 address data in 32bit host-byte-order format to write to.
+ * \param[out] dst IPv4 address data in 32bit network-byte-order format to write to.
* \return 0 on success, negative on error (e.g. invalid IPv4 address string).
*/
int osmo_sockaddr_str_to_32(const struct osmo_sockaddr_str *sockaddr_str, uint32_t *ip)
@@ -396,9 +397,10 @@ int osmo_sockaddr_str_to_32(const struct osmo_sockaddr_str *sockaddr_str, uint32
return 0;
}
-/*! Convert osmo_sockaddr_str address string to IPv4 address data in network-byte-order.
+/*! Convert osmo_sockaddr_str address string to IPv4 address data in host-byte-order.
+ * For legacy reasons, this function has a misleading 'n' in its name.
* \param[in] sockaddr_str The instance to convert the IP of.
- * \param[out] dst IPv4 address data in 32bit network-byte-order format to write to.
+ * \param[out] dst IPv4 address data in 32bit host-byte-order format to write to.
* \return 0 on success, negative on error (e.g. invalid IPv4 address string).
*/
int osmo_sockaddr_str_to_32n(const struct osmo_sockaddr_str *sockaddr_str, uint32_t *ip)