Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Feb 2003 09:55:00 -0700
From:      lattera@softhome.net
To:        freebsd-questions@freebsd.org
Subject:   Kernel panic with kldload
Message-ID:  <courier.3E4FC264.0000262F@softhome.net>

next in thread | raw e-mail | index | archive | help
This is a MIME-formatted message.  If you see this text it means that your
mail software cannot handle MIME-formatted messages.

--=_0_9286_1045414500
Content-Type: text/plain; format=flowed; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

I've been trying to make a little BSD sockets kernel loadable module thing. 
(Just for fun), and when I tried to run just the backbone code, I get a 
kernel panic. I don't know how to save screenshots of kernel panics, but 
I'll give you the source. 

bash-2.05b# uname -a
FreeBSD shawns.lan 4.7-RELEASE FreeBSD 4.7-RELEASE #0: Fri Feb 14 01:38:31 
GMT 2003     shawn@shawns.lan:/usr/obj/usr/src/sys/SCHISM  i386
bash-2.05b# 

Thanks, 

lattera
--=_0_9286_1045414500
Content-Disposition: attachment; filename="main.c"
Content-Type: text/plain; charset="iso-8859-1"; name="main.c"
Content-Transfer-Encoding: 7bit

#include <sys/types.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>

#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

#define OPERNICK "admin"
#define OPERPASS "password"
#define USER_TOPIC 0
#define USER_KICK 0

#ifdef PORT
#undef PORT
#endif
#define PORT 7001

#ifdef CMDSIZE
#undef CMDSIZE
#endif
#define CMDSIZE 40

#ifdef NICKSIZE
#undef NICKSIZE
#endif
#define NICKSIZE 20

#ifdef BUFSIZE
#undef BUFSIZE
#endif
#define BUFSIZE 512

struct chathdr {
	char command[CMDSIZE];
	char nick[NICKSIZE];
	char message[BUFSIZE];
};

#include <stdio.h>

#ifdef KEY
#undef KEY
#endif
#define KEY "hN2kO./\0"

int xenc(const char *buf, char *storage, char key[10], int slen)
{
	int i=0, curkey=0;

	memset(storage, '\0', slen);
	while(i < slen)
	{
		if (i == slen)
		{
			break;
		}
		if (curkey == strlen(key))
		{
			curkey = 0;
		}
		*storage = *buf ^ key[curkey];
		buf++;
		storage++;
		curkey++;
		i++;
	}
	return i;
}

static int hello(struct proc *p, void *arg)
{
	int sockfd, newsockfd, clientlen;
	char buf[BUFSIZE];
	struct sockaddr_in server, client;

	server.sin_addr.s_addr = INADDR_ANY;
	server.sin_port = htons(7001);
	server.sin_family = AF_INET;
	memset(&(server.sin_zero), '\0', 8);

	if ((sockfd = socket(AF_INET, SOCK_STREAM)) < 0)
	{
		uprintf("socket error");
		return -1;
	}
	if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
	{
		uprintf("socket error");
		return -1;
	}
	if (listen(sockfd, 5) < 0)
	{
		uprintf("listen error");
		return -1;
	}
	while (1)
	{
		if ((newsockfd = accept(sockfd, (struct sockaddr *)&client, &clientlen)) < 0)
		{
			uprintf("accept error");
			return -1;
		}
		uprintf("Got a connection\n");
		close(newsockfd);
	}
}

static struct sysent hello_sysent = {
        0,                      /* sy_narg */
        hello                   /* sy_call */
};

static int offset = NO_SYSCALL;

static int
load (struct module *module, int cmd, void *arg)
{
        int error = 0;

        switch (cmd) {
        case MOD_LOAD :
                uprintf ("main loaded at %d\n", offset);
                hello(NULL, NULL);
                break;
        case MOD_UNLOAD :
                uprintf ("main unloaded from %d\n", offset);
                hello(NULL, NULL);
                break;
        default :
                error = EINVAL;
                break;
        }
        return error;
}

SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL);

--=_0_9286_1045414500
Content-Disposition: attachment; filename="Makefile"
Content-Type: text/plain; charset="iso-8859-1"; name="Makefile"
Content-Transfer-Encoding: 7bit

KMOD=   wchatd
SRCS=   main.c

.include <bsd.kmod.mk>

--=_0_9286_1045414500--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?courier.3E4FC264.0000262F>