OSX安装packETH

一、下载packETH的OSX专用版本(1.7.1),下载完成后,解压

      下载地址:download

二、下载并安装GTK+2.24

      下载地址:download

三、编辑packETH-1.7/configure

在文件首(文件注释结束后的首行)加入四行代码:

1
2
3
4
PKG_CONFIG_PATH=/Library/Frameworks/GTK+.framework/Versions/2.24.X11/Resources/lib/pkgconfig
export PKG_CONFIG_PATH
PKG_CONFIG=/Library/Frameworks/GTK+.framework/Versions/2.24.X11/Resources/bin/pkg-config
export PKG_CONFIG

注意这里给出的版本号就是上一步安装的GTK+的版本号,要对应上。

四、编辑function_send.c和function.c,二者都在packETH-1.7/src/目录下

在文件中找到"#include <net/if.h>",在与其相邻的上面几行中添加如下内容:

1
2
3
#include <net/bpf.h>
#include <fcntl.h>
#include <sys/socket.h>

删除这一行代码:

1
#include <netpacket/packet.h>

五、修改packETH-1.7/src/function_send.c文件中的三个函数实现

"sendbuilt"改为:

1
2
3
4
void* sendbuilt(void* parameters)
{
    return NULL;
}

"sendsequence"改为:

1
2
3
4
void* sendsequence(void* parameters)
{
    return NULL;
}

"packet_go_on_the_link"改为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
int packet_go_on_the_link(unsigned char* pkt, int nr)
{
    int c, fd, i;
    struct ifreq ifr;
    char buff[100];

    /* do we have the rights to do that? */
    if (getuid() && geteuid()) {
        error("need the su rights");
        return -2;
    }
    memset(&ifr, 0, sizeof(ifr));
    strncpy (ifr.ifr_name, iftext, sizeof(ifr.ifr_name) - 1);
    ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';

    /* check that the specified interface exists */
    if (!if_nametoindex(ifr.ifr_name)) {
        snprintf(buff, 100, "no such interface: %s", iftext);
        error(buff);
        close(fd);
        return -2;
    }

    /* open a bpf device */
    fd = -1;
    for (i = 0; i < 100 && fd == -1; i++) { 
        sprintf(buff, "/dev/bpf%d", i);
        fd = open(buff, O_RDWR);
    }
    if (-1 == fd) {
        error("error - could not open bpf");
        return -2;
    }

    /* set bpf to use the desired interface */
    if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
        snprintf(buff, 100, "error - BIOCSETIF ioctl failed");
        error(buff);
        close(fd);
        return -2;
    }

    /* Set bpf to use ethernet frames */
    u_int dlt = DLT_EN10MB;
    if (ioctl(fd, BIOCSDLT, &dlt ) < 0) {
        snprintf(buff, 100, "error - BIOCSDLT ioctl failed");
        error(buff);
        close(fd);
        return -2;
    }

    /* Send the packet */
    c = write(fd, pkt, nr);
    if (c < 0) {
        error("error during write()");
        return -2;
    }
    if (close(fd) < 0)
        error("warning : close() returned -1");
    return (c);                                                
}

六、编译、安装

./configure --prefix="/usr/local" && make && make install

packETH-1.7_change_for_osx.tar.gz是一个已经改好的packETH包,可以直接下载使用。