Add test for ioctl(SIOCGIFCONF) and polyfill on BSDs

- Use nullness checks when calling weakly linked functions.

- Avoid typedef for reasons described in Linux Kernel style guide.

- Avoid enum in in Windows headers. Earlier in Cosmo's history all one
  hundred files in libc/nt/enum/ used to be enums and it resulted in
  gigabytes of DWARF data almost as large as everything else in the
  codebase combined.

- Bitfields aren't our friends. They have frequent ABI breakages,
  inconsistent arithmetic across compilers, and different endianness
  between cpus. Compiler authors also haven't invested much roi into
  making bit fields go fast so they produce poor assembly.

- Use memccpy() instead of strncpy() or snprintf() for length-bounded
  copying of C strings. strncpy() is a misunderstood function and
  snprintf() is awesome but memccpy() deserves more love.
This commit is contained in:
Justine Tunney 2021-06-25 18:41:02 -07:00
parent 86ab24ce56
commit 5144c22189
41 changed files with 502 additions and 476 deletions

View file

@ -1497,14 +1497,18 @@ syscon modem TIOCMODG 0 0x40047403 0 0x4004746a 0x4004746a -1 # wut
syscon modem TIOCMODS 0 0x80047404 0 0x8004746d 0x8004746d -1 # wut
syscon modem TIOCMSDTRWAIT 0 0x8004745b 0x8004745b 0 0 -1 # wut
syscon iff IFF_BROADCAST 2 2 2 2 2 2 # consensus
syscon iff IFF_LOOPBACK 8 8 8 8 8 4 # unix consensus
syscon iff IFF_MULTICAST 0x1000 0x8000 0x8000 0x8000 0x8000 0x10 # bsd consensus
syscon iff IFF_ALLMULTI 0x0200 0x0200 0x0200 0x0200 0x0200 0 # unix consensus
syscon iff IFF_DEBUG 4 4 4 4 4 0 # unix consensus
syscon iff IFF_NOARP 0x80 0x80 0x80 0x80 0x80 0 # unix consensus
syscon iff IFF_POINTOPOINT 0x10 0x10 0x10 0x10 0x10 0 # unix consensus
syscon iff IFF_PROIFF 0x0100 0x0100 0x0100 0x0100 0x0100 0 # unix consensus
# ioctl(SIOCGIFFLAGS) Network Interface Flags
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon iff IFF_UP 1 1 1 1 1 1 # unix consensus
syscon iff IFF_BROADCAST 2 2 2 2 2 2 # valid broadcast address set; consensus
syscon iff IFF_DEBUG 4 4 4 4 4 4 # faked nt; consensus
syscon iff IFF_LOOPBACK 8 8 8 8 8 4 # is loopback device; consensus
syscon iff IFF_MULTICAST 0x1000 0x8000 0x8000 0x8000 0x8000 0x1000 # supports multicast; faked nt; bsd consensus
syscon iff IFF_ALLMULTI 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 # receive all multicast packets; faked nt; unix consensus
syscon iff IFF_NOARP 0x80 0x80 0x80 0x80 0x80 0x80 # faked nt as linux; unix consensus
syscon iff IFF_POINTOPOINT 0x10 0x10 0x10 0x10 0x10 0x10 # point-to-point; faked nt as linux; unix consensus
syscon iff IFF_PROMISC 0x100 0x100 0x100 0x100 0x100 0 # in packet capture mode; unix consensus
syscon iff IFF_RUNNING 0x40 0x40 0x40 0x40 0x40 0 # unix consensus
syscon iff IFF_NOTRAILERS 0x20 0x20 0 0 0 0
syscon iff IFF_AUTOMEDIA 0x4000 0 0 0 0 0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_ALLMULTI,0x0200,0x0200,0x0200,0x0200,0x0200,0
.syscon iff,IFF_ALLMULTI,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_DEBUG,4,4,4,4,4,0
.syscon iff,IFF_DEBUG,4,4,4,4,4,4

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_MULTICAST,0x1000,0x8000,0x8000,0x8000,0x8000,0x10
.syscon iff,IFF_MULTICAST,0x1000,0x8000,0x8000,0x8000,0x8000,0x1000

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_NOARP,0x80,0x80,0x80,0x80,0x80,0
.syscon iff,IFF_NOARP,0x80,0x80,0x80,0x80,0x80,0x80

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_POINTOPOINT,0x10,0x10,0x10,0x10,0x10,0
.syscon iff,IFF_POINTOPOINT,0x10,0x10,0x10,0x10,0x10,0x10

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_PROIFF,0x0100,0x0100,0x0100,0x0100,0x0100,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_PROMISC,0x100,0x100,0x100,0x100,0x100,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon iff,IFF_UP,1,1,1,1,1,1

View file

@ -1,26 +1,9 @@
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
#include "libc/runtime/symbolic.h"
#define IFF_ALLMULTI SYMBOLIC(IFF_ALLMULTI)
#define IFF_AUTOMEDIA SYMBOLIC(IFF_AUTOMEDIA)
#define IFF_BROADCAST SYMBOLIC(IFF_BROADCAST)
#define IFF_DEBUG SYMBOLIC(IFF_DEBUG)
#define IFF_DYNAMIC SYMBOLIC(IFF_DYNAMIC)
#define IFF_LOOPBACK SYMBOLIC(IFF_LOOPBACK)
#define IFF_MASTER SYMBOLIC(IFF_MASTER)
#define IFF_MULTICAST SYMBOLIC(IFF_MULTICAST)
#define IFF_NOARP SYMBOLIC(IFF_NOARP)
#define IFF_NOTRAILERS SYMBOLIC(IFF_NOTRAILERS)
#define IFF_POINTOPOINT SYMBOLIC(IFF_POINTOPOINT)
#define IFF_PORTSEL SYMBOLIC(IFF_PORTSEL)
#define IFF_PROMISC SYMBOLIC(IFF_PROMISC)
#define IFF_RUNNING SYMBOLIC(IFF_RUNNING)
#define IFF_SLAVE SYMBOLIC(IFF_SLAVE)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const long IFF_UP;
extern const long IFF_ALLMULTI;
extern const long IFF_AUTOMEDIA;
extern const long IFF_BROADCAST;
@ -39,4 +22,22 @@ extern const long IFF_SLAVE;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define IFF_UP 1
#define IFF_BROADCAST 2
#define IFF_DEBUG 4
#define IFF_LOOPBACK 8
#define IFF_ALLMULTI IFF_ALLMULTI
#define IFF_AUTOMEDIA IFF_AUTOMEDIA
#define IFF_DYNAMIC IFF_DYNAMIC
#define IFF_MASTER IFF_MASTER
#define IFF_MULTICAST IFF_MULTICAST
#define IFF_NOARP IFF_NOARP
#define IFF_NOTRAILERS IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL IFF_PORTSEL
#define IFF_PROMISC IFF_PROMISC
#define IFF_RUNNING IFF_RUNNING
#define IFF_SLAVE IFF_SLAVE
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_ */