Home | History | Annotate | Line # | Download | only in lib
      1  1.2   darrenr /*	$NetBSD: addipopt.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.2   darrenr  * Copyright (C) 2012 by Darren Reed.
      5  1.1  christos  *
      6  1.1  christos  * See the IPFILTER.LICENCE file for details on licencing.
      7  1.1  christos  *
      8  1.2   darrenr  * Id: addipopt.c,v 1.1.1.2 2012/07/22 13:44:38 darrenr Exp $
      9  1.1  christos  */
     10  1.1  christos 
     11  1.1  christos #include "ipf.h"
     12  1.1  christos 
     13  1.1  christos 
     14  1.1  christos int addipopt(op, io, len, class)
     15  1.1  christos 	char *op;
     16  1.1  christos 	struct ipopt_names *io;
     17  1.1  christos 	int len;
     18  1.1  christos 	char *class;
     19  1.1  christos {
     20  1.1  christos 	int olen = len;
     21  1.1  christos 	struct in_addr ipadr;
     22  1.1  christos 	u_short val;
     23  1.1  christos 	u_char lvl;
     24  1.1  christos 	char *s;
     25  1.1  christos 
     26  1.1  christos 	if ((len + io->on_siz) > 48) {
     27  1.1  christos 		fprintf(stderr, "options too long\n");
     28  1.1  christos 		return 0;
     29  1.1  christos 	}
     30  1.1  christos 	len += io->on_siz;
     31  1.1  christos 	*op++ = io->on_value;
     32  1.1  christos 	if (io->on_siz > 1) {
     33  1.1  christos 		s = op;
     34  1.1  christos 		*op++ = io->on_siz;
     35  1.1  christos 		*op++ = IPOPT_MINOFF;
     36  1.1  christos 
     37  1.1  christos 		if (class) {
     38  1.1  christos 			switch (io->on_value)
     39  1.1  christos 			{
     40  1.1  christos 			case IPOPT_SECURITY :
     41  1.1  christos 				lvl = seclevel(class);
     42  1.1  christos 				*(op - 1) = lvl;
     43  1.1  christos 				break;
     44  1.1  christos 			case IPOPT_RR :
     45  1.1  christos 			case IPOPT_TS :
     46  1.1  christos 				s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4;
     47  1.1  christos 				break;
     48  1.1  christos 			case IPOPT_LSRR :
     49  1.1  christos 			case IPOPT_SSRR :
     50  1.1  christos 				ipadr.s_addr = inet_addr(class);
     51  1.1  christos 				s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4;
     52  1.1  christos 				bcopy((char *)&ipadr, op, sizeof(ipadr));
     53  1.1  christos 				break;
     54  1.1  christos 			case IPOPT_SATID :
     55  1.1  christos 				val = atoi(class);
     56  1.1  christos 				bcopy((char *)&val, op, 2);
     57  1.1  christos 				break;
     58  1.1  christos 			}
     59  1.1  christos 		}
     60  1.1  christos 	}
     61  1.1  christos 	if (opts & OPT_DEBUG)
     62  1.1  christos 		fprintf(stderr, "bo: %s %d %#x: %d\n",
     63  1.1  christos 			io->on_name, io->on_value, io->on_bit, len);
     64  1.1  christos 	return len - olen;
     65  1.1  christos }
     66