bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PPP port: iface_Create


From: Neal H Walfield
Subject: Re: PPP port: iface_Create
Date: Sat, 2 Dec 2000 14:54:58 -0500
User-agent: Mutt/1.2.5i

On Sat, Dec 02, 2000 at 12:31:27PM -0600, Daniel E Baumann wrote:
> I have writen the function to create an iface startuct in PPP using several 
> SIOC* ioctl glibc calls. This is the first time I've used this so I am 
> posting it for inspection, comments and all that. Also, is it ok to reuse the 
> same ifreq struct in the ioctl calls or should I declare one for each type of 
> call to pass in. Also, Marcus if your not implementing any of these calls 
> please let me know. I've got your list, but I haven't checked it yet.

> #ifdef __GNU__

Personally, I HATE ifdefs.  I encourage you to consider breaking this
function out and creating two files (I like the glibc way of doing
things) then figuring out which one to compile at configure time.

>   if ((iface = (struct iface *)malloc(sizeof (struct iface))) == NULL) 

You should not cast the return type of malloc (unless that is what they
do in the rest of the code, however, I have not looked at it).

>   {
>     fprintf(stderr, "iface_Create: malloc: %s\n", strerror(errno));

Is there a reason that you choose not to use perror?
perror ("iface_Create")

>   s = socket(AF_INET, SOCK_DGRAM, 0);
>   if (s < 0) 
>   {
>     fprintf(stderr, "iface_Create: socket(): %s\n", strerror(errno));
      goto error;
>   }
> 
> 
>   if ((addr = (struct iface_addr *)malloc(sizeof (struct iface_addr))) ==     
>   NULL) 
>   {
>     fprintf(stderr, "iface_Create: malloc: %s\n", strerror(errno));
      goto have_socket_error;
>   }
>
>   if ((ifr = (struct ifreq *)malloc(sizeof (struct ifreq))) == NULL) 
>   {
>     fprintf(stderr, "iface_Create: malloc: %s\n", strerror(errno));
>     goto have_addr_error;
>   }

...

>   return iface;

...

have_addr_error:
    free (addr);
have_socket_error:
    free (iface);
    close (s);
error:
    return NULL;

-Neal

-- 
Neal H Walfield
University of Massachusetts at Lowell
neal@walfield.org or neal@cs.uml.edu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]