[systemd-devel] [PATCH v2 05/26] dhcp: Add option appending and parsing

Lennart Poettering lennart at poettering.net
Wed Nov 27 12:25:33 PST 2013


On Wed, 27.11.13 16:51, Patrik Flykt (Patrik.Flykt at linux.intel.com) wrote:

> On Tue, 2013-11-26 at 00:08 +0100, Lennart Poettering wrote:
> > On Mon, 25.11.13 09:13, Patrik Flykt (patrik.flykt at linux.intel.com) wrote:
> > 
> > > +#include <stdint.h>
> > > +
> > > +#include "protocol.h"
> > > +
> > > +int dhcp_option_append(uint8_t **buf, int *buflen, uint8_t code,
> > 
> >                                          ^^^^
> > 
> > This is a memory size, right? It should be size_t rather than int, then, no?
> 
> size_t it is.
> 
> > > +static int parse_options(uint8_t *buf, int32_t buflen, int *overload,
> > 
> >                             ^^^^^^ const missing?
> 
> Here the idea was to go over the whole buffer and calling the callback
> with the proper code, len and value. Start of 'buf', i.e. 'code' in the
> function, needs to be advanced to the next option, so its not a const
> value.

The "const" in "const uint8_t *buf" declares that the buffer this points
*to* is constant, not the pointer itself. You are welcome to alter the
pointer as much as you want if you do this. Note the difference between
"const uint8_t * buf" and "uint8_t * const buf"...

The latter makes little sense, but the former makes a lot of sense.

A function declared as 

  void foo(const int a);

makes little sense, as this just means that the function internally
won't change the internal copy of a, which is pretty useless
information. 

  void foo(const int *a);

however makes a ton of sense, since it indicates that the buffer passed
in won't be changed, while the function can do whatever it likes with
the pointer copy it got internally...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list