LinuxQuestions.org
Visit Jeremy's Blog.
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 04-10-2012, 09:00 PM   #1
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Rep: Reputation: 0
include kernel headers


I'm experimenting w/ creating my own protocol family and type in the socket api. So creating a socket looks like this ...
Code:
    sockfd = socket(AF_MY, SOCK_MY, IPPROTO_MY);
I've added the type SOCK_MY to /usr/src/linux/include/linux/net.h as follows ...
Code:
#ifndef ARCH_HAS_SOCKET_TYPES
/**
 * enum sock_type - Socket types
 * @SOCK_STREAM: stream (connection) socket
 * @SOCK_DGRAM: datagram (conn.less) socket
 * @SOCK_RAW: raw socket
 * @SOCK_RDM: reliably-delivered message
 * @SOCK_SEQPACKET: sequential packet socket
 * @SOCK_DCCP: Datagram Congestion Control Protocol socket
 * @SOCK_PACKET: linux specific way of getting packets at the dev level.
 *        For writing rarp and other similar things on the user level.
 *
 * When adding some new socket type please
 * grep ARCH_HAS_SOCKET_TYPE include/asm-* /socket.h, at least MIPS
 * overrides this enum for binary compat reasons.
 */
enum sock_type {
    SOCK_STREAM = 1,
    SOCK_DGRAM  = 2,
    SOCK_RAW    = 3,
    SOCK_RDM    = 4,
    SOCK_SEQPACKET  = 5,
    SOCK_DCCP   = 6,
    SOCK_MY    = 7,                                          
    SOCK_PACKET = 10,
};
My problem is that when I add the socket() call above to my userspace program. I get the following compile error.
Code:
my.c:58:25: error: 'SOCK_MY' undeclared (first use in this function)
Is there some reason why my userspace app can't see the kernel source headers? It seems like the sock type SOCK_STREAM or others have no problem being seen. I did try to follow the instructions for the grep as indicated in the notes of net.h, but I didn't find anything and believe its not being overridden. I'm running x86_64, gentoo-3.2.1-r2 kernel.
 
Old 04-11-2012, 12:27 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
Did you recompile your kernel after editing the header file ?

Last edited by bsat; 04-11-2012 at 12:28 AM.
 
Old 04-11-2012, 07:15 PM   #3
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Yes, I did. Though I don't understand how that would affect the compile error I'm seeing.

Last edited by rrlangly; 04-11-2012 at 07:16 PM.
 
Old 04-11-2012, 11:48 PM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
If i understand it right, you are trying to modify the operation of the system call "socket". All system calls are a part of the kernel and any modification in them will take effect only when kernel is compiled with the modification.
So make sure you have compiled and booted the right kernel to ensure the change is present in the kernel.
 
Old 04-12-2012, 11:26 PM   #5
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Correct, I am modifying the calls to socket. I've already compiled it in the kernel and I run this kernel. But when I modify for the 'type' field, my user space program which makes the call ...
Code:
sockfd = socket(AF_MY, SOCK_MY, IPPROTO_MY);
... ends up giving me problems as I state above.

The 'domain' field of the protocol I just use a #define in my userspace program and make sure the matching modification in socket.h is compiled into my kernel. The 'protocol' field is defined in my kernel module. But this 'type' field I can't seem to get past.

Last edited by rrlangly; 04-13-2012 at 10:52 PM.
 
Old 04-14-2012, 05:02 PM   #6
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Ok, solved. I needed to do a 'make headers_include' on the kernel source, then make the same changes I made in linux/socket.h to bits/socket.h for my userspace programs.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Recursively include headers in include option for gcc kvm1983 Linux - Newbie 5 09-04-2012 03:21 PM
compiler not able to find headers in /usr/include gupta.pulkit89 Linux - Mobile 0 05-03-2011 04:10 PM
which headers usr/include/ or /usr/include/nptl/? Chris.Rector Linux - Enterprise 0 02-02-2007 01:40 PM
Updating kernel headers /usr/include/linux mhansen Slackware 4 11-30-2006 06:31 AM
Unable to include headers in Makefile Raphexion Programming 2 11-05-2005 08:00 AM


All times are GMT -5. The time now is 09:24 PM.

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