本程序在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