小编Saa*_*aat的帖子

MAC地址打印

这是一个代码,它获取有关网络的一些信息,问题是当它打印出正常打印的MAC地址时,有时会用00:21:84:a2:12:88和00:ffffff21:84:a2:12填充fff :ffffff88因机器而异

这是代码

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <sys/types.h>
#    include <netinet/if_ether.h>
#define IP_QUAD(ip)  (ip)>>24,((ip)&0x00ff0000)>>16,((ip)&0x0000ff00)>>8,((ip)&0x000000ff)
#define IP_ADDR_LEN 4
struct {
    char *dev;
    int sd;
    struct ether_addr eth;
    struct in_addr ip;
    struct in_addr bcast;
    unsigned int mtu;
} local_info ;

struct ifreq eth_init(char*,struct ifreq);
struct ifreq eth_get_info(struct ifreq);
struct ifreq eth_get_bcast(struct ifreq);

int
main(int argc,char **argv){
    int sd;
    struct ifreq ifr;
    if(argc != …
Run Code Online (Sandbox Code Playgroud)

c networking

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

networking ×1