Unable to talk to tap(4)

Steve Randall srandall52 at sbcglobal.net
Fri May 16 13:25:09 UTC 2008


On Thu, 15 May 2008 14:49:26 -0400
"Bob McConnell" <rvm at CBORD.com> wrote:

> >>> My code so far:
> >>>
> >>> ----------------- tear along dotted line -----------------
> >>>  tapFD = open ("/dev/tap0", O_RDWR);
> >>>  if (tapFD < 0) {
> >>>    fprintf (stderr, "Failed to open /dev/tap0: %d.\n", tapFD);
> >>>    exit (2);
> >>>  }
> >>>
> >>>  fprintf (stderr, "Successfully opened /dev/tap0.\n");
> >>>
> >>>  unsigned char * buffer = (unsigned char*)malloc(1514);
> >>>  if (buffer = NULL) {

       if (buffer == NULL) {


> >>>    fprintf (stderr, "No memory available.\n");
> >>>    close (tapFD);
> >>>    exit(3);
> >>>  }
> 
> When I replace the malloc with an automatic array, the
> error goes away and I get the data I am looking for. i.e.:
> 
>    unsigned char buffer[1514];
> 
> So why can't I use malloc to create that buffer?



More information about the freebsd-questions mailing list