17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (C) 1993-2001 by Darren Reed. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 57c478bd9Sstevel@tonic-gate * 6*ab25eeb5Syz155240 * $Id: ports.c,v 1.9.4.1 2004/12/09 19:41:22 darrenr Exp $ 77c478bd9Sstevel@tonic-gate */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate #include <ctype.h> 107c478bd9Sstevel@tonic-gate 117c478bd9Sstevel@tonic-gate #include "ipf.h" 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate /* 157c478bd9Sstevel@tonic-gate * check for possible presence of the port fields in the line 167c478bd9Sstevel@tonic-gate */ 177c478bd9Sstevel@tonic-gate int ports(seg, proto, pp, cp, tp, linenum) 187c478bd9Sstevel@tonic-gate char ***seg; 197c478bd9Sstevel@tonic-gate char *proto; 207c478bd9Sstevel@tonic-gate u_short *pp; 217c478bd9Sstevel@tonic-gate int *cp; 227c478bd9Sstevel@tonic-gate u_short *tp; 237c478bd9Sstevel@tonic-gate int linenum; 247c478bd9Sstevel@tonic-gate { 257c478bd9Sstevel@tonic-gate int comp = -1; 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate if (!*seg || !**seg || !***seg) 287c478bd9Sstevel@tonic-gate return 0; 297c478bd9Sstevel@tonic-gate if (!strcasecmp(**seg, "port") && *(*seg + 1) && *(*seg + 2)) { 307c478bd9Sstevel@tonic-gate (*seg)++; 31*ab25eeb5Syz155240 if (ISALNUM(***seg) && *(*seg + 2)) { 327c478bd9Sstevel@tonic-gate if (portnum(**seg, proto, pp, linenum) == 0) 337c478bd9Sstevel@tonic-gate return -1; 347c478bd9Sstevel@tonic-gate (*seg)++; 357c478bd9Sstevel@tonic-gate if (!strcmp(**seg, "<>")) 367c478bd9Sstevel@tonic-gate comp = FR_OUTRANGE; 377c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, "><")) 387c478bd9Sstevel@tonic-gate comp = FR_INRANGE; 397c478bd9Sstevel@tonic-gate else { 407c478bd9Sstevel@tonic-gate fprintf(stderr, 417c478bd9Sstevel@tonic-gate "%d: unknown range operator (%s)\n", 427c478bd9Sstevel@tonic-gate linenum, **seg); 437c478bd9Sstevel@tonic-gate return -1; 447c478bd9Sstevel@tonic-gate } 457c478bd9Sstevel@tonic-gate (*seg)++; 467c478bd9Sstevel@tonic-gate if (**seg == NULL) { 477c478bd9Sstevel@tonic-gate fprintf(stderr, "%d: missing 2nd port value\n", 487c478bd9Sstevel@tonic-gate linenum); 497c478bd9Sstevel@tonic-gate return -1; 507c478bd9Sstevel@tonic-gate } 517c478bd9Sstevel@tonic-gate if (portnum(**seg, proto, tp, linenum) == 0) 527c478bd9Sstevel@tonic-gate return -1; 537c478bd9Sstevel@tonic-gate } else if (!strcmp(**seg, "=") || !strcasecmp(**seg, "eq")) 547c478bd9Sstevel@tonic-gate comp = FR_EQUAL; 557c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, "!=") || !strcasecmp(**seg, "ne")) 567c478bd9Sstevel@tonic-gate comp = FR_NEQUAL; 577c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, "<") || !strcasecmp(**seg, "lt")) 587c478bd9Sstevel@tonic-gate comp = FR_LESST; 597c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, ">") || !strcasecmp(**seg, "gt")) 607c478bd9Sstevel@tonic-gate comp = FR_GREATERT; 617c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, "<=") || !strcasecmp(**seg, "le")) 627c478bd9Sstevel@tonic-gate comp = FR_LESSTE; 637c478bd9Sstevel@tonic-gate else if (!strcmp(**seg, ">=") || !strcasecmp(**seg, "ge")) 647c478bd9Sstevel@tonic-gate comp = FR_GREATERTE; 657c478bd9Sstevel@tonic-gate else { 667c478bd9Sstevel@tonic-gate fprintf(stderr, "%d: unknown comparator (%s)\n", 677c478bd9Sstevel@tonic-gate linenum, **seg); 687c478bd9Sstevel@tonic-gate return -1; 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate if (comp != FR_OUTRANGE && comp != FR_INRANGE) { 717c478bd9Sstevel@tonic-gate (*seg)++; 727c478bd9Sstevel@tonic-gate if (portnum(**seg, proto, pp, linenum) == 0) 737c478bd9Sstevel@tonic-gate return -1; 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate *cp = comp; 767c478bd9Sstevel@tonic-gate (*seg)++; 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate return 0; 797c478bd9Sstevel@tonic-gate } 80