using kernel_sendmsg function to send tcp package would return broken pipe error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



anyone could tell me why the error is happened,what problem with the
code and how to resolve it?
any help is appreciated!

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/socket.h>
#include <net/sock.h>

static struct socket *sock;
static struct work_struct work;
static int tcp_sendto(struct socket *sock, void * buff, size_t len,
                unsigned flags, struct sockaddr *addr, int addr_len)
{
        struct kvec vec;
        struct msghdr msg;

        vec.iov_base=buff;
        vec.iov_len=len;

        memset(&msg, 0x00, sizeof(msg));
        msg.msg_name=addr;
        msg.msg_namelen=addr_len;
        msg.msg_flags = flags | MSG_DONTWAIT | MSG_NOSIGNAL;

        return kernel_sendmsg(sock, &msg, &vec, 1, len);
}



static char *hello = "hello";

static void sendmsg(void *dummy)
{
        int n;
        struct sockaddr_in addr;
        memset(&addr, 0x00, sizeof(addr));
        addr.sin_family = AF_INET;
        addr.sin_port = htons(15221);
        addr.sin_addr.s_addr = in_aton("192.168.0.102");
        n = tcp_sendto(sock, hello, 6, 0, (struct sockaddr *)&addr,
sizeof(addr));
        if(n == -EPIPE) {
            printk("broken pipe\n");
        } else {
            printk("send %d bytes\n", n);
        }

}

static int __init socket_init(void)
{
        sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
        INIT_WORK(&work, sendmsg, NULL);
        schedule_work(&work);
        return 0;
}

static void __exit socket_exit(void)
{
        sock_release(sock);
}



module_init(socket_init);
module_exit(socket_exit);
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux