bug-hurd
[Top][All Lists]
Advanced

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

Re: PPP port: Code for setting gateway


From: Igor Khavkine
Subject: Re: PPP port: Code for setting gateway
Date: Sat, 25 Nov 2000 16:31:31 -0500
User-agent: Mutt/1.2.5i

On Sat, Nov 25, 2000 at 01:50:37AM -0600, Daniel E Baumann wrote:
> Here is the code I wrote for setting the gateway in bundle.c, I welcome any 
> comments. Some of this I borrowed from fsysopts.c.
> 

I hope this is prototype code because there is a couple of obvious
blunders.

> int
> bundle_SetRoute(struct bundle *bundle, int cmd, struct in_addr dst,
>                 struct in_addr gateway, struct in_addr mask, int bang, 
>                 int ssh)
> {
> #ifdef __GNU__
>   int result = 1;
>   error_t err;
>  
>   /* The file we use as a handle to get FSYS.  */
>   char *node_name;
>   file_t node;
>  
>   /* The filesystem we're passing options to.  */
>   fsys_t fsys;
>   char *opt = strcat("--gateway=", inet_ntoa(gateway));

Hmm, you can't really append a string to a literal string,
most often you'll get a segfault. Try:
char opt[sizeof("--gateway=255.255.255.255")] = "--gateway=";
strcat(opt, inet_ntoa(gateway));

>  
>   sprintf(node_name, "%s/%d", _SERVERS_SOCKET, PF_INET);

Well, that's another segfault right there, you're trying to write
to a wild pointer. Try:
asprintf(&node_name, _SERVERS_SOCKET "%d", PF_INET);
Actually you don't even have to use asprintf(), just allocate an array
large enough to hold _SERVERS_SOCKET + largest integer. Too bad
you can't embed a constant integer into a string at compile time.

>   node = file_name_lookup (node_name, 0, 0666);
>   if (node == MACH_PORT_NULL)
>   {
>     log_Printf(LogERROR, "HURD: Can't open port to pfinet server, 
> file_name_lookup
>                 failed with %s.\n", strerror(errno));
>     error (1, errno, "%s", node_name);
>   }
>  
>    /* Get the filesystem for NODE.  */
>   err = file_getcontrol (node, &fsys);
>   if (err)
>   {
>     log_Printf(LogERROR, "HURD: Can't get the filesystem for node %s.", 
> node_name);
>     error (2, err, "%s", node_name);
>   }
>  
>   err = fsys_set_options (fsys, opt, 1, 1);
>   if (err)
>   {
>     log_Printf(LogERROR, "HURD: Failed to set option %s for node %s.", opt, 
> node_name);
>     error(5, err, "%s: %s", node_name, opt);
>   }
>  
>   log_Printf(LogDEBUG, "HURD: The pfinet server's gateway is set to %x\n",
>               (unsigned)gateway.s_addr);
>  
>   return result;
>  
> #else
> ...
>                    
> Dan

Otherwise looks good.

Igor



reply via email to

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