Re: sys/queue.h
- From: William Pursell <bill.pursell@xxxxxxxxx>
- Date: Sun, 15 Jul 2007 20:16:56 -0000
On Jul 15, 8:14 pm, westymatt <westym...@xxxxxxxxx> wrote:
I am looking for some documentation on using #include <sys/queue.h>
Has anybody ever used it? I would like to integrate a linked list
using it.
The best documentation is in /usr/include/sys/queue.h :)
A few remarks on the code below...
I am writing a packet sniffer and am using a packetCache structure to
hold captured packets for exporting purposes and data collection.
well here is the code
<code>
#define TRUE 1
#define FALSE 0
typedef int bool;
You can get these from stdbool.h.
{
struct packetCache *pc;
if ((pc = (struct packetCache *) malloc (sizeof
(struct packetCache) + packet_header->len)) == NULL)
Many people will argue that the assignemt is better written:
pc = malloc( sizeof *pc + packet_header->len)
(no cast and take the size of the object rather than a type.)
I have a slight preference that there be no cast, since
failure to include a prototype will cause a compiler
warning, and I strongly encourage sizeof object instead
of sizeof(type), since it can be verified by local inspection
of the code (ie, I don't have to look for the declaration
of pc to confirm that it is a struct packetCache *.
And, the line stays correct when pc's type is changed
to be a struct newpacketCache *)
/*command line options parsing*/
int option;
while ((option = getopt(argc, argv, "i:pdw:Dm:ch")) != -1)
{
IMO, this should not be in main, but moved to a seperate
function.
print_help();
return 1;
return EXIT_FAILURE is more portable, but this
is okay on linux.
default:
print_help();
abort();
Hmmm. I'm not sure I want a program to
dump core due to erroneous command line
args.
void signal_capture_cntrlc(int sig)
{
fprintf(stderr, "Caught a INT signal\n");
fprintf(stderr, "Shutting Down\n");
exit(0);}
You really should not call fprintf
from within the signal handler, as it is not
re-entrant. Especially since you registered with
signal() instead of sigaction, you may receive
a SIGINT during one of the calls to fprintf and
your program will lock up.
.
- Follow-Ups:
- Re: sys/queue.h
- From: westymatt
- Re: sys/queue.h
- References:
- sys/queue.h
- From: westymatt
- sys/queue.h
- Prev by Date: sys/queue.h
- Next by Date: PLEASE HELP - Very odd kernel panic problem
- Previous by thread: sys/queue.h
- Next by thread: Re: sys/queue.h
- Index(es):