Find the answer to your Linux question:
Results 1 to 8 of 8
Hi all, I'm reading about linux networking architecture. Now I want to test some kernel APIs in manipulating socket buffers so I write a very small program to test the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! dongthao's Avatar
    Join Date
    May 2006
    Posts
    5

    Unhappy Test Kernel API


    Hi all,
    I'm reading about linux networking architecture. Now I want to test some kernel APIs in manipulating socket buffers so I write a very small program to test the functions in skbuff.h file. First, I try the alloc_skb:
    Code:
    #include <linux/skbuff.h>
    #include <socket.h>
    
    int main(){
            sk_buff socketbuff;
            socketbuff = alloc_skb(12, GFP_DMA);
            return 0;
    }
    You see, a very simple program but when I compile with
    Code:
    gcc -o test testskbuff.c 
    or
    gcc -o test testskbuff.c -l /usr/include/linux
    , the errors sank me!
    Code:
    In file included from /usr/include/linux/sched.h:14,
                     from /usr/include/linux/skbuff.h:19,
                     from testskbuff.c:1:
    /usr/include/linux/timex.h:173: field `time' has incomplete type
    In file included from /usr/include/linux/bitops.h:69,
                     from /usr/include/asm/system.h:7,
                     from /usr/include/linux/sched.h:16,
                     from /usr/include/linux/skbuff.h:19,
                     from testskbuff.c:1:
    /usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
    /usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
    In file included from /usr/include/linux/signal.h:4,
                     from /usr/include/linux/sched.h:25,
                     from /usr/include/linux/skbuff.h:19,
                     from testskbuff.c:1:
    /usr/include/asm/signal.h:107: syntax error before "sigset_t"
    /usr/include/asm/signal.h:110: syntax error before '}' token
    In file included from /usr/include/linux/sched.h:81,
                     from /usr/include/linux/skbuff.h:19,
                     from testskbuff.c:1:
    /usr/include/linux/timer.h:32: field `vec' has incomplete type
    /usr/include/linux/timer.h:37: field `vec' has incomplete type
    /usr/include/linux/timer.h:45: syntax error before "spinlock_t"
    /usr/include/linux/timer.h:53: syntax error before '}' token
    /usr/include/linux/timer.h:63: field `list' has incomplete type
    /usr/include/linux/timer.h:67: syntax error before "tvec_base_t"
    /usr/include/linux/timer.h:101: syntax error before "tvec_bases"
    /usr/include/linux/timer.h: In function `init_timer':
    ....
    My god! It's only a little bit on my screen. I guess that I have missed some including files but I can't know what exactly they are .
    So can you explain me what happen and tell me what to do to run this simple program?

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Are you trying to write a module? I'm not completly sure, but if you are going to use the kernel API, maybe you need the kernel.h include.




    Best regards

  3. #3
    Just Joined! dongthao's Avatar
    Join Date
    May 2006
    Posts
    5
    Hi, fernape,
    I don't intend to write a module (uhm, it's so complex for my purpose), i just want to test some kernel APIs. I've just added the kernel.h to my program but nothing changed . It's the first time I test kernel APIs in this way so I'm not sure what I have to do!

  4. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    I think you can not use kernel API from an userland program. Your program will be linked against the libc (as other programs did) but you need some recursive definitions for the kernel headers (that amount of symbol blah blah blah not defined...)

    The other problems are related to the API itself. sk_buff is NOT a type, it is a structure, so you should declare it as: struct sk_buff my_sk_buff. More, alloc_skb returns a pointer, not a structure... read the API again. This compiles:

    #include <linux/kernel.h>
    #include <linux/skbuff.h>
    #include <linux/module.h>

    int algo()
    {
    struct sk_buff *socketbuff;
    socketbuff = alloc_skb(12, GFP_DMA);
    return 0;
    }

    But this does not perform anything... this is almost a module... you should use module_init and module_exit.

    Maybe you want to read this: http://www.linuxforums.org/programmi...ng_part_i.html

    Best regards

  5. #5
    Just Joined! dongthao's Avatar
    Join Date
    May 2006
    Posts
    5
    Hi fernape, sorry for late responding.
    After a time finding solution, I think that you were right! I haven't got any idea for programming using kernel functions without using module. So I decided to start module programming.
    Thank you very much for your help. It's very helpful to me.

  6. #6
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Your welcome!

    Check this: http://www.faqs.org/docs/kernel/

    Best regards

  7. #7
    Just Joined! dongthao's Avatar
    Join Date
    May 2006
    Posts
    5
    Hihi, I've got that document. And here's my first problem in the world of kernel module:
    http://www.linuxforums.org/forum/lin...em-redhat.html
    Hope have help.

  8. #8
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    You need to install your kernel sources.

    Best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •