Skip to contentSkip to conversation

lib: Document the endianity in tst_get_unused_port()

PATCH New Petr Vorel 3 participants 4 messages Jun 7, 2019 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 lib: Document the endianity in tst_get_unused_port()

To prevent confusing [1]:

if you want to print the port you actually have to use ntohs() function to convert it to the host endianity. And if you are passing that value in the sockaddr_in structure you must not use the htons() since the value is already in the correct byte order.

[1] http://lists.linux.it/pipermail/ltp/2019-June/012289.html

---
 lib/safe_net.c | 3 +++
 1 file changed, 3 insertions(+)
lib/safe_net.c +3 -0
index 970a2aba3..abebd1899 100644
@@ -373,6 +373,9 @@ int safe_gethostname(const char *file, const int lineno,
 	return rval;
 }
 
+/*
+ * @return port in network byte order.
+ */
 unsigned short tst_get_unused_port(const char *file, const int lineno,
 	      void (cleanup_fn)(void), unsigned short family, int type)
 {
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 lib: Document the endianity in tst_get_unused_port()

Hi!

That should make things more clear, thanks!

Quoted 19 lines · Petr Vorel

To prevent confusing [1]:

if you want to print the port you actually have to use ntohs() function to convert it to the host endianity. And if you are passing that value in the sockaddr_in structure you must not use the htons() since the value is already in the correct byte order.

[1] http://lists.linux.it/pipermail/ltp/2019-June/012289.html

---
 lib/safe_net.c | 3 +++
 1 file changed, 3 insertions(+)
lib/safe_net.c +0 -0
index 970a2aba3..abebd1899 100644

lib/safe_net.c int safe_gethostname(const char *file, const int lineno, · line 381

Quoted 9 lines
lib/safe_net.c +3 -0
@@ -373,6 +373,9 @@ int safe_gethostname(const char *file, const int lineno,
 	return rval;
 }
 
+/*
+ * @return port in network byte order.
+ */
 unsigned short tst_get_unused_port(const char *file, const int lineno,
 	      void (cleanup_fn)(void), unsigned short family, int type)
 {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190607/1d359253/attachment.html>

author
#3 lore raw

PATCH 1/1 lib: Document the endianity in tst_get_unused_port()

Hi,

Quoted 1 line

Acked.

Thanks, merged!

Kind regards,
Petr