stevens wrote:
I have added -Nmisc/neti option to ld,see below:
$ cat hook_test.c
/*
* File: hook_test.c
* Author: stevens
*
* Created on 2008���6���15���, ������10:45
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/neti.h>
#include <netinet/in.h>
#include <sys/int_types.h>
#include <sys/queue.h>
#include <sys/hook_impl.h>
#include <sys/netstack.h>
/*
*
*/
int main(int argc, char** argv) {
net_data_t ipv4=net_lookup_impl(NHF_INET,NULL);
return (EXIT_SUCCESS);
}
Stevens,
Your program indeed looks confusing. As Jim already pointed out
(attached below), kernel modules don't have main(), also stdio.h and
stdlib.h are userland headers that cannot be used in kernel. You may
want to learn how to write a kernel module in Solaris. The links below
can give you some sense about what a Solaris kernel driver looks like.
Also the link Jim mentioned is a good read. And you can always refer to
OpenSolaris source code when have something in doubt.
http://www.sun.com/bigadmin/features/articles/write_dev_driver.jsp
http://packetstormsecurity.org/groups/thc/slkm-1.0.html
Zhijun
$ cc -c hook_test.c
$ ld -Nmisc/amd64/neti -o hook_test hook_test.o
Undefined first referenced
symbol in file
net_lookup_impl hook_test.o
ld: fatal: Symbol referencing errors. No output written to hook_test
$nm /kernel/misc/amd64/neti|grep net_lookup_impl [46] | 976|
92|FUNC |GLOB |0 |2 |net_lookup_impl
---------------------
James Carlson wrote:
stevens writes:
Can I put net_look_impl to main function?Like this:
int main(int argc, char** argv) {
net_data_t ipv4=net_lookup_impl(NHF_INET,NULL);
return (EXIT_SUCCESS);
}
I can't tell what you're trying to do here. main() isn't specified
for kernel loadable modules. Have you read the _init(9E) man page?
Are you trying to build a kernel module or something else? If you're
trying to build a user space program, then main() is a good starting
point, but none of the kernel functions will be available. You
probably want something else (sockets, perhaps) for I/O.
And I compiled
$cc -D_KERNEL -lnsl -lsocket -c hook_test.c
You cannot link against libnsl or libsocket in the kernel. Libraries
don't exist in the kernel.
Do you want to create a kernel module or a user space program?
$ld -dy -Nmisc/neti -o hook_test hook_test.o
Undefined first referenced
symbol in file
net_lookup_impl hook_test.o
ld: fatal: Symbol referencing errors. No output written to hook_test
You need "-r" to produce a relocatable module for use in the kernel.
Here's a good starting point:
http://docs.sun.com/app/docs/doc/816-4854
--
#mdb -K
[0]> eri.prc.sun.com::walk staff s|::print staff_t s_name|
::grep .== zhijun |::eval <s=K|::print staff_t
[EMAIL PROTECTED], x84349
Network Virtualization & Performance Team,
Solaris Core Operating Systems
Since Jul 10,2006
[0]> :c
_______________________________________________
networking-discuss mailing list
[email protected]