Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 05-27-2008, 03:33 AM   #1
LQ Newbie
Registered: Nov 2006
Posts: 3

Rep: Reputation: 0
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)

Old 06-01-2008, 05:07 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,575

Rep: Reputation: 181Reputation: 181
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PWC - Broken pipe error taladan Linux - Software 5 06-05-2006 04:00 PM
Error whilst intalling 'libgtk2.0-dev', 'Broken Pipe'?! Eerath MEPIS 4 08-15-2005 10:47 AM
Broken Pipe error with rpmbuild in rh9 tuxfood Red Hat 1 05-21-2005 05:30 PM
Broken pipe error when sending data on LAN Tanc Linux - Networking 2 09-14-2003 06:16 AM
Broken Pipe Error ken734 Linux - Newbie 6 09-04-2003 10:54 AM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration