Exemplo n.º 1
0
struct protoent* _getprotobynumber(int number)
{
	struct protoent* proto;

	proto = getprotobynumber(number);

	return proto;
}
Exemplo n.º 2
0
struct protoent *
win32_getprotobynumber(int num)
{
    struct protoent *r;

    SOCKET_TEST(r = getprotobynumber(num), NULL);
    return r;
}
Exemplo n.º 3
0
Arquivo: pfs.c Projeto: ryo/netbsd-src
static void
display_states(const struct pfioc_states *ps, int verbose __unused, FILE* f)
{
    struct pfsync_state *p = NULL;
    struct pfsync_state_peer *src, *dst;
    struct protoent *proto;
    int nb_states;
    int i;
    uint64_t id;

    p = ps->ps_states;
    nb_states = ps->ps_len / sizeof(struct pfsync_state);

    for (i = 0; i < nb_states; i++, p++) {
        fprintf(f, "state %s ", p->direction == PF_OUT ? "out" : "in");
        fprintf(f, "on %s ", p->ifname);

        if ((proto = getprotobynumber(p->proto)) != NULL)
            fprintf(f, "proto %s ", proto->p_name);
        else
            fprintf(f, "proto %u ", p->proto);


        if (PF_ANEQ(&p->lan.addr, &p->gwy.addr, p->af) ||
                (p->lan.port != p->gwy.port)) {

            char buf1[64], buf2[64], buf3[64];
            fprintf(f, "from %s to %s using %s",
                    print_host(&p->lan, p->af, buf1, sizeof(buf1)),
                    print_host(&p->ext, p->af, buf2, sizeof(buf2)),
                    print_host(&p->gwy, p->af, buf3, sizeof(buf3)));
        } else {
            char buf1[64], buf2[64];
            fprintf(f, "from %s to %s",
                    print_host(&p->lan, p->af, buf1, sizeof(buf1)),
                    print_host(&p->ext, p->af, buf2, sizeof(buf2)));
        }

        memcpy(&id, p->id, sizeof(p->id));
        fprintf(f, " id %" PRIu64 " cid %" PRIu32 " expire %" PRIu32 " timeout %" PRIu8,
                id , p->creatorid, p->expire, p->timeout);

        if (p->direction == PF_OUT) {
            src = &p->src;
            dst = &p->dst;
        } else {
            src = &p->dst;
            dst = &p->src;
        }

        fprintf(f, " src ");
        print_peer(src, p->proto, f);
        fprintf(f, " dst ");
        print_peer(dst, p->proto, f);

        fprintf(f, "\n");
    }
}
Exemplo n.º 4
0
/**
 * sim_db_insert_host_service:
 *
 * Insert 'host service' in @databse
 */
