当前位置: 技术问答>linux和unix
linux下如何自定义IPV4包?并把它转发到指定网卡上
来源: 互联网 发布时间:2016-03-21
本文导语: 在linux内核模块编程下实现 自定义IPV4包,并转发 如何实现呢? 我找半天没找到相关的资料,有没有高手指点下!!!感激不尽!!! | man 7 socket SO_BINDTODEVICE Bi...
在linux内核模块编程下实现
自定义IPV4包,并转发
如何实现呢?
我找半天没找到相关的资料,有没有高手指点下!!!感激不尽!!!
自定义IPV4包,并转发
如何实现呢?
我找半天没找到相关的资料,有没有高手指点下!!!感激不尽!!!
|
man 7 socket
SO_BINDTODEVICE
Bind this socket to a particular device like "eth0", as specified
in the passed interface name. If the name is an empty string or
the option length is zero, the socket device binding is removed.
The passed option is a variable-length null terminated interface
name string with the maximum size of IFNAMSIZ. If a socket is
bound to an interface, only packets received from that particular
interface are processed by the socket. Note that this only works
for some socket types, particularly AF_INET sockets. It is not
supported for packet sockets (use normal bind(8) there).
SO_BINDTODEVICE
Bind this socket to a particular device like "eth0", as specified
in the passed interface name. If the name is an empty string or
the option length is zero, the socket device binding is removed.
The passed option is a variable-length null terminated interface
name string with the maximum size of IFNAMSIZ. If a socket is
bound to an interface, only packets received from that particular
interface are processed by the socket. Note that this only works
for some socket types, particularly AF_INET sockets. It is not
supported for packet sockets (use normal bind(8) there).
|
用raw socket
sock = socket(AF_PACKET,SOCK_RAW,ETH_P_IP)
然后bind到指定的网卡
sock = socket(AF_PACKET,SOCK_RAW,ETH_P_IP)
然后bind到指定的网卡
|
在应用层写应用程序可以用原始套接字来做。需要root权限。
|
自定义IPV4包?
你是要改包的格式,IP协议?
这个有难度
只增加或减少一位倒是不难的
你是要改包的格式,IP协议?
这个有难度
只增加或减少一位倒是不难的