makefile

VPATH = src include  # 添加文件搜索目录
CC = cc  # 编译器
CFLAGS = -g -Wall -I include  # 添加.h文件搜索目录

build: objs/arpping

objs/arpping: objs/carp.o objs/arp.o objs/tools.o
    $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@     

objs/carp.o: main.c arp.h
    $(CC) $(CFLAGS) -c $< -o $@

objs/arp.o: arp.c arp.h tools.h
    $(CC) $(CFLAGS) -c $<  -o $@

objs/tools.o: tools.c tools.h
    $(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean install
clean:
    rm -rf objs/*

执行结果

执行make命令在objs文件夹中就会看到arpping可执行文件

  1. 不指定接口名字 arpping 172.18.0.2

    [root@iz2zecj7a5r32f2axsctb9z arp]# ./objs/arpping 172.18.0.2
    welcome use ./objs/arpping program, version is v1.0
    usage:    ./objs/arpping -I interface host
  2. 指定不正确的接口名字 arpping -I eth3 172.18.0.2

    [root@iz2zecj7a5r32f2axsctb9z arp]# ./objs/arpping -I eth3 172.18.0.2
    ioctl SIOCGIFINDEX error: No such device
  3. 指定不正确的发出接口 eth0 网段为172.17.147.255网段 arpping -I eth0 172.18.0.2

    [root@iz2zecj7a5r32f2axsctb9z arp]# ./objs/arpping -I eth0 172.18.0.2
    ARPING 172.18.0.2 from 172.17.147.135 eth0
    Request timeout
  4. 指定正确的接口和地址 arpping -I docker0 172.18.0.2

    [root@iz2zecj7a5r32f2axsctb9z arp]# ./objs/arpping -I docker0 172.18.0.2
    ARPING 172.18.0.2 from 172.18.0.1 docker0
    Unicast reply from 172.18.0.2 [02:42:AC:12:00:02]
  5. 指定正确的接口和没有占用的网段地址 arpping -I docker0 172.18.0.3

    [root@iz2zecj7a5r32f2axsctb9z arp]# ./objs/arpping -I docker0 172.18.0.3
    ARPING 172.18.0.3 from 172.18.0.1 docker0
    Request timeout
文档更新时间: 2021-02-04 19:42   作者:周国强