void
sim_db_insert_host_service (SimDatabase   *database,
                            SimInet       *inet,
                            gchar         *date,
                            gint           port,
                            gint           protocol,
                            SimInet       *sensor,
                            gchar         *interface,
                            gchar         *service,
                            gchar         *application,
                            SimUuid       *context_id)
{
    gchar           *query;
    gint             plugin_id;
    struct servent  *temp_serv  = NULL;
    struct protoent *temp_proto = NULL;

    g_return_if_fail (SIM_IS_DATABASE (database));
    g_return_if_fail (SIM_IS_INET (inet));
    g_return_if_fail (date);
    g_return_if_fail (port >= 0); /* Needed for ints */
    g_return_if_fail (protocol >= 0);
    g_return_if_fail (sensor);
    g_return_if_fail (service);
    g_return_if_fail (application);


    temp_proto = getprotobynumber (protocol);
    if (temp_proto->p_name == NULL)
        return; /* Since we don't know the proto we wont insert a service without a protocol */

    temp_serv = getservbyport (port, temp_proto->p_name);

    query = g_strdup_printf ("INSERT INTO host_services "
                             "(id, date, port, protocol, service, service_type, version, origin, sensor, interface, ctx) "
                             "SELECT id, '%s', %u, %u, '%s', '%s', '%s', 0, %s, '%s', %s "
                             "FROM host WHERE ip = %s and ctx = %s LIMIT 1",
                             date,
                             port,
                             protocol,
                             (temp_serv != NULL) ? temp_serv->s_name : "unknown",
                             service,
                             application,
                             sim_inet_get_db_string (sensor),
                             interface,
                             sim_uuid_get_db_string (context_id),
                             sim_inet_get_db_string (inet),
                             sim_uuid_get_db_string (context_id));

    sim_db_execute_query (database, query);

    g_free (query);

    plugin_id = SIM_PLUGIN_SERVICE;

    sim_db_insert_host_plugin_sid (database, inet, plugin_id, port, context_id);
}
Exemplo n.º 5
0
Variant f_getprotobynumber(int number) {
    Lock lock(NetworkMutex);

    struct protoent *ent = getprotobynumber(number);
    if (ent == NULL) {
        return false;
    }
    return String(ent->p_name, CopyString);
}
Exemplo n.º 6
0
void
show_proto(ipfw_insn *cmd, int show_or)
{
	struct protoent *pe;
	u_char proto = 0;
	proto = cmd->arg1;
	pe = getprotobynumber(cmd->arg1);
	printf(" %s", pe->p_name);
}
Exemplo n.º 7
0
/*
 * Like strtol, but also translates service names into port numbers
 * for some protocols.
 * In particular:
 *	proto == -1 disables the protocol check;
 *	proto == IPPROTO_ETHERTYPE looks up an internal table
 *	proto == <some value in /etc/protocols> matches the values there.
 * Returns *end == s in case the parameter is not found.
 */
