[1/1] lib: Document the endianity in tst_get_unused_port()
diff mbox series

Message ID 20190607071751.9225-1-pvorel@suse.cz
State Accepted
Delegated to: Petr Vorel
Headers show
Series
  • [1/1] lib: Document the endianity in tst_get_unused_port()
Related show

Commit Message

Petr Vorel June 7, 2019, 7:17 a.m. UTC
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

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/safe_net.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Christian Amann June 7, 2019, 7:34 a.m. UTC | #1
Hi!

That should make things more clear, thanks!

Reviewed-by: Christian Amann <camann@suse.com>

On 07/06/2019 09:17, Petr Vorel wrote:
> 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
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  lib/safe_net.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/safe_net.c b/lib/safe_net.c
> index 970a2aba3..abebd1899 100644
> --- a/lib/safe_net.c
> +++ b/lib/safe_net.c
> @@ -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)
>  {
Cyril Hrubis June 7, 2019, 11:36 a.m. UTC | #2
Hi!
Acked.
Petr Vorel June 7, 2019, 12:46 p.m. UTC | #3
Hi,

> Acked.
Thanks, merged!

Kind regards,
Petr

Patch
diff mbox series

diff --git a/lib/safe_net.c b/lib/safe_net.c
index 970a2aba3..abebd1899 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -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)
 {