123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- // interfaces.h :
- //
- /////////////////////////////////////////////////////////////////////////////
- //
- // https://manpages.debian.org/stretch/ifupdown/interfaces.5.en.html
- // https://wiki.debian.org/NetworkConfiguration
- // https://wiki.ubuntuusers.de/interfaces/
- //
- /////////////////////////////////////////////////////////////////////////////
- #if !defined(AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_)
- #define AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <linux/if_packet.h>
- #include <linux/if_arp.h>
- #include <vector>
- #include <list>
- #include <string>
- #include "inet4s.h"
- #include "inet4d.h"
- #include "inet4m.h"
- /////////////////////////////////////////////////////////////////////////////
- // interfaces.h - Declarations:
- typedef struct _ITF_CONFIG_GROUP
- {
- _ITF_CONFIG_GROUP(){_reset();}
- void _reset(void)
- {
- cfgName.clear();
- members.clear();
- }
- std::string cfgName;
- std::vector<std::string> members;
- }ITF_CONFIG_GROUP, *LPITF_CONFIG_GROUP;
- typedef const ITF_CONFIG_GROUP *LPCITF_CONFIG_GROUP;
- typedef std::list<ITF_CONFIG_GROUP> ITF_CONFIG_GROUP_LIST;
- typedef enum CfgGroup
- {
- CG_Unknown = -1,
- CG_Auto,
- CG_AllowAuto,
- CG_AllowHotplug,
- CG_NoAutoDown,
- DG_NoScripts,
- CG_User
- }CfgGroup;
- CfgGroup ParseCfgGroup(const std::vector<std::string> &v, ITF_CONFIG_GROUP &icg);
- /////////////////////////////////////////////////////////////////////////////
- typedef enum IfaceProtos
- {
- IFP_Unknown = -1,
- IFP_Inet,
- IFP_Inet6,
- IFP_Ipx,
- IFP_Can
- }IfaceProtos;
- IfaceProtos GetIfaceProto(const std::string &s);
- const char *GetIfaceProtoStr(IfaceProtos ip);
- /////////////////////////////////////////////////////////////////////////////
- typedef enum IfaceMethods
- {
- IFM_Unknown = -1,
- IFM_Static,
- IFM_Dhcp,
- IFM_Manual,
- IFM_BootP,
- IFM_Tunnel,
- IFM_Ppp,
- IFM_WvDial,
- IFM_IpV4ll,
- IFM_Loopback,
- IFM_Auto
- }IfaceMethods;
- IfaceMethods GetIfaceMethod(const std::string &s);
- const char *GetIfaceMethodStr(IfaceMethods im);
- /////////////////////////////////////////////////////////////////////////////
- typedef enum IfaceCommands
- {
- IFC_Unknown = -1,
- IFC_PreUp,
- IFC_Up,
- IFC_PostUp,
- IFC_Down,
- IFC_PreDown,
- IFC_PostDown
- }IfaceCommands;
- typedef struct _IFACE_COMMAND
- {
- IfaceCommands cmd;
- std::string args;
- }IFACE_COMMAND, *LPIFACE_COMMAND;
- typedef const IFACE_COMMAND *LPCIFACE_COMMAND;
- IfaceCommands GetIfaceCommand(const std::string &s);
- const char *GetIfaceCommandsStr(IfaceCommands ic);
- bool ParseIfaceCmd(const std::vector<std::string> &v, std::vector<IFACE_COMMAND> &c);
- /////////////////////////////////////////////////////////////////////////////
- typedef enum ItfInclude
- {
- II_None = -1,
- II_File,
- II_Directory
- }ItfInclude;
- typedef struct _ITF_INCLUDE
- {
- ItfInclude inc;
- std::string path;
- }ITF_INCLUDE, *LPITF_INCLUDE;
- typedef const ITF_INCLUDE *LPCITF_INCLUDE;
- typedef std::list<ITF_INCLUDE> ITF_INCLUDE_LIST;
- bool ParseIncludes(const std::vector<std::string> &v, ITF_INCLUDE_LIST &inc);
- const char *GetIncTypeStr(ItfInclude inc);
- /////////////////////////////////////////////////////////////////////////////
- typedef struct _ITF_IFACE_BLOCK
- {
- _ITF_IFACE_BLOCK(){_reset();}
- void _reset(void)
- {
- cfgName.clear();
- proto = IFP_Unknown;
- method = IFM_Unknown;
- inheritedFrom.clear();
- desc.clear();
- cmds.clear();
- memberOf.clear();
- unparsed.clear();
- inet4s._reset();
- inet4d._reset();
- inet4m._reset();
- }
- std::string cfgName;
- IfaceProtos proto;
- IfaceMethods method;
- std::string inheritedFrom;
- std::string desc;
- std::vector<IFACE_COMMAND> cmds;
- std::vector<LPITF_CONFIG_GROUP> memberOf;
- std::vector<std::string> unparsed;
- IFACE_INET_STATIC inet4s;
- IFACE_INET_DHCP inet4d;
- IFACE_INET_MANUAL inet4m;
- }ITF_IFACE_BLOCK, *LPITF_IFACE_BLOCK;
- typedef const ITF_IFACE_BLOCK *LPCITF_IFACE_BLOCK;
- //typedef std::vector<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
- typedef std::list<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
- typedef enum IfaceHdrType
- {
- IHR_NoHdr,
- IHR_Invalid,
- IHR_Unknown,
- IHR_OK
- }IfaceHdrType;
- IfaceHdrType ParseIfaceHeader(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
- bool ParseIfaceParam(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
- bool ParseIfaceDesc(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
- /////////////////////////////////////////////////////////////////////////////
- typedef struct _ITF_MAPPING_BLOCK
- {
- _ITF_MAPPING_BLOCK(){_reset();}
- void _reset(void)
- {
- unparsed.clear();
- }
- std::vector<std::string> unparsed;
- }ITF_MAPPING_BLOCK, *LPITF_MAPPING_BLOCK;
- typedef const ITF_MAPPING_BLOCK *LPCITF_MAPPING_BLOCK;
- typedef std::list<ITF_MAPPING_BLOCK> ITF_MAPPING_BLOCK_LIST;
- bool ParseMapping(const std::vector<std::string> &v, ITF_MAPPING_BLOCK &mab);
- /////////////////////////////////////////////////////////////////////////////
- typedef struct _ETC_NETWORK_INTERFACES
- {
- _ETC_NETWORK_INTERFACES(void){_reset();}
- void _reset(void)
- {
- mbl.clear();
- cgl.clear();
- ibl.clear();
- inc.clear();
- unparsed.clear();
- }
- ITF_MAPPING_BLOCK_LIST mbl;
- ITF_CONFIG_GROUP_LIST cgl;
- ITF_IFACE_BLOCK_LIST ibl;
- ITF_INCLUDE_LIST inc;
- std::vector<std::string> unparsed;
- }ETC_NETWORK_INTERFACES, *LPETC_NETWORK_INTERFACES;
- typedef const ETC_NETWORK_INTERFACES *LPCETC_NETWORK_INTERFACES;
- void ProcessIface(ETC_NETWORK_INTERFACES &eni);
- void ProcessGroupMembers(ETC_NETWORK_INTERFACES &eni);
- bool ParseEtcNetworkInterfaces(ETC_NETWORK_INTERFACES &eni, const char *pszPath = NULL);
- bool WriteEtcNetworkInterfaces(const ETC_NETWORK_INTERFACES &eni, const char *pszPath = NULL);
- /////////////////////////////////////////////////////////////////////////////
- #endif // !defined(AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_)
|