static int
strtoport(char *s, char **end, int base, int proto)
{
	char *p, *buf;
	char *s1;
	int i;

	*end = s; 		/* default - not found */
	if ( *s == '\0')
		return 0; 	/* not found */

	if (isdigit(*s))
		return strtol(s, end, base);

	/*
	 * find separator. '\\' escapes the next char.
	 */
	for (s1 = s; *s1 && (isalnum(*s1) || *s1 == '\\') ; s1++) {
		if (*s1 == '\\' && s1[1] != '\0')
			s1++;
	}

	buf = malloc(s1 - s + 1);
	if (buf == NULL)
		return 0;

	/*
	 * copy into a buffer skipping backslashes
	 */
	for (p = s, i = 0; p != s1 ; p++)
		if ( *p != '\\')
			buf[i++] = *p;
	buf[i++] = '\0';

	if (proto == IPPROTO_ETHERTYPE) {
		i = match_token(ether_types, buf);
		free(buf);
		if (i != -1) {	/* found */
			*end = s1;
			return i;
		}
	} else {
		struct protoent *pe = NULL;
		struct servent *se;

		if (proto != 0)
			pe = getprotobynumber(proto);
		setservent(1);
		se = getservbyname(buf, pe ? pe->p_name : NULL);
		free(buf);
		if (se != NULL) {
			*end = s1;
			return ntohs(se->s_port);
		}
	}
	return 0; 	/* not found */
}
Exemplo n.º 8
0
static char *
proto_type (char *xb, int proto) 
{
	struct protoent *p;
	char *tb = !(p = getprotobynumber(proto)) ? "unknown" : p->p_name;
	endprotoent();
	sprintf(xb, "%s", tb);
	return xb;
}
Exemplo n.º 9
0
Variant HHVM_FUNCTION(getprotobynumber, int64_t number) {
    Lock lock(NetworkMutex);

    struct protoent *ent = getprotobynumber(number);
    if (ent == NULL) {
        return false;
    }
    return String(ent->p_name, CopyString);
}
Exemplo n.º 10
0
static void brip_print(const void *ip, const struct xt_entry_match *match,
		       int numeric)
{
	struct ebt_ip_info *info = (struct ebt_ip_info *)match->data;
	struct in_addr *addrp, *maskp;

	if (info->bitmask & EBT_IP_SOURCE) {
		printf("--ip-src ");
		if (info->invflags & EBT_IP_SOURCE)
			printf("! ");
		addrp = (struct in_addr *)&info->saddr;
		maskp = (struct in_addr *)&info->smsk;
		printf("%s%s ", xtables_ipaddr_to_numeric(addrp),
		       xtables_ipmask_to_numeric(maskp));
	}
	if (info->bitmask & EBT_IP_DEST) {
		printf("--ip-dst ");
		if (info->invflags & EBT_IP_DEST)
			printf("! ");
		addrp = (struct in_addr *)&info->daddr;
		maskp = (struct in_addr *)&info->dmsk;
		printf("%s%s ", xtables_ipaddr_to_numeric(addrp),
		       xtables_ipmask_to_numeric(maskp));
	}
	if (info->bitmask & EBT_IP_TOS) {
		printf("--ip-tos ");
		if (info->invflags & EBT_IP_TOS)
			printf("! ");
		printf("0x%02X ", info->tos);
	}
	if (info->bitmask & EBT_IP_PROTO) {
		struct protoent *pe;

		printf("--ip-proto ");
		if (info->invflags & EBT_IP_PROTO)
			printf("! ");
		pe = getprotobynumber(info->protocol);
		if (pe == NULL) {
			printf("%d ", info->protocol);
		} else {
			printf("%s ", pe->p_name);
		}
	}
	if (info->bitmask & EBT_IP_SPORT) {
		printf("--ip-sport ");
		if (info->invflags & EBT_IP_SPORT)
			printf("! ");
		print_port_range(info->sport);
	}
	if (info->bitmask & EBT_IP_DPORT) {
		printf("--ip-dport ");
		if (info->invflags & EBT_IP_DPORT)
			printf("! ");
		print_port_range(info->dport);
	}
}
Exemplo n.º 11
0
static void print(const struct ebt_u_entry *entry,
   const struct ebt_entry_match *match)
{
	struct ebt_ip_info *ipinfo = (struct ebt_ip_info *)match->data;
	int j;

	if (ipinfo->bitmask & EBT_IP_SOURCE) {
		printf("--ip-src ");
		if (ipinfo->invflags & EBT_IP_SOURCE)
			printf("! ");
		for (j = 0; j < 4; j++)
			printf("%d%s",((unsigned char *)&ipinfo->saddr)[j],
			   (j == 3) ? "" : ".");
		printf("%s ", ebt_mask_to_dotted(ipinfo->smsk));
	}
	if (ipinfo->bitmask & EBT_IP_DEST) {
		printf("--ip-dst ");
		if (ipinfo->invflags & EBT_IP_DEST)
			printf("! ");
		for (j = 0; j < 4; j++)
			printf("%d%s", ((unsigned char *)&ipinfo->daddr)[j],
			   (j == 3) ? "" : ".");
		printf("%s ", ebt_mask_to_dotted(ipinfo->dmsk));
	}
	if (ipinfo->bitmask & EBT_IP_TOS) {
		printf("--ip-tos ");
		if (ipinfo->invflags & EBT_IP_TOS)
			printf("! ");
		printf("0x%02X ", ipinfo->tos);
	}
	if (ipinfo->bitmask & EBT_IP_PROTO) {
		struct protoent *pe;

		printf("--ip-proto ");
		if (ipinfo->invflags & EBT_IP_PROTO)
			printf("! ");
		pe = getprotobynumber(ipinfo->protocol);
		if (pe == NULL) {
			printf("%d ", ipinfo->protocol);
		} else {
			printf("%s ", pe->p_name);
		}
	}
	if (ipinfo->bitmask & EBT_IP_SPORT) {
		printf("--ip-sport ");
		if (ipinfo->invflags & EBT_IP_SPORT)
			printf("! ");
		print_port_range(ipinfo->sport);
	}
	if (ipinfo->bitmask & EBT_IP_DPORT) {
		printf("--ip-dport ");
		if (ipinfo->invflags & EBT_IP_DPORT)
			printf("! ");
		print_port_range(ipinfo->dport);
	}
}
Exemplo n.º 12
0
Arquivo: sock.c Projeto: udhos/nepim
static const char *proto_name(int proto)
{
  struct protoent *pe;

  pe = getprotobynumber(proto);
  if (pe)
    return pe->p_name;

  return "unknown_protocol";
}
Exemplo n.º 13
0
int main(int argc, char** argv)
{
   if( argc != 2)
   {
       printf("usage: getprotobynumber prot\n");
       return 1;
   }
   struct protoent prot;
   memcpy(&prot, getprotobynumber((int)atoi(argv[1])), sizeof(prot));
   printf("name:%s\n prot: %d\n", prot.p_name, prot.p_proto);
}
Exemplo n.º 14
0
static void print_proto(char *prefix, u_int8_t proto, int numeric)
{
	struct protoent *p = NULL;

	printf("%sproto ", prefix);
	if (!numeric)
		p = getprotobynumber(proto);
	if (p != NULL)
		printf("%s ", p->p_name);
	else
		printf("%u ", proto);
}
Exemplo n.º 15
0
// Return the corresponding string that matches the numeric protocol (if any).
static int __lua_p_name(lua_State *L)
{
    struct protoent *pe;
    const char *proto = luaL_checkstring(L, 1);

    if((pe = getprotobynumber(atoi(proto))))
        lua_pushstring(L, pe->p_name);
    else
        lua_pushstring(L, proto);

    return 1;
}
Exemplo n.º 16
0
char *nl_ip_proto2str(int proto, char *buf, size_t len)
{
	struct protoent *p = getprotobynumber(proto);

	if (p) {
		snprintf(buf, len, "%s", p->p_name);
		return buf;
	}

	snprintf(buf, len, "0x%x", proto);
	return buf;
}
Exemplo n.º 17
0
void
print_rdr(struct pf_rdr *r)
{
    if (r->no)
        printf("no ");
    printf("rdr ");
    if (r->ifname[0]) {
        printf("on ");
        if (r->ifnot)
            printf("! ");
        printf("%s ", r->ifname);
    }
    if (r->proto) {
        struct protoent *p = getprotobynumber(r->proto);
        if (p != NULL)
            printf("proto %s ", p->p_name);
        else
            printf("proto %u ", r->proto);
    }
    printf("from ");
    if (!PF_AZERO(&r->saddr, r->af) || !PF_AZERO(&r->smask, r->af)) {
        if (r->snot)
            printf("! ");
        print_addr(&r->saddr, &r->smask, r->af);
        printf(" ");
    } else
        printf("any ");
    printf("to ");
    if (!PF_AZERO(&r->daddr, r->af) || !PF_AZERO(&r->dmask, r->af)) {
        if (r->dnot)
            printf("! ");
        print_addr(&r->daddr, &r->dmask, r->af);
        printf(" ");
    } else
        printf("any ");
    if (r->dport) {
        printf("port %u", ntohs(r->dport));
        if (r->opts & PF_DPORT_RANGE)
            printf(":%u", ntohs(r->dport2));
    }
    if (!r->no) {
        printf(" -> ");
        print_addr(&r->raddr, NULL, r->af);
        printf(" ");
        if (r->rport) {
            printf("port %u", ntohs(r->rport));
            if (r->opts & PF_RPORT_RANGE)
                printf(":*");
        }
    }
    printf("\n");
}
Exemplo n.º 18
0
/*
 * getinetproto --
 *	print name of protocol number
 */
