Send packet with sockets from kernel module -
i writing kernel module should receive messages user-space , send response via socket.
when program , module on same machine , use ip 127.0.0.1
, works fine. when try on different machines , use real network ip, 192.168.3.146
works in 1 way.
i receive message user-space, can not receive kernel. use sock_sendmsg
function sending message kernel , it's not return error. not messages firewall came machine, kernel module.
here similar questions , examples, not useful enough me or examples used old kernel version.for skeleton used one,from udp sockets: http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-3.html. help?
kernel module code sending:
void send_data(unsigned char *data) { if(!is_err_or_null(data)) { int ret; mm_segment_t oldfs; struct msghdr message; struct iovec iovector; struct sockaddr_in sendaddr; sendaddr.sin_family = af_inet; sendaddr.sin_addr.s_addr = inaddr_any; //sendaddr.sin_addr.s_addr = in_aton("192.168.1.75"); //here port sk_buff structure received. sendaddr.sin_port = *((unsigned short*)skbuffer->data); memset(&message, 0, sizeof(message)); message.msg_name = &sendaddr; message.msg_namelen = sizeof(sendaddr); /* send message */ iovector.iov_base = data; iovector.iov_len = strlen(data); message.msg_iov = &iovector; message.msg_iovlen = 1; message.msg_control = null; message.msg_controllen = 0; oldfs = get_fs(); set_fs(kernel_ds); ret = sock_sendmsg(sendsocket, &message, strlen(data)); set_fs(oldfs); } }
i found alternative solution, using netpoll sockets. more easier sockets, used before , works. answer , proper code here, on stackoverflow question.
Comments
Post a Comment