<div dir="ltr"><div>From 8b0c44c17d17ea3a9710ae7586579c288289a46e Mon Sep 17 00:00:00 2001</div><div>From: JingPiao Chen <<a href="mailto:chenjingpiao@gmail.com">chenjingpiao@gmail.com</a>></div><div>Date: Mon, 19 Dec 2016 23:29:54 +0800</div><div>Subject: [PATCH 2/2] tests: check decoding of SIOC* ioctls</div><div><br></div><div>* tests/ioctl_sock.c: New file.</div><div>* tests/ioctl_sock.test: New test.</div><div>* tests/.gitignore: Add ioctl_sock.</div><div>* tests/Makefile.am (check_PROGRAMS): Likewise.</div><div>(DECODER_TESTS): Add ioctl_sock.test.</div><div>---</div><div> tests/.gitignore      |   1 +</div><div> tests/Makefile.am     |   2 +</div><div> tests/ioctl_sock.c    | 289 ++++++++++++++++++++++++++++++++++++++++++++++++++</div><div> tests/ioctl_sock.test |  12 +++</div><div> 4 files changed, 304 insertions(+)</div><div> create mode 100644 tests/ioctl_sock.c</div><div> create mode 100755 tests/ioctl_sock.test</div><div><br></div><div>diff --git a/tests/.gitignore b/tests/.gitignore</div><div>index 92b1120..01de0d5 100644</div><div>--- a/tests/.gitignore</div><div>+++ b/tests/.gitignore</div><div>@@ -120,6 +120,7 @@ ioctl_evdev-v</div><div> ioctl_mtd</div><div> ioctl_rtc</div><div> ioctl_rtc-v</div><div>+ioctl_sock</div><div> ioctl_uffdio</div><div> ioctl_v4l2</div><div> ioperm</div><div>diff --git a/tests/Makefile.am b/tests/Makefile.am</div><div>index 488bfb8..6bfe4b3 100644</div><div>--- a/tests/Makefile.am</div><div>+++ b/tests/Makefile.am</div><div>@@ -182,6 +182,7 @@ check_PROGRAMS = \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl_mtd \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>ioctl_rtc \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>ioctl_rtc-v \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl_sock \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl_uffdio \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl_v4l2 \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioperm \</div><div>@@ -571,6 +572,7 @@ DECODER_TESTS = \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl_mtd.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>ioctl_rtc.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>ioctl_rtc-v.test \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>ioctl_sock.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>ioctl_uffdio.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>ioctl_v4l2.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>ioperm.test \</div><div>diff --git a/tests/ioctl_sock.c b/tests/ioctl_sock.c</div><div>new file mode 100644</div><div>index 0000000..87e721e</div><div>--- /dev/null</div><div>+++ b/tests/ioctl_sock.c</div><div>@@ -0,0 +1,289 @@</div><div>+/*</div><div>+ * This file is part of ioctl_sock strace test.</div><div>+ *</div><div>+ * Copyright (c) 2016 JingPiao Chen <<a href="mailto:chenjingpiao@gmail.com">chenjingpiao@gmail.com</a>></div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ * 3. The name of the author may not be used to endorse or promote products</div><div>+ *    derived from this software without specific prior written permission.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR</div><div>+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</div><div>+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</div><div>+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,</div><div>+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT</div><div>+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</div><div>+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</div><div>+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</div><div>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</div><div>+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div><div>+ */</div><div>+</div><div>+#include "tests.h"</div><div>+#include <stdio.h></div><div>+#include <string.h></div><div>+#include <sys/ioctl.h></div><div>+#include <linux/sockios.h></div><div>+#include <arpa/inet.h></div><div>+#include <net/if.h></div><div>+</div><div>+#define TEST_STRUCT_IFREQ_ARG_READ(cmd, addr) \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl(-1, cmd, addr); \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>printf("ioctl(-1, %s, {ifr_name=\"%.*s\"}) = -1 EBADF (%m)\n", \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>#cmd, (int) sizeof(addr->ifr_name), \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>addr->ifr_name)</div><div>+</div><div>+#define TEST_STRUCT_IFREQ_ARG_WRITE(cmd, addr) \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>init_ifreq(cmd, addr); \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>ioctl(-1, cmd, addr); \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>printf("ioctl(-1, %s, {ifr_name=\"%.*s\", ", #cmd, \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>(int) sizeof(addr->ifr_name), addr->ifr_name); \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>print_ifreq(cmd, ifr); \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>printf("}) = -1 EBADF (%m)\n")</div><div>+</div><div>+static const unsigned int magic = 0xdeadbeef;</div><div>+</div><div>+static void</div><div>+init_magic(void *addr, const unsigned int size)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>unsigned int *p = addr;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>const unsigned int *end = addr + size - sizeof(int);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>for (; p <= end; ++p)</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>*(unsigned int *) p = magic;</div><div>+}</div><div>+</div><div>+static void</div><div>+init_sockaddr(void *addr)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>struct sockaddr_in *sin;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>sin = (struct sockaddr_in *) addr;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>sin->sin_family = AF_INET;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sin->sin_addr.s_addr = inet_addr("0.0.0.0");</div><div>+}</div><div>+</div><div>+static void</div><div>+print_sockaddr(void *addr, const char *str)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>struct sockaddr_in *sin = (struct sockaddr_in *) addr;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>printf("%s={sa_family=AF_INET, sin_port=htons(%u), "</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>"sin_addr=inet_addr(\"0.0.0.0\")}",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>str, sin->sin_port);</div><div>+}</div><div>+</div><div>+static void</div><div>+init_ifreq(const unsigned int code, struct ifreq *ifr)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>switch (code) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>case SIOCSIFADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>init_sockaddr((void *) &ifr->ifr_addr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFDSTADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>init_sockaddr((void *) &ifr->ifr_dstaddr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFBRDADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>init_sockaddr((void *) &ifr->ifr_broadaddr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFNETMASK:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>init_sockaddr((void *) &ifr->ifr_netmask);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFFLAGS:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>ifr->ifr_flags = IFF_UP;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMETRIC:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>ifr->ifr_metric = magic;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMTU:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>ifr->ifr_mtu = magic;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFSLAVE:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>memset(ifr->ifr_slave, 'B', sizeof(ifr->ifr_slave));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFHWADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>init_magic(&ifr->ifr_hwaddr.sa_data,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                           </span>sizeof(ifr->ifr_hwaddr.sa_data));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFTXQLEN:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>ifr->ifr_qlen = magic;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMAP:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>init_magic(&ifr->ifr_map, sizeof(ifr->ifr_map));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>break;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>}</div><div>+}</div><div>+</div><div>+static void</div><div>+print_ifreq(const unsigned int code, const struct ifreq *ifr)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>switch (code) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>case SIOCSIFADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>print_sockaddr((void *) &ifr->ifr_addr, "ifr_addr");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFDSTADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>print_sockaddr((void *) &ifr->ifr_dstaddr, "ifr_dstaddr");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFBRDADDR:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>print_sockaddr((void *) &ifr->ifr_broadaddr, "ifr_broadaddr");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">               </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFNETMASK:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>print_sockaddr((void *) &ifr->ifr_netmask, "ifr_netmask");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFFLAGS:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>printf("ifr_flags=IFF_UP");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMETRIC:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>printf("ifr_metric=%d", ifr->ifr_metric);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMTU:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>printf("ifr_mtu=%d", ifr->ifr_mtu);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFSLAVE:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>printf("ifr_slave=\"%.*s\"", (int) sizeof(ifr->ifr_slave),</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                             </span>ifr->ifr_slave);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFHWADDR: {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>const unsigned char *bytes =</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>(unsigned char *) &ifr->ifr_hwaddr.sa_data;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>printf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>bytes[0], bytes[1], bytes[2],</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                 </span>bytes[3], bytes[4], bytes[5]);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>break;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>} </div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>case SIOCSIFTXQLEN:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>printf("ifr_qlen=%d", ifr->ifr_qlen);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>break;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>case SIOCSIFMAP:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>printf("ifr_map={mem_start=%#lx, "</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>"mem_end=%#lx, base_addr=%#x, "</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>"irq=%u, dma=%u, port=%u}",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                 </span>ifr->ifr_map.mem_start,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                    </span>ifr->ifr_map.mem_end,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>(unsigned) ifr->ifr_map.base_addr,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                 </span>(unsigned) ifr->ifr_map.irq,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>(unsigned) ifr->ifr_map.dma,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>(unsigned) ifr->ifr_map.port);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>break;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>}</div><div>+}</div><div>+</div><div>+int</div><div>+main(void)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>char brname[] = "eth0";</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>struct ifconf *const ifc = tail_alloc(sizeof(*ifc));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>struct ifreq *const ifr = tail_alloc(sizeof(*ifr));;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>init_magic(ifr, sizeof(*ifr));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>init_magic(ifc, sizeof(*ifc));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>memset(ifr->ifr_name, 'A', sizeof(ifr->ifr_name));</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>ioctl(-1, SIOCGIFCONF, ifc);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>printf("ioctl(-1, SIOCGIFCONF, {%d}) = -1 EBADF (%m)\n", ifc->ifc_len);</div><div>+</div><div>+#ifdef SIOCBRADDBR</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, SIOCBRADDBR, brname);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>printf("ioctl(-1, SIOCBRADDBR, \"eth0\") = -1 EBADF (%m)\n");</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>ioctl(-1, SIOCBRDELBR, brname);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>printf("ioctl(-1, SIOCBRDELBR, \"eth0\") = -1 EBADF (%m)\n");</div><div>+#endif</div><div>+</div><div>+#ifdef FIOSETOWN</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl(-1, FIOSETOWN, &magic);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, FIOSETOWN, [%d]) = -1 EBADF (%m)\n", magic);</div><div>+#endif</div><div>+#ifdef SIOCSPGRP</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, SIOCSPGRP, &magic);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, SIOCSPGRP, [%d]) = -1 EBADF (%m)\n", magic);</div><div>+#endif</div><div>+#ifdef FIOGETOWN</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, FIOGETOWN, &magic);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, FIOGETOWN, %#llx) = -1 EBADF (%m)\n",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>(long long) &magic);</div><div>+#endif</div><div>+#ifdef SIOCGPGRP</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, SIOCGPGRP, &magic);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, SIOCGPGRP, %#llx) = -1 EBADF (%m)\n",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>(long long) &magic);</div><div>+#endif</div><div>+#ifdef SIOCATMARK</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl(-1, SIOCATMARK, &magic);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>printf("ioctl(-1, SIOCATMARK, %#llx) = -1 EBADF (%m)\n",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                    </span>(long long) &magic);</div><div>+#endif</div><div>+#ifdef SIOCBRADDIF</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>ioctl(-1, SIOCBRADDIF, 0);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>printf("ioctl(-1, SIOCBRADDIF) = -1 EBADF (%m)\n");</div><div>+#endif</div><div>+#ifdef SIOCBRDELIF</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl(-1, SIOCBRDELIF, 0);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>printf("ioctl(-1, SIOCBRDELIF) = -1 EBADF (%m)\n"); </div><div>+#endif</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>memset(ifr->ifr_newname, 'B', sizeof(ifr->ifr_newname));</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, SIOCSIFNAME, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>printf("ioctl(-1, SIOCSIFNAME, {ifr_name=\"%.*s\", ifr_newname=\"%.*s\"})"</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>       " = -1 EBADF (%m)\n", (int) sizeof(ifr->ifr_name), ifr->ifr_name,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>       (int) sizeof(ifr->ifr_newname), ifr->ifr_newname);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFDSTADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFBRDADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFNETMASK, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFFLAGS, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFMETRIC, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFMTU, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFSLAVE, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFHWADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFTXQLEN, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_WRITE(SIOCSIFMAP, ifr);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl(-1, SIOCGIFNAME, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>printf("ioctl(-1, SIOCGIFNAME, {ifr_index=%d}) = -1 EBADF (%m)\n",</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>ifr->ifr_ifindex);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFINDEX, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFDSTADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFBRDADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFNETMASK, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFFLAGS, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFMETRIC, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFMTU, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFSLAVE, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFHWADDR, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFTXQLEN, ifr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>TEST_STRUCT_IFREQ_ARG_READ(SIOCGIFMAP, ifr);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>puts("+++ exited with 0 +++");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>return 0;</div><div>+}</div><div>diff --git a/tests/ioctl_sock.test b/tests/ioctl_sock.test</div><div>new file mode 100755</div><div>index 0000000..b915d1f</div><div>--- /dev/null</div><div>+++ b/tests/ioctl_sock.test</div><div>@@ -0,0 +1,12 @@</div><div>+#!/bin/sh</div><div>+</div><div>+# Check decoding of SIOC* ioctls.</div><div>+</div><div>+. "${srcdir=.}/init.sh"</div><div>+</div><div>+run_prog > /dev/null</div><div>+run_strace -a22 -s9 -eioctl $args > "$EXP"</div><div>+check_prog grep</div><div>+grep -v '^ioctl([012],' < "$LOG" > "$OUT"</div><div>+match_diff "$OUT" "$EXP"</div><div>+rm -f "$EXP" "$OUT"</div><div>-- </div><div>2.7.4</div><div><br></div></div>