Is is it possible to have Minix 3 as a dns-server and if one would dare to code the service self how would that code look like (roughly)?
Minix actually has a nameserver in it already. Since Minix is open source, you can use it as a starting point. The program is called "nonamed". The man page says it isn't a name daemon, but actually it is.
It's just that it's very simple, which is probably what you want. Either you can use it as is, just put all hostnames you want to resolve in /etc/hosts, and "nonamed" will export those... or use nonamed as something to extend upon. At least the protocol is there already.
Man page for nonamed(8) and source code.
That's kind of a big question for little, ol' StackOverflow. I'd suggest looking around for some code that you could use or port.
Related
This question already has an answer here:
Implementing Linux System Call using LKM
(1 answer)
Closed 6 years ago.
So I have seen a bunch of questions about adding system calls but I can't find any examples of one using an LKM that works. I have found resources like this: http://tldp.org/LDP/lkmpg/2.6/html/
This works, in theory, but doesnt compile. Can anyone point me towards a simple example for adding a hello world system call or something. Something like this: https://tssurya.wordpress.com/2014/08/19/adding-a-hello-world-system-call-to-linux-kernel-3-16-0/ that doesn't require me to recompile my kernel?
Generally, it's strongly recommended to not implement a whole new system call.
Rather, only implement a new ioctl and likely some new block or character devices.
For how to do that, it looks like there is another question/answer already: How do I use ioctl() to manipulate my kernel module?
I don't think you can do that with a module. The definitions of the syscall go into two places which cannot really be changed at runtime (as far as I know): syscall table (which assigns numbers per architecture) and syscalls include file (installed with kernel itself, not modules). (Or at least not without messing with code rewriting at runtime.)
You'll always need to recompile the kernel in that case. But if you want to have a quick update/try cycle, you could implement a syscall that's just a stub, passing a message to the right module if it's loaded. It would allow you to change the implementation, but not the signature.
I often spend lots of time trying to find out where the exact implementation is located. It gets very frustrating when dealing with some low-level code that might end up somewhere in kernel.
I usually just google or try to guess the location and/or method names, but it is not always very effective.
Is there some methodical way to trace the flow up to the implementation? How do you guys usually do it?
Load the whole the code with relevant dependencies to a graphical IDE (NetBeans can do it, for instance) which can to call graph, declaration-definition jumps, etc. or use LibClang and its wrapper for the text editor of your choice, it is also very good at indexing. At last, you can consider classics, ctags, which can link definition and declaration points.
There used to be a ctrace program that did just that but I don't think it is actively maintained.
Ultimately, it depends what exactly you are trying to achieve. It actually looks like you want to look up a specific function rather than trace it. If that is the case indeed, consider using some kind of source browser: from etags to cscope to OpenGrok.
I learned to program with Pascal in high school, and more recently I decided to get out of the sandbox and try to figure out how my computer actually works. So I installed ubuntu on my iMac (i686) and started learning C, which seemed like a good way to get "under the hood."
One of the basic things I'm trying to figure out is where the kernel ends and the standard libraries begin. A book told me that the linux system calls (which I understand to be the interface between the kernel and the libraries) could be found in the header file unistd.h, so this seemed like a good place to start. But when I tried to find the header on my system (using locate unistd.h), I got this result:
/usr/include/unistd.h
/usr/include/asm-generic/unistd.h
/usr/include/i386-linux-gnu/asm/unistd.h
/usr/include/i386-linux-gnu/bits/unistd.h
/usr/include/i386-linux-gnu/sys/unistd.h
/usr/include/linux/unistd.h
/usr/lib/syslinux/com32/include/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/alpha/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/arm/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/avr32/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/blackfin/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/c6x/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/cris/include/arch-v10/arch/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/cris/include/arch-v32/arch/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/cris/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/frv/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/h8300/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/hexagon/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/ia64/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/m32r/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/m68k/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/microblaze/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/mips/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/mn10300/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/openrisc/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/parisc/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/powerpc/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/s390/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/score/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/sh/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/sparc/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/tile/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/unicore32/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/x86/include/asm/ia32_unistd.h
/usr/src/linux-headers-3.5.0-27/arch/x86/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/arch/xtensa/include/asm/unistd.h
/usr/src/linux-headers-3.5.0-27/include/asm-generic/unistd.h
/usr/src/linux-headers-3.5.0-27/include/linux/unistd.h
/usr/src/linux-headers-3.5.0-27-generic/include/linux/unistd.h
Why the heck are there so many versions of this file--and other header files--in my system? Some of them seem to be for other CPUs (like sparc), so why did ubuntu bother to install them on my computer? And how does the all of this fit with what Eric Raymond calls the SPOT rule: "every piece of knowledge must have a single, unambiguous, authoritative representation within a system." (The Art of Unix Programming, p. 91.)
Thanks in advance for any help. I'm happy to read big books if necessary.
I think these header files are directly from linux-3.5.0-27 source code. Ubuntu developers didn't know what kind of target they are dealing with. Maybe Intel x86/powerPC/ or even a mobile hand set(ARM), so they just copy all the head files and make a simple link.
As a proof-of-concept, plus a handy paranoid tool, I'm writing an OpenBSD LKM that will connect to an IRC channel, and report when hooked syscalls are executed.
This is so I can essentially have a 'live' update of filesystem changes, user logons, etc., when I'm offsite but have internet access.
I've gotten as far as connecting the socket, but am stuck at trying to perform the equivalent of a getaddrinfo or even inet_addr call with a hardcoded address.
As these are userland functions, any attempts to use them will result in undefined references - fair enough. The trouble is, after a while of Googling and grep'ing the openbsd source, I cannot find any equivalent kernel functions to do this; the best recommendation has been to reimplement them in the module.
This means I need to also implement things like islower, isxdigit and isspace (and probably others as I progress), which gets a bit much to perform something so simple; is anyone aware of a workaround or alternative for this, or am I stuck c+p code from the net files?
This is definitely better done in userspace. Regardless, OpenBSD no longer supports kernel modules.
Not that you're working on this project anymore. I just wanted to answer so that this could be closed, and so that I could clarify how to use some stdlib functions in the kernel.
In response to this:
This means I need to also implement things like islower, isxdigit and isspace (and probably others as I progress), which gets a bit much to perform something so simple; is anyone aware of a workaround or alternative for this, or am I stuck c+p code from the net files?
Some C stdlib functions are available from libkern (see libkern(9)). Others, including many of the ctype functions like islower(), are available from libsa. To use these, you need something like:
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
libsa contains a handful of headers (found in /usr/src/sys/lib/libsa/), so include each one you need.
After reading some stuff it seems I can map the SMBIOS memory and parse it.
I have no idea on how to go about this.
I can't use any managed code as I would like this to be compilable under any OS.
Does anyone have any code examples how to go about this?
On most systems, it is not mapped into user-mode accessible memory, so you need to call some system API.
On Windows, you can call GetSystemFirmwareTable.
For Linux I guess you should have a look at the dmidecode source (GPL) for concrete code...
Using and parsing dmidecode output may be all you need...
I wrote a reusable class to read all the SMBIOS stuff.
It is very clean code with a proper error handling and easy to extend.
You can derive a class from this class that uses the parsed data to display it or do whatever you want with it.
You find also a link to the actual SMBios documentation in the code's comments.
You can download it from my homepage:
ftp://ftp.netcult.ch/mirror/elmue/SMBiosClass.zip
Elmue