#pragma once
#include <iostream>
#include <vector>
#include <list>
#include <mutex>

#define IPV4_CHAR_LENGTH	22
#define MAC_CHAR_LENGTH		18
#define NAME_MAXPATH		256

/// 网络信息
typedef struct
{
	unsigned int	nAdapterIndex;
	char			szNetCardName[NAME_MAXPATH];		//<
	unsigned char	byLocalIP[4];
	unsigned char	byMacAddress[6];
	unsigned char	bySubMask[4];
	unsigned char	byGetWay[4];
    unsigned char   byBroadCastIP[4];
} SVrCardInfo;

std::ostream& operator<<(std::ostream& os, const SVrCardInfo& sAction);

namespace CVrNetUtils
{
	/// 获取所有设备
    bool QueryAllNetworkInfo(std::list<SVrCardInfo>& lstNetCardInfo);

	/// ip是否有效
    bool IsValidIP(const char szIPv4[IPV4_CHAR_LENGTH]);

    bool SetAddrMaskGateWay(const char *ifname, const char *Ipaddr, const char *mask, const char *gateway);

	/// 设置IP
    bool SetIPv4Address(const char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 获取IP
    bool GetIPv4Address(char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 设置网关；
    bool SetIPv4NetMask(const char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 获取子网掩码
    bool GetIPv4NetMask(char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 获取广播地址
    bool GetIPv4BroadIP(char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 获取网卡地址
    bool GetLocalMAC(char byMac[MAC_CHAR_LENGTH], const char *devName);

	/// 设置网关
    bool SetGateWay(const char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 获取网关
    bool GetGateWay(char ip[IPV4_CHAR_LENGTH], const char *devName);

	/// 将IP字符串转为Byte
    bool IPString2Byte(const char* szIP, unsigned char byIP[4]);

	/// 将IP的Byte转为字符串
    void IPByte2String(const unsigned char byIP[4], char szIP[IPV4_CHAR_LENGTH]);

	/// 计算广播地址
    void CalcBroadCastIP(unsigned char byIP[4], unsigned char byMask[4], unsigned char byBroadCast[4]);

}
