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