C++之动态配置ip信息

本文主要探讨如何在C++中实现动态配置IP地址的功能,通过`configManager.h`头文件的使用,讲解配置网络接口的关键步骤和技巧。
摘要由CSDN通过智能技术生成

## configManager.h

#ifndef CONFIGACMUCONTROLLER_H
#define CONFIGACMUCONTROLLER_H

#include <string>
using namespace  std;

class ConfigACMUController
{
public:
    static ConfigACMUController * getInstance();
    inline void setIsSetting(bool flag)
    {
        m_isSetting = flag;
    }
    inline bool isSetting()
    {
        return m_isSetting;
    }
    inline string getAcmuIP()
    {
        return m_acmu_ip;
    }
    inline string getExtIfIP()
    {
        return m_extif_ip;
    }
    void startConfig(string acmu_ip,string extif_ip);
    static void * OnConfigAcmuThread(void * p);
    void onReportStatus(int state,string content);
private:
    ConfigACMUController();
    bool m_isSetting;
    pthread_t m_config_tid;
    string m_acmu_ip;
    string m_extif_ip;
};

#endif // CONFIGACMUCONTROLLER_H

## configManager.cpp

#include "configacmucontroller.h"
#include <unistd.h>
#include "ping_dev.h"
#include <string>
#include <iostream>
#include <stdarg.h>
#include "csettings.h"
using namespace std;

/**************************************************************************************************
*   This Api is Used to Format String for C++.
***************************************************************************************************/
string formatString(const char* fmt, ...)
{
        va_list args;
        static char buffer[1024];
        va_start(args, fmt);
        vsnprintf((char *) buffer, 1024, (char *) fmt, args);
        va_end(args);
        return string(buffer);
}

static ConfigACMUController * gInstance = NULL;

/**************************************************************************************************
*   This Api is Used to run the command by
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值