-   Linux - Kernel (
-   -   kernel_sendmsg function send tcp package would return broken pipe error (

asert 05-27-2008 02:33 AM

kernel_sendmsg function send tcp package would return broken pipe error
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;


        memset(&msg, 0x00, sizeof(msg));
        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("");
        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);
        return 0;

static void __exit socket_exit(void)


Mara 06-01-2008 04:07 PM

It looks for me that the socket is not connected to the other side, so any attempt to send a message will produce an error.

All times are GMT -5. The time now is 07:33 AM.