On Wed, Jun 14, 2017 at 05:37:07PM +0200, Klemens Nanni wrote:
> With this patch, v[46]_info() both output exactly what their description
> says.
> 
> As of now, these functions are only used through
>       set -- $(v4_info $_if)
> which gracefully handles any constellation of whitespaces in the output
> just fine. However future usage might change (or not) and being precise
> about a function's output doesn't hurt.
> 
> The sed command itself is a tad clearer/smarter that way as well, imho.
> 
> Here's what I mean (whitespaces visualised):
> 
>       $ v4_info trunk0
>       UP
>       ???     ??192.168.1.2????0xffffff00??broadcast??192.168.1.255
>       $ v4_info_clean trunk0
>       UP
>       192.168.1.2??0xffffff00??broadcast??192.168.1.255
> 
> 
> Feeback/OK?
> 
> Index: install.sub
> ===================================================================
> RCS file: /cvs/src/distrib/miniroot/install.sub,v
> retrieving revision 1.1014
> diff -u -p -r1.1014 install.sub
> --- install.sub       3 Jun 2017 22:27:41 -0000       1.1014
> +++ install.sub       14 Jun 2017 15:13:05 -0000
> @@ -896,13 +896,14 @@ __EOT
> }
> 
> # Obtain and output the inet information related to interface $1.
> -# Should output '<UP/DOWN> <addr> <netmask> <rest of inet line>'.
> +# Outputs '<UP/DOWN>\n<addr> <netmask> <rest of inet line>'.
> v4_info() {
>       ifconfig $1 inet | sed -n '
> -             1s/.*<UP,.*/UP/p
> -             1s/.*<.*/DOWN/p
> -             /inet/s/netmask//
> -             /inet/s///p'
> +             1{      s/.*<UP,.*/UP/p
> +                     s/.*<.*/DOWN/p; }
> +             /inet/{ s///
> +                     s/^[[:space:]]*//
> +                     s/netmask //p; }'
> }
> 
> # Convert a netmask in hex format ($1) to dotted decimal format.
> @@ -981,14 +982,15 @@ v4_config() {
> }
> 
> # Obtain and output the inet6 information related to interface $1.
> -# Should output '<UP/DOWN> <addr> <prefixlen> <rest of inet line> '.
> +# Outputs '<UP/DOWN>\n<addr> <prefixlen> <rest of inet6 line>'.
> v6_info() {
>       ifconfig $1 inet6 | sed -n '
> -             1s/.*<UP,.*/UP/p
> -             1s/.*<.*/DOWN/p
> -             /scopeid/d
> -             /inet6/s/prefixlen//
> -             /inet6/s///p'
> +             1{      s/.*<UP,.*/UP/p
> +                     s/.*<.*/DOWN/p; }
> +             /inet6/{s///
> +                     /scopeid/d
> +                     s/^[[:space:]]*//
> +                     s/prefixlen //p; }'
> }
> 
> # Set up IPv6 default route on interface $1.

Dokument explicitely possible outputs and tweak the sed expressions
to remove the superfluous whitespaces. I guess that does the trick.

Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1019
diff -u -p -p -u -r1.1019 install.sub
--- install.sub 2 Jul 2017 12:45:43 -0000       1.1019
+++ install.sub 3 Jul 2017 22:34:04 -0000
@@ -896,13 +896,16 @@ __EOT
 }
 
 # Obtain and output the inet information related to interface $1.
-# Should output '<UP/DOWN> <addr> <netmask> <rest of inet line>'.
+# Outputs one of:
+# <DOWN>
+# <UP>
+# <UP>\n<addr> <netmask> <rest of inet line>[\n<more addr lines>]
 v4_info() {
        ifconfig $1 inet | sed -n '
                1s/.*<UP,.*/UP/p
                1s/.*<.*/DOWN/p
-               /inet/s/netmask//
-               /inet/s///p'
+               /inet/s/netmask //
+               /.inet /s///p'
 }
 
 # Convert a netmask in hex format ($1) to dotted decimal format.
@@ -981,14 +984,17 @@ v4_config() {
 }
 
 # Obtain and output the inet6 information related to interface $1.
-# Should output '<UP/DOWN> <addr> <prefixlen> <rest of inet line> '.
+# Outputs one of:
+# <DOWN>
+# <UP>
+# <UP>\n<addr> <prefixlen> <rest of inet6 line>[\n<more addr lines>]
 v6_info() {
        ifconfig $1 inet6 | sed -n '
                1s/.*<UP,.*/UP/p
                1s/.*<.*/DOWN/p
                /scopeid/d
-               /inet6/s/prefixlen//
-               /inet6/s///p'
+               /inet6/s/prefixlen //
+               /.inet6 /s///p'
 }
 
 # Set up IPv6 default route on interface $1.
===================================================================
Stats: --- 6 lines 209 chars
Stats: +++ 12 lines 283 chars
Stats: 6 lines
Stats: 74 chars

-- 
-=[rpe]=-

Reply via email to