aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

net.h (2881B)


      1 #ifndef NET_H
      2 #define NET_H
      3 
      4 #include <netinet/in.h>
      5 #include <stddef.h>
      6 #include <sys/types.h>
      7 
      8 #define NET_IFNAME_MAX       16
      9 #define NET_ROUTE_ADDRSTRLEN 16
     10 
     11 enum NetInterfaceFlag {
     12   NET_IF_UP          = 0x00000001,
     13   NET_IF_BROADCAST   = 0x00000002,
     14   NET_IF_DEBUG       = 0x00000004,
     15   NET_IF_LOOPBACK    = 0x00000008,
     16   NET_IF_POINTOPOINT = 0x00000010,
     17   NET_IF_RUNNING     = 0x00000020,
     18   NET_IF_NOARP       = 0x00000040,
     19   NET_IF_PROMISC     = 0x00000080,
     20   NET_IF_ALLMULTI    = 0x00000100,
     21   NET_IF_MULTICAST   = 0x00000200,
     22   // no device behind it (a bridge, a tunnel); unknown is not virtual
     23   NET_IF_VIRTUAL = 0x00000400,
     24   // a radio; unknown is not wireless
     25   NET_IF_WIRELESS = 0x00000800,
     26 };
     27 
     28 struct NetStats {
     29   unsigned long long rx_bytes;
     30   unsigned long long rx_packets;
     31   unsigned long long rx_errs;
     32   unsigned long long rx_drop;
     33   unsigned long long tx_bytes;
     34   unsigned long long tx_packets;
     35   unsigned long long tx_errs;
     36   unsigned long long tx_drop;
     37 };
     38 
     39 struct NetInterface {
     40   char                name[NET_IFNAME_MAX];
     41   unsigned int        flags;
     42   int                 mtu;
     43   int                 metric;
     44   unsigned char       mac[6];
     45   int                 has_mac;
     46   struct sockaddr_in  ipv4_addr;
     47   int                 has_ipv4;
     48   struct sockaddr_in  ipv4_mask;
     49   struct sockaddr_in  ipv4_brd;
     50   struct sockaddr_in6 ipv6_addr;
     51   int                 has_ipv6;
     52   unsigned int        ipv6_scope;
     53   unsigned int        ipv6_prefix;
     54 };
     55 
     56 struct NetRoute {
     57   char           interface[NET_IFNAME_MAX];
     58   struct in_addr destination;
     59   struct in_addr gateway;
     60   struct in_addr mask;
     61   unsigned int   flags;
     62   unsigned int   metric;
     63 };
     64 
     65 int net_get_interfaces(struct NetInterface **, int *);
     66 int net_get_routes(struct NetRoute **, int *);
     67 int net_show_routes(void);
     68 int net_get_stats(const char *, struct NetStats *);
     69 int net_set_flags(const char *, unsigned int, int);
     70 int net_set_mtu(const char *, int);
     71 int net_set_metric(const char *, int);
     72 int net_set_mac(const char *, const unsigned char *);
     73 int net_set_mask(const char *, const char *);
     74 int net_set_broadcast(const char *, const char *);
     75 int net_set_dstaddr(const char *, const char *);
     76 int net_add_addr(const char *, const char *, int);
     77 int net_del_addr(const char *, const char *, int);
     78 int net_add_route(const char *, const char *, const char *, int, int);
     79 int net_del_route(const char *, const char *, const char *, int, int);
     80 int net_flush_addrs(const char *);
     81 int net_set_txqueuelen(const char *, int);
     82 int net_set_name(const char *, const char *);
     83 int net_tun_open(void);
     84 int net_tun_attach(int, char *, size_t, int);
     85 int net_tun_persist(int, int);
     86 int net_tun_owner(int, uid_t);
     87 int net_bind_device(int, const char *);
     88 int net_get_hwaddr(int, const char *, unsigned char *, size_t);
     89 int
     90 net_set_lease(const char *, const unsigned char[4], const unsigned char[4], const unsigned char[4]);
     91 
     92 #endif