From owner-freebsd-net@freebsd.org Tue Feb 9 21:58:03 2016 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 85D04AA230E for ; Tue, 9 Feb 2016 21:58:03 +0000 (UTC) (envelope-from jb@jboy.eu) Received: from gacrux.uberspace.de (gacrux.uberspace.de [185.26.156.53]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0CA4415A1 for ; Tue, 9 Feb 2016 21:58:02 +0000 (UTC) (envelope-from jb@jboy.eu) Received: (qmail 9360 invoked from network); 9 Feb 2016 21:51:16 -0000 Received: from localhost (HELO jb-mbp.fritz.box) (127.0.0.1) by gacrux.uberspace.de with SMTP; 9 Feb 2016 21:51:16 -0000 From: Jeremy Boy Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: ifconfig with quoted arguments Date: Tue, 9 Feb 2016 22:51:14 +0100 Message-Id: <76A08658-ACD2-426B-865A-45A6A79BBFB4@jboy.eu> Cc: Jeremy Boy To: freebsd-net@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) X-Mailer: Apple Mail (2.3112) X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Feb 2016 21:58:03 -0000 Hello list, please CC me in replies to this mail, since I am no subscriber to this = list. For safety reasons, we enclose user input to shell commands in quotes. = Until today, the resulting command for ifconfig(8) looked like this: > ifconfig ue0 inet "192.168.2.176 netmask 255.255.255.0" As we figured out, this means that ifconfig sometimes doesn't set the = netmask as we expect it to do: > root@csbuild:~ # ifconfig ue0 > ue0: flags=3D8843 metric 0 mtu = 1500 > options=3D80001 > ether b8:27:eb:fd:58:69 > inet 192.168.2.176 netmask 0xffff0000 broadcast = 192.168.255.255=20 > media: Ethernet autoselect (100baseTX ) > status: active > nd6 options=3D29 > root@csbuild:~ # ifconfig ue0 inet "192.168.2.176 netmask 255.0.0.0" > root@csbuild:~ # echo $? > 0 > root@csbuild:~ # ifconfig ue0 > ue0: flags=3D8843 metric 0 mtu = 1500 > options=3D80001 > ether b8:27:eb:fd:58:69 > inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255=20= > media: Ethernet autoselect (100baseTX ) > status: active > nd6 options=3D29 > root@csbuild:~ #=20 As you can see, ifconfig sets the netmask to 255.255.255.0, ignoring the = netmask we provided. If provided with a 10.* address, ifconfig sets the = netmask to 255.0.0.0, no matter what actual netmask we entered. Also, it = doesn't exit with a status indicating error, which made it a little = harder to debug this issue. The following works as expected: > root@csbuild:~ # ifconfig ue0 > ue0: flags=3D8843 metric 0 mtu = 1500 > options=3D80001 > ether b8:27:eb:fd:58:69 > inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255=20= > media: Ethernet autoselect (100baseTX ) > status: active > nd6 options=3D29 > root@csbuild:~ # ifconfig ue0 inet "192.168.2.176" netmask "255.0.0.0" > root@csbuild:~ # ifconfig ue0 > ue0: flags=3D8843 metric 0 mtu = 1500 > options=3D80001 > ether b8:27:eb:fd:58:69 > inet 192.168.2.176 netmask 0xff000000 broadcast = 192.255.255.255=20 > media: Ethernet autoselect (100baseTX ) > status: active > nd6 options=3D29 > root@csbuild:~ #=20 What exactly does ifconfig do? It seems to me that it reads the IP = address from the quoted string but truncates the netmask. Is this a bug = in ifconfig or intended behavior? Best wishes Jeremy=