2
votes

I want to develop a network kernel extension on mac os. I got some data with gzip format in function sf_data_in(). I included the header file named <libkern/zlib.h>, and my mac crashed when it was running the code below after I loading the kext with "kextload".

z_stream strm;
bzero(&strm, sizeof(z_stream));

if (Z_OK != inflateInit2(&strm))
{
    printf("inflateInit error.\n");

    inflateEnd(&strm);

    return 0;
}

who can tell me how to use it in kernel programming. it's much better to give some samples. Thanks very much.

2

2 Answers

2
votes

You are passing the wrong number of parameters to inflateInit2(), it requires both a pointer to a stream and the window size in bits. if you do not wish to set the latter, use inflateInit() instead.

You may also want to look at some of the kernel code using zlib, ppp_deflate.c, ipcomp_core.c

0
votes

I found some use of the zlib kernel library in the arch/powerpc/boot/gunzip_util.c file, maybe it will be a good starting point for your code.