141edb306SCy Schubert
241edb306SCy Schubert /*
341edb306SCy Schubert * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert *
541edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert *
741edb306SCy Schubert * $Id$
841edb306SCy Schubert */
941edb306SCy Schubert
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert
1241edb306SCy Schubert
13efeb8bffSCy Schubert u_32_t
buildopts(char * cp,char * op,int len)14efeb8bffSCy Schubert buildopts(char *cp, char *op, int len)
1541edb306SCy Schubert {
1641edb306SCy Schubert struct ipopt_names *io;
1741edb306SCy Schubert u_32_t msk = 0;
1841edb306SCy Schubert char *s, *t;
1941edb306SCy Schubert int inc;
2041edb306SCy Schubert
2141edb306SCy Schubert for (s = strtok(cp, ","); s; s = strtok(NULL, ",")) {
2241edb306SCy Schubert if ((t = strchr(s, '=')))
2341edb306SCy Schubert *t++ = '\0';
2441edb306SCy Schubert else
2541edb306SCy Schubert t = "";
2641edb306SCy Schubert for (io = ionames; io->on_name; io++) {
2741edb306SCy Schubert if (strcasecmp(s, io->on_name) || (msk & io->on_bit))
2841edb306SCy Schubert continue;
2941edb306SCy Schubert if ((inc = addipopt(op, io, len, t))) {
3041edb306SCy Schubert op += inc;
3141edb306SCy Schubert len += inc;
3241edb306SCy Schubert }
3341edb306SCy Schubert msk |= io->on_bit;
3441edb306SCy Schubert break;
3541edb306SCy Schubert }
3641edb306SCy Schubert if (!io->on_name) {
3741edb306SCy Schubert fprintf(stderr, "unknown IP option name %s\n", s);
38*2582ae57SCy Schubert return (0);
3941edb306SCy Schubert }
4041edb306SCy Schubert }
4141edb306SCy Schubert while ((len & 3) != 3) {
4241edb306SCy Schubert *op++ = IPOPT_NOP;
4341edb306SCy Schubert len++;
4441edb306SCy Schubert }
4541edb306SCy Schubert *op++ = IPOPT_EOL;
4641edb306SCy Schubert len++;
47*2582ae57SCy Schubert return (len);
4841edb306SCy Schubert }
49