On Sat, Dec 19, 2009 at 09:16:06PM +0200, Vladimir Kirillov wrote:
> Hello t...@!
> 
> Not sure this strdup() is required just to print the actor_mac.
> Should it be removed?

No. Please read the ether_ntoa manpage:
"It returns a pointer to a static structure that is reused for each call."
In other words you can not call ether_ntoa() twice in a printf().

> 
> Index: ifconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.226
> diff -u -p -r1.226 ifconfig.c
> --- ifconfig.c        14 Dec 2009 17:22:58 -0000      1.226
> +++ ifconfig.c        19 Dec 2009 19:15:15 -0000
> @@ -4360,21 +4360,16 @@ trunk_status(void)
>               if (isport)
>                       printf(" trunkdev %s", rp.rp_ifname);
>               putchar('\n');
> -             if (ra.ra_proto == TRUNK_PROTO_LACP) {
> -                     char *act_mac = strdup(
> -                         ether_ntoa((struct ether_addr*)lp->actor_mac));
> -                     if (act_mac == NULL)
> -                             err(1, "strdup");
> +             if (ra.ra_proto == TRUNK_PROTO_LACP)
>                       printf("\ttrunk id: [(%04X,%s,%04X,%04X,%04X),\n"
>                           "\t\t (%04X,%s,%04X,%04X,%04X)]\n",
> -                         lp->actor_prio, act_mac,
> +                         lp->actor_prio,
> +                         ether_ntoa((struct ether_addr *)lp->actor_mac),
>                           lp->actor_key, lp->actor_portprio, lp->actor_portno,
>                           lp->partner_prio,
>                           ether_ntoa((struct ether_addr*)lp->partner_mac),
>                           lp->partner_key, lp->partner_portprio,
>                           lp->partner_portno);
> -                     free(act_mac);
> -             }
>  
>               for (i = 0; i < ra.ra_ports; i++) {
>                       printf("\t\ttrunkport %s ", rpbuf[i].rp_portname);
> 

-- 
:wq Claudio

Reply via email to