I have followed a driver tempate to rewrite code.
$cat qotd_1.c
/* 
 * File:   qotd_1.c
 * Author: stevens
 *
 * Created on 2008年7月28日, 下午2:15
 */

#include <sys/modctl.h>
#include <sys/conf.h>
#include <sys/devops.h>
#include <sys/cmn_err.h>
#include <sys/ddi.h>
#include <sys/sunddi.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>
#define QOTD_MAXLEN 128
/*
 * 
 */
static const char qotd[QOTD_MAXLEN]
="Be careful about reading heath book.\
You may die of a misprint.-Mark Twain \n";
static struct dev_ops qotd_dev_ops={
DEVO_REV,
0,
ddi_no_info,
nulldev,
nulldev,
nulldev,
nulldev,
nodev,
(struct cb_ops*)NULL,
(struct bus_ops*)NULL,
nulldev
};
static struct modldrv modldrv={
    &mod_driverops,
    "Quote of the Day 1.0",
    &qotd_dev_ops
};
static struct modlinkage modlinkage={
    MODREV_1,
    (void*)&modldrv,
    NULL
};
int _init(void){
    cmn_err(CE_CONT,"QOTD:%s\n",qotd);
    net_data_t ipv4=net_lookup_impl(NHF_INET,NULL);
    return (mod_install(&modlinkage));
}
int _info(struct modinfo*modinfop){
    return (mod_info(&modlinkage,modinfop));
}
int _fini(void){
    return (mod_remove(&modlinkage));
}
$ cc -D_KERNEL -m64 -c qotd_1.c
$ ld -r -o qotd_1 qotd_1.o
#cp qotd_1 /tmp
#ln -s /tmp/qotd_1 /usr/kernel/drv/amd64/qotd_1
#cp qotd_1.conf  /usr/kernel/drv/amd64/
# add_drv qotd_1
devfsadm: driver failed to attach: qotd_1
Warning: Driver (qotd_1) successfully added to system but failed to attach
#tail /var/adm/messages
Jul 28 14:20:44 e1000 genunix: [ID 819705 kern.notice] 
/usr/kernel/drv/amd64/qotd_1: undefined symbol
Jul 28 14:20:44 e1000 genunix: [ID 826211 kern.notice]  'net_lookup_impl'
Jul 28 14:20:44 e1000 genunix: [ID 472681 kern.notice] WARNING: mod_load: 
cannot load module 'qotd_1'
 
 
This message posted from opensolaris.org
_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to