int send_arp_request(void)
{
struct socket *arpsock;
struct sockaddr sa;
struct msghdr msg;
struct iovec iov;
mm_segment_t oldfs;
int size = 0;
int error = 0;
char *warp_dev="eth0";
char dev[20];
char*buf="ffffffffffff0060b31ecda3080600010800060400010060b31ecda3c0a80401000000000000c0a8040239e000003078000035a40000000600010000";
if ((error=sock_create(PF_INET, SOCK_PACKET, htons(ETH_P_ARP),
&arpsock))<0) {
printk(KERN_WARNING "Could not create a PF_PACKET SOCK_RAW
Socket\n");
return (-1);
}
memset(&sa,0,sizeof(sa));
strcpy(dev,warp_dev);
strncpy(sa.sa_data,dev,sizeof(sa.sa_data));
error = arpsock->ops->bind(arpsock,&sa,sizeof(sa));
if (error<0)
{
printk(KERN_WARNING "Error binding socket");
return -1;
}
iov.iov_base = (char *)buf;
iov.iov_len = (__kernel_size_t) strlen(buf);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_flags = 0;
oldfs = get_fs();
set_fs(KERNEL_DS);
size = sock_sendmsg(arpsock,&msg,strlen(buf));
set_fs(oldfs);
if (size < 0)
printk(KERN_WARNING "sock_sendmsg error: %d\n",size);
return 0;
}
Thanks & Regards,
Sid
> I was trying to send ARP requests by using the following function
> inside a kernel module but I always get an error saying "sock_sendmsg
> error: -107". Am I missing something?? Would really appreciate if you
> can look into this code and tell me what I am doing wrong.
> char*buf="ffffffffffff0060b31ecda3080600010800060400010060b31ecda3c0a80401000000000000c0a8040239e000003078000035a40000000600010000";
This is a long string of ASCII characters, and it is not the proper
contents of the Ethernet frame. You ought to convert the hex text
to binary bytes before attempting a send.
Get the arping sources <http://freshmeat.net/projects/arping/>.
HTH
Tauno Voipio
tauno voipio (at) iki fi
> > >char*buf="ffffffffffff0060b31ecda3080600010800060400010060b31ecda3c0a80401000000000000c0a8040239e000003078000035a40000000600010000";
>
> This is a long string of ASCII characters, and it is not the proper
> contents of the Ethernet frame. You ought to convert the hex text
> to binary bytes before attempting a send.
Captured an arp packet that is sent by the same machine and tried to
send the same arp packet in binary from inside the kernel module but
it still didn't work. Any other ideas?
>
> Get the arping sources <http://freshmeat.net/projects/arping/>.
Looks like they create sockets and send packets from user space. When
I am trying to send packets from kernel space, I was not able to use
the same functions.
Sid
Woud you please tell why?
It could, maybe, help us to give the proper answers.
If you're trying to do some kernel programming, you should
know enough of C to separate a hex string and a binary
byte vector from each other.