void
getinetproto(int number)
{
    static int isopen;
    struct protoent *pe;

    if (!isopen)
        setprotoent(++isopen);
    if ((pe = getprotobynumber(number)) != NULL)
        printf(" %s", pe->p_name);
    else
        printf(" %d", number);
}
Exemplo n.º 19
0
void manejador(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
	protoent *protocolo;
	iphdr *datagrama;
	ether_header *trama;
	tcphdr *cabecera_tcp;

	struct mi_cabecera_tcp *ptr_paquetes_aux;
	int i;

	trama=(ether_header *)(pkt_data);

	if(ntohs(trama->ether_type) == ETHERTYPE_IP)  //IP¿?
	{		
		datagrama=(iphdr *)(pkt_data+sizeof(ether_header));

		protocolo = getprotobynumber(datagrama->protocol);

		if(protocolo!=0 && !strcmp(protocolo->p_name, "tcp")) //tcp¿?
		{
			cabecera_tcp = (tcphdr *) (pkt_data+sizeof(ether_header)+sizeof(iphdr));

			//Reservo memoria en bloques de 10 paquetes
			if (num_paquetes%10==0)
			{
				ptr_paquetes_aux = ptr_paquetes;

				ptr_paquetes = (mi_cabecera_tcp *)malloc(sizeof(mi_cabecera_tcp)*(num_paquetes+10));

				for (i=0;i<num_paquetes;i++)
					ptr_paquetes[i] = ptr_paquetes_aux[i];

				if (num_paquetes>0) free(ptr_paquetes_aux);
			}

			//Añado al vector los paquetes TCP
			ptr_paquetes[num_paquetes].ip1 = (dir_ip) ntohl(datagrama->saddr);
			ptr_paquetes[num_paquetes].ip2 = (dir_ip) ntohl(datagrama->daddr);
			ptr_paquetes[num_paquetes].puerto1 = (puerto) ntohs(cabecera_tcp->source);
			ptr_paquetes[num_paquetes].puerto2 = (puerto) ntohs(cabecera_tcp->dest);
			ptr_paquetes[num_paquetes].seq = (num_seq_ack) ntohl(cabecera_tcp->seq);
			ptr_paquetes[num_paquetes].ack = (num_seq_ack) ntohl(cabecera_tcp->ack_seq);

			#ifdef DEBUG
			mostrar_paquete_tcp(&ptr_paquetes[num_paquetes]);
			#endif

			num_paquetes++;
		}
	}
}
Exemplo n.º 20
0
static void print(const struct ebt_u_entry *entry,
   const struct ebt_entry_match *match)
{
	struct ebt_ip6_info *ipinfo = (struct ebt_ip6_info *)match->data;

	if (ipinfo->bitmask & EBT_IP6_SOURCE) {
		printf("--ip6-src ");
		if (ipinfo->invflags & EBT_IP6_SOURCE)
			printf("! ");
		printf("%s", ebt_ip6_to_numeric(&ipinfo->saddr));
		printf("/%s ", ebt_ip6_to_numeric(&ipinfo->smsk));
	}
	if (ipinfo->bitmask & EBT_IP6_DEST) {
		printf("--ip6-dst ");
		if (ipinfo->invflags & EBT_IP6_DEST)
			printf("! ");
		printf("%s", ebt_ip6_to_numeric(&ipinfo->daddr));
		printf("/%s ", ebt_ip6_to_numeric(&ipinfo->dmsk));
	}
	if (ipinfo->bitmask & EBT_IP6_TCLASS) {
		printf("--ip6-tclass ");
		if (ipinfo->invflags & EBT_IP6_TCLASS)
			printf("! ");
		printf("0x%02X ", ipinfo->tclass);
	}
	if (ipinfo->bitmask & EBT_IP6_PROTO) {
		struct protoent *pe;

		printf("--ip6-proto ");
		if (ipinfo->invflags & EBT_IP6_PROTO)
			printf("! ");
		pe = getprotobynumber(ipinfo->protocol);
		if (pe == NULL) {
			printf("%d ", ipinfo->protocol);
		} else {
			printf("%s ", pe->p_name);
		}
	}
	if (ipinfo->bitmask & EBT_IP6_SPORT) {
		printf("--ip6-sport ");
		if (ipinfo->invflags & EBT_IP6_SPORT)
			printf("! ");
		print_port_range(ipinfo->sport);
	}
	if (ipinfo->bitmask & EBT_IP6_DPORT) {
		printf("--ip6-dport ");
		if (ipinfo->invflags & EBT_IP6_DPORT)
			printf("! ");
		print_port_range(ipinfo->dport);
	}
}
Exemplo n.º 21
0
void print_proto(uint16_t proto, int invert)
{
	const struct protoent *pent = getprotobynumber(proto);

	if (invert)
		printf("! ");

	if (pent) {
		printf("-p %s ", pent->p_name);
		return;
	}

	printf("-p %u ", proto);
}
Exemplo n.º 22
0
XPCGetProtocol::XPCGetProtocol(int _iProtocol)
{
#ifdef UNIX
        cIteratorFlag = 0;
#endif
        // Retrieves the protocol structure by number
        protocolPtr = getprotobynumber(_iProtocol);
        if (protocolPtr == NULL)
        {
              XPCException exceptObject("Could Not Get Protocol By Number");
              throw exceptObject;
              return;
        }
}
Exemplo n.º 23
0
const char *strxf_proto(__u8 proto)
{
	static char buf[32];
	struct protoent *pp;
	const char *p;

	pp = getprotobynumber(proto);
	if (pp)
		p = pp->p_name;
	else {
		sprintf(buf, "%u", proto);
		p = buf;
	}

	return p;
}
Exemplo n.º 24
0
void printAiProto(int p)
{
	struct protoent * pe;
	char ** sp;

	pe = getprotobynumber(p);

	printf("%s", pe->p_name);

	if (*(pe->p_aliases) != NULL)
		printf(" (");
	for (sp = pe->p_aliases; *sp != NULL; sp++)
		printf("%s%s", *sp, (*(sp+1) != NULL ? ", " : ""));
	if (*(pe->p_aliases) != NULL)
		printf(")");
}
Exemplo n.º 25
0
Arquivo: types.c Projeto: hsiboy/ida
static int idsa_ipport_print(IDSA_UNIT * u, char *s, int l, int m)
{
  int x[2];
  int y;
  struct protoent *pe;
  struct servent *se;
  char *sp, *pp;
  char sb[NBUFFER], pb[NBUFFER];

  memcpy(&x, u->u_ptr, 2 * sizeof(int));

  if (m < 100) {
    y = snprintf(s, l, "%d/%d", x[0], x[1]);
    return (y > l) ? (-1) : y;
  }

  pe = getprotobynumber(x[0]);
  if (pe) {
    pp = pe->p_name;
  } else {
    snprintf(pb, NBUFFER, "%d", x[0]);
    pp = pb;
  }

  se = getservbyport(htons(x[1]), pp);
  if (se) {
    sp = se->s_name;
  } else {
    snprintf(sb, NBUFFER, "%d", x[1]);
    sp = sb;
  }

  y = snprintf(s, l, "%s/%s", pp, sp);
  if (y > l) {
    return -1;
  }

  switch (m - 100) {
  case ESCAPE_UNIX:
    return idsa_escape_unix(s, y, l);
  case ESCAPE_XML:
    return idsa_escape_xml(s, y, l);
  default:
    return y;
  }

}
Exemplo n.º 26
0
static void
doShowFilter(struct filterent *fp, struct prompt *prompt)
{
  struct protoent *pe;
  int n;

  for (n = 0; n < MAXFILTERS; n++, fp++) {
    if (fp->f_action != A_NONE) {
      prompt_Printf(prompt, "  %2d %s", n, filter_Action2Nam(fp->f_action));
      prompt_Printf(prompt, "%c ", fp->f_invert ? '!' : ' ');

      if (ncprange_isset(&fp->f_src))
        prompt_Printf(prompt, "%s ", addrstr(&fp->f_src, fp->f_srctype));
      else
        prompt_Printf(prompt, "any ");

      if (ncprange_isset(&fp->f_dst))
        prompt_Printf(prompt, "%s ", addrstr(&fp->f_dst, fp->f_dsttype));
      else
        prompt_Printf(prompt, "any ");

      if (fp->f_proto) {
        if ((pe = getprotobynumber(fp->f_proto)) == NULL)
	  prompt_Printf(prompt, "P:%d", fp->f_proto);
        else
	  prompt_Printf(prompt, "%s", pe->p_name);

	if (fp->f_srcop)
	  prompt_Printf(prompt, " src %s %d", filter_Op2Nam(fp->f_srcop),
		  fp->f_srcport);
	if (fp->f_dstop)
	  prompt_Printf(prompt, " dst %s %d", filter_Op2Nam(fp->f_dstop),
		  fp->f_dstport);
	if (fp->f_estab)
	  prompt_Printf(prompt, " estab");
	if (fp->f_syn)
	  prompt_Printf(prompt, " syn");
	if (fp->f_finrst)
	  prompt_Printf(prompt, " finrst");
      } else
	prompt_Printf(prompt, "all");
      if (fp->timeout != 0)
	  prompt_Printf(prompt, " timeout %u", fp->timeout);
      prompt_Printf(prompt, "\n");
    }
  }
}
Exemplo n.º 27
0
/* *********************************************************************** */
int NPSL_GetProtoByNumberBasic(int proto_number, NPSL_PROTOENT *proto_ent_ptr,
	void *proto_ent_buffer_ptr, unsigned int proto_ent_buffer_length,
	unsigned int *required_length, char *error_text)
{
	int            return_code = NPSL_SUCCESS;
	NPSL_PROTOENT *tmp_ent_ptr;

	if (required_length != NULL)
		*required_length = 0;

	if ((return_code = NPSL_CheckProtoEntParams(proto_ent_ptr,
		proto_ent_buffer_ptr, proto_ent_buffer_length, error_text)) !=
		NPSL_SUCCESS)
		;
	else {
#if NPSL_HAS_GETPROTOBYPORT_R
		if ((tmp_ent_ptr = getprotobynumber_r(proto_number, proto_ent_ptr,
			proto_ent_buffer_ptr, ((int) proto_ent_buffer_length))) == NULL) {
			if (error_text != NULL) {
				sprintf(error_text,
					"%s '%s()' for protocol number '%d': ",
					"Unable to get protocol entry with", "getprotobynumber_r",
					proto_number);
				NPSL_AppendLastErrorString(0, NPSL_MAX_ERROR_TEXT, error_text);
			}
			return_code = NPSL_SUPP_MapLastError();
		}
#else
		if ((tmp_ent_ptr = getprotobynumber(proto_number)) == NULL) {
			if (error_text != NULL) {
				sprintf(error_text,
					"%s '%s()' for protocol number '%d': ",
					"Unable to get protocol entry with", "getprotobynumber",
					proto_number);
				NPSL_AppendLastErrorString(0, NPSL_MAX_ERROR_TEXT, error_text);
			}
			return_code = NPSL_SUPP_MapLastError();
		}
		else
			return_code = NPSL_CopyProtoEntFlatBasic(tmp_ent_ptr, proto_ent_ptr,
				proto_ent_buffer_ptr, proto_ent_buffer_length, required_length,
				error_text);
#endif // #if NPSL_HAS_GETPROTOBYPORT_R
	}

	return(return_code);
}
const char *
proto_to_name(uint8_t proto, int nolookup)
{
	unsigned int i;

	if (proto && !nolookup) {
		struct protoent *pent = getprotobynumber(proto);
		if (pent)
			return pent->p_name;
	}

	for (i = 0; xtables_chain_protos[i].name != NULL; ++i)
		if (xtables_chain_protos[i].num == proto)
			return xtables_chain_protos[i].name;

	return NULL;
}
static char *
proto_to_name(u_int8_t proto, int nolookup)
{
        unsigned int i;

        if (proto && !nolookup) {
                struct protoent *pent = getprotobynumber(proto);
                if (pent)
                        return pent->p_name;
        }

        for (i = 0; i < ARRAY_SIZE(chain_protos); ++i)
                if (chain_protos[i].num == proto)
                        return chain_protos[i].name;

        return NULL;
}
Exemplo n.º 30
0
int
ip_proto_iterator(char **label)
{
    static char label_buf[20];
    struct protoent *p;
    if (NULL == label) {
        next_iter = 0;
        return largest + 1;
    }
    if (next_iter > largest)
        return -1;
    p = getprotobynumber(next_iter);
    if (p)
        *label = p->p_name;
    else
        snprintf(*label = label_buf, 20, "p%d", next_iter);
    return next_iter++;
}