LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 05-27-2008, 02:33 AM   #1
asert
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!

Code:
#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);
 
Old 06-01-2008, 04:07 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,527

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 11:40 AM.

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