C语言获取本地所有网卡的ip地址及MAC信息

这是一个在Ubuntu和CentOS系统上成功运行的C语言程序,用于获取本地所有网卡的IP地址和MAC信息。编译后,程序能够提供所需网络配置详情。
摘要由CSDN通过智能技术生成

  本程序在ubuntu下运行成功,后再centos系统下也能编译成功并运行。源代码如下
  

// demo01.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include <netdb.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>

#define MAC_SIZE    18
#define IP_SIZE     16

// function declare
int get_ip_by_domain(const char *domain, char *ip); // 根据域名获取ip
int get_local_mac(const char *eth_inf, char *mac); // 获取本机mac
int get_local_ip(const char *eth_inf, char *ip); // 获取本机ip


/****** main test **********/
int main(void)
{
    char ip[IP_SIZE];
    char mac[MAC_SIZE];

    //get all the information of interface
    int sockfd;
    struct ifconf ifconf;
    struct
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值