LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 03-12-2010, 09:25 AM   #1
duwei
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Rep: Reputation: 0
How can I code a simple Transport Layer Protocol?


Like this?
Code:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>

#include "transport.h"

static int test_protosw_init(void)
{
	int rc;

	rc = proto_register(&test_prot, 0);/*2nd parameter 0 or 1?*/
	if (rc)
		return rc;

	inet_register_protosw(&test_stream_protosw);

	return 0;
}

static void test_protosw_exit(void)
{
	inet_unregister_protosw(&test_stream_protosw);
	proto_unregister(&test_prot);
}

static int test_add_protocol(void)
{
	if (inet_add_protocol(&test_protocol, IPPROTO_TEST) < 0)
		return -EAGAIN;

	return 0;
}

static void test_del_protocol(void)
{
	inet_del_protocol(&test_protocol, IPPROTO_TEST);
}

static int __init init_test(void)
{
    int status = -EINVAL;
    status=test_protosw_init();
    status=test_add_protocol();
    return status;
}

static void __exit exit_test(void)
{
    test_del_protocol();
    test_protosw_exit();
}

module_init(init_test);
module_exit(exit_test);
There seemed to be something wrong,where is it?
 
Old 03-14-2010, 02:52 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The code is not complete, but the general idea seems to be OK. However, where do you fail exactly?

The second argument of proto_register tells if you want a slab allocator or not. It is usually a good idea, but things shouldn't fall if you say 0.
 
Old 03-15-2010, 02:57 AM   #3
duwei
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Mara View Post
The code is not complete, but the general idea seems to be OK. However, where do you fail exactly?

The second argument of proto_register tells if you want a slab allocator or not. It is usually a good idea, but things shouldn't fall if you say 0.
Code:
#define IPPROTO_TEST 150
#define MAX_BUFFER 100

int main()
{
    int sockfd;
    struct sockaddr_in servaddr;
    char buffer[MAX_BUFFER+1];
    
    sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TEST);
    printf("\nconnSock:%d",sockfd);
    
    bzero((void *)&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr =inet_addr("127.0.0.1");
    servaddr.sin_port = htons(5351);
    if(bind(sockfd,(struct sockaddr *)&servaddr,sizeof(struct sockaddr))==-1)
    {
        perror("bind");
        exit(1);
    }
    close(sockfd);
}
I started this test program,error comes.
Attached Thumbnails
Click image for larger version

Name:	Screenshot.png
Views:	47
Size:	13.9 KB
ID:	3026  
 
Old 03-15-2010, 03:07 AM   #4
duwei
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Original Poster
Rep: Reputation: 0
I guess the main problem is that I implemented struct proto test_prot
Code:
struct proto test_prot =
{
    .name           = "TEST",
    .owner          = THIS_MODULE,
    .close          = test_close,
    .connect        = test_connect,
    .disconnect     = test_disconnect,
    .accept         = test_accept,
    .ioctl          = test_ioctl,
    .init           = test_init_sock,
    .destroy        = test_destroy_sock,
    .shutdown       = test_shutdown,
    .setsockopt     = test_setsockopt,
    .getsockopt     = test_getsockopt,
    .sendmsg        = test_sendmsg,
    .recvmsg        = test_recvmsg,
    .backlog_rcv    = test_backlog_rcv,
    .hash           = test_hash,
    .unhash         = test_unhash,
    .get_port       = test_get_port,
};
with simple "printk" function,can you show me a sample function,say "test_init_sock",for me?I have never written such a function.Thanks!
 
Old 03-15-2010, 10:30 PM   #5
zulhelman_hanafi
LQ Newbie
 
Registered: Mar 2010
Location: Depok Indonesia
Distribution: Ubuntu
Posts: 4

Rep: Reputation: 0
I have any problem when I try running VNE Dragon on Ubuntu, after I make type as below
> help shell
shell <cmd> or !<cmd> -- send <cmd> to your shell. whats the meaning cmd ???? help me please
 
  


Reply



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
Protocol on ethernet layer brunoczo Linux - Networking 1 11-05-2009 11:42 PM
Kmail; unrecognized transport protocol when sending. tidiman07 Linux - Software 2 02-08-2008 12:39 PM
LXer: FTP Server setup with TLS (Transport Layer Security) on Debian LXer Syndicated Linux News 0 02-04-2008 07:00 AM
simple way to make k9copy shrink dual layer to single layer DVD replica9000 Linux - Software 2 12-06-2007 02:41 PM
System V Transport Layer Interface-should I learn it? beginner16 Programming 1 01-21-2004 11:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:50 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration