1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright (C) 1993-2001 by Darren Reed. 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 5*0Sstevel@tonic-gate * 6*0Sstevel@tonic-gate * $Id: portname.c,v 1.6 2002/01/28 06:50:47 darrenr Exp $ 7*0Sstevel@tonic-gate */ 8*0Sstevel@tonic-gate #include "ipf.h" 9*0Sstevel@tonic-gate 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate char *portname(pr, port) 12*0Sstevel@tonic-gate int pr, port; 13*0Sstevel@tonic-gate { 14*0Sstevel@tonic-gate static char buf[32]; 15*0Sstevel@tonic-gate struct protoent *p = NULL; 16*0Sstevel@tonic-gate struct servent *sv = NULL, *sv1 = NULL; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate if (pr == -1) { 19*0Sstevel@tonic-gate if ((sv = getservbyport(htons(port), "tcp"))) { 20*0Sstevel@tonic-gate strncpy(buf, sv->s_name, sizeof(buf)-1); 21*0Sstevel@tonic-gate buf[sizeof(buf)-1] = '\0'; 22*0Sstevel@tonic-gate sv1 = getservbyport(htons(port), "udp"); 23*0Sstevel@tonic-gate sv = strncasecmp(buf, sv->s_name, strlen(buf)) ? 24*0Sstevel@tonic-gate NULL : sv1; 25*0Sstevel@tonic-gate } 26*0Sstevel@tonic-gate if (sv) 27*0Sstevel@tonic-gate return buf; 28*0Sstevel@tonic-gate } else if ((pr != -2) && (p = getprotobynumber(pr))) { 29*0Sstevel@tonic-gate if ((sv = getservbyport(htons(port), p->p_name))) { 30*0Sstevel@tonic-gate strncpy(buf, sv->s_name, sizeof(buf)-1); 31*0Sstevel@tonic-gate buf[sizeof(buf)-1] = '\0'; 32*0Sstevel@tonic-gate return buf; 33*0Sstevel@tonic-gate } 34*0Sstevel@tonic-gate } 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate (void) sprintf(buf, "%d", port); 37*0Sstevel@tonic-gate return buf; 38*0Sstevel@tonic-gate } 39