Beispiel #1
0
/*
 * Find the protox corresponding to name.
 */
struct protox *
name2protox(const char *name)
{
	struct protox *tp;
	char **alias;			/* alias from p->aliases */
	struct protoent *p;
	
	/*
	 * Try to find the name in the list of "well-known" names. If that
	 * fails, check if name is an alias for an Internet protocol.
	 */
	if ((tp = knownname(name)))
		return(tp);
		
	setprotoent(1);			/* make protocol lookup cheaper */
	while ((p = getprotoent46())) {
		/* assert: name not same as p->name */
		for (alias = p->p_aliases; *alias; alias++)
			if (strcasecmp(name, *alias) == 0) {
				endprotoent();
				return(knownname(p->p_name));
			}
	}
	endprotoent();
	return(NULLPROTOX);
}
Beispiel #2
0
/*
 * protocols
 */
static int
protocols(int argc, char *argv[])
{
	struct protoent	*pe;
	unsigned long	id;
	int		i, rv;

	assert(argc > 1);
	assert(argv != NULL);

#define PROTOCOLSPRINT	printfmtstrings(pe->p_aliases, "  ", " ", \
			    "%-16s  %5d", pe->p_name, pe->p_proto)

	setprotoent(1);
	rv = RV_OK;
	if (argc == 2) {
		while ((pe = getprotoent()) != NULL)
			PROTOCOLSPRINT;
	} else {
		for (i = 2; i < argc; i++) {
			if (parsenum(argv[i], &id))
				pe = getprotobynumber((int)id);
			else
				pe = getprotobyname(argv[i]);
			if (pe != NULL)
				PROTOCOLSPRINT;
			else {
				rv = RV_NOTFOUND;
				break;
			}
		}
	}
	endprotoent();
	return rv;
}
Beispiel #3
0
struct protoent * getprotoent (void)
{
  static struct _protoent p;
  char   buf[100];

  if (!netdb_init() || !protoFile)
     return (NULL);

  do
  {
    if (!fgets(buf,sizeof(buf)-1,protoFile))
       return (NULL);
  }
  while (buf[0] == '#' || buf[0] == '\n');

  if (protoClose)
     endprotoent();

/*  Protocol  Name
 *  ----------------------------------------
 *  0         reserved
 *  1         icmp, internet control message
 *  2         igmp, internet group management
 *  3         ggp, gateway-gateway protocol
 */

  p.p_proto = atoi  (strtok (buf," \t\n"));
  p.p_name  = strdup(strtok (NULL," ,\t\n"));
  if (!p.p_name)
     return (NULL);

  p.p_aliases = NULL;
  return (struct protoent*) &p;
}
Beispiel #4
0
static int
protocols(int argc, char *argv[])
{
	struct protoent	*pe;
	int		i, rv = RV_OK;

	setprotoent(1);
	if (argc == 2) {
		while ((pe = getprotoent()) != NULL)
			PROTOCOLSPRINT;
	} else {
		for (i = 2; i < argc; i++) {
			const char	*err;
			long long id = strtonum(argv[i], 0, UINT_MAX, &err);

			if (!err)
				pe = getprotobynumber((int)id);
			else
				pe = getprotobyname(argv[i]);
			if (pe != NULL)
				PROTOCOLSPRINT;
			else {
				rv = RV_NOTFOUND;
				break;
			}
		}
	}
	endprotoent();
	return rv;
}
Beispiel #5
0
_WCRTLINK struct protoent *getprotobyname(const char *name)
{
    struct protoent *ret;
    int i;

    if( name == NULL ) {
        _RWD_errno = EINVAL;
        return( NULL );
    }

    setprotoent( 1 );

    ret = getprotoent();
    while( ret != NULL ) {
        if( ret->p_name != NULL && strcmp(name, ret->p_name) == 0 )
            goto protobyname_cleanup;

        for( i = 0; ret->p_aliases != NULL && ret->p_aliases[i] != NULL; i++ ) {
            if( strcmp( name, ret->p_aliases[i] ) == 0 ) {
                goto protobyname_cleanup;
            }
        }

        ret = getprotoent();
    }

protobyname_cleanup:

    endprotoent();

    return( ret );
}
Beispiel #6
0
static int
inet_proto_a2n(const char *buf)
{
	struct protoent *pe;
	unsigned long proto_num;
	char *endptr;

	/* Skip white space */
	buf += strspn(buf, WHITE_SPACE);

	if (!*buf || *buf == '-')
		return -1;

	proto_num = strtoul(buf, &endptr, 10);
	if (proto_num > INT8_MAX)
		return -1;
	if (!*endptr)
		return proto_num;

	pe = getprotobyname(buf);
	endprotoent();

	if (pe)
		return pe->p_proto;

	return -1;
}
Beispiel #7
0
Datei: proto.c Projekt: 5kg/osv
struct protoent *getprotobyname(const char *name)
{
	struct protoent *p;
	endprotoent();
	do p = getprotoent();
	while (p && strcmp(name, p->p_name));
	return p;
}
Beispiel #8
0
Datei: proto.c Projekt: 5kg/osv
struct protoent *getprotobynumber(int num)
{
	struct protoent *p;
	endprotoent();
	do p = getprotoent();
	while (p && p->p_proto != num);
	return p;
}
Beispiel #9
0
void parse_end(void)
{
    endprotoent() ;
    endpwent() ;
    endgrent() ;
    endnetent() ;
    endhostent() ;
}
Beispiel #10
0
endprotoent_r()
#endif
{
#ifdef PROTO_R_ENT_UNUSED
        PROTO_R_ENT_UNUSED;
#endif
	endprotoent();
	PROTO_R_END_RESULT(PROTO_R_OK);
}
Beispiel #11
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;
}
Beispiel #12
0
/* The setprotoent() function opens and rewinds the `/etc/protocols' file. 
   As in setservent() the user can modify the location of the file using
   an environment variable.  */
void 
setprotoent (int stayopen)
{
  char *file = NULL;

  endprotoent ();
  if ((file = getenv (ENVIRON_ETC_PROTOCOLS)) != NULL)
    strcpy (scm_i_protoent.file, file);
  else if ((file = scm_i_socket_filename (FILE_ETC_PROTOCOLS)) != NULL)
    strcpy (scm_i_protoent.file, file);
  scm_i_protoent.fd = fopen (scm_i_protoent.file, "rt");
}
Beispiel #13
0
int main(int argc, char *argv[])
{
    struct protoent *protoent_p = NULL;

    setprotoent(0);
    while ((protoent_p = getprotoent()) != NULL) {
        printf("%-20s\t", protoent_p->p_name);
        printf("%d\t\n", protoent_p->p_proto);
    }
    endprotoent();

    return 0;
}
extern int getprotobyname_r(const char* name,
			    struct protoent *res, char *buf, size_t buflen,
			    struct protoent **res_sig) {
  while (!getprotoent_r(res,buf,buflen,res_sig)) {
    int i;
    if (!strcmp(res->p_name,name)) goto found;
    for (i=0; res->p_aliases[i]; ++i)
      if (!strcmp(res->p_aliases[i],name)) goto found;
  }
  *res_sig=0;
found:
  endprotoent();
  return *res_sig?0:-1;
}
Beispiel #15
0
/*
 * call-seq:
 *    Proto.getprotobynumber(num)
 *
 * Given a protocol number, returns the corresponding string, or nil if not
 * found.
 *
 * Examples:
 *
 *    Net::Proto.getprotobynumber(6)   # => "tcp"
 *    Net::Proto.getprotobynumber(999) # => nil
 */
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
   struct protoent p;
   char buffer[BUF_SIZE];
   VALUE v_proto_name = Qnil;

   setprotoent(0);
   
   if(getprotobynumber_r(NUM2INT(v_proto_num),&p,buffer,BUF_SIZE) != NULL)
      v_proto_name = rb_str_new2(p.p_name);

   endprotoent();

   return v_proto_name;
}
Beispiel #16
0
struct protoent *
getprotobynumber_p(int proto, struct net_data *net_data) {
	struct irs_pr *pr;

	if (!net_data || !(pr = net_data->pr))
		return (NULL);
	if (net_data->pr_stayopen && net_data->pr_last)
		if (net_data->pr_last->p_proto == proto)
			return (net_data->pr_last);
	net_data->pr_last = (*pr->bynumber)(pr, proto);
	if (!net_data->pr_stayopen)
		endprotoent();
	return (net_data->pr_last);
}
Beispiel #17
0
static int
get_proto_number (const char *name)
{
  struct protoent *p;
  int number;

  p = getprotobyname (name);
  if (p == NULL)
    number = -1;
  else
    number = p->p_proto;
  endprotoent ();

  return number;
}
Beispiel #18
0
/*
 * call-seq:
 *    Proto.getprotobyname(name)
 *
 * Given a protocol string, returns the corresponding number, or nil if not
 * found.
 *
 * Examples:
 *
 *    Net::Proto.getprotobyname("tcp")   # => 6
 *    Net::Proto.getprotobyname("bogus") # => nil
*/
static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
   struct protoent p;
   char buffer[BUF_SIZE];
   VALUE v_proto_num = Qnil;
   
   SafeStringValue(v_proto_name);

   setprotoent(0);
   
   if(getprotobyname_r(StringValuePtr(v_proto_name),&p,buffer,BUF_SIZE) != NULL)
      v_proto_num = INT2FIX(p.p_proto);

   endprotoent();

   return v_proto_num;
}
Beispiel #19
0
static int
protoent_fill_test_data(struct protoent_test_data *td)
{
    struct protoent *pe;

    setprotoent(1);
    while ((pe = getprotoent()) != NULL) {
        if (protoent_test_correctness(pe, NULL) == 0)
            TEST_DATA_APPEND(protoent, td, pe);
        else
            return (-1);
    }
    endprotoent();

    return (0);
}
Beispiel #20
0
/** desetup parse */
void
zonec_desetup_parser(void)
{
	if(parser) {
		endservent();
		endprotoent();
		region_destroy(parser->rr_region);
		/* removed when parser->region(=db->region) is destroyed:
		 * region_recycle(parser->region, (void*)error_dname, 1);
		 * region_recycle(parser->region, (void*)error_domain, 1); */
		/* clear memory for exit, but this is not portable to
		 * other versions of lex. yylex_destroy(); */
#ifdef MEMCLEAN /* OS collects memory pages */
		yylex_destroy();
#endif
	}
}
struct protoent * getprotobynumber(int proto) {
	struct protoent *pe;

	setprotoent(1);

	while ((pe = getprotoent()) != NULL) {
		/* same proto? */
		if (pe->p_proto == proto) {
			break;
		}
		/* nope. try again */
	}

	endprotoent();

	return pe;
}
Beispiel #22
0
struct protoent *
getprotobynumber(
	int proto )
{
	register struct protoent *p;

	setprotoent(_proto_stayopen);
	while ( (p = getprotoent()) )
		if (p->p_proto == proto)
			break;
	if (!_proto_stayopen)
		endprotoent();

	if ( !p )
		p = getprotobynumber_static(proto);
	return (p);
}
static void init_protos(int num)
{
	int proto_count = 0;

	if (num > 0) {
		proto_count = num;
	} else {
		/* Find the maximum number of possible protocols. */
		while (getprotoent() != NULL)
			proto_count++;
		endprotoent();
	}

	if ((protos = (int *)malloc(sizeof(int) * proto_count)) == NULL)
		err(1, "malloc");
	numprotos = proto_count;
}
Beispiel #24
0
int getprotobynumber_r (int proto_num,
			struct protoent *result_buf,
			char *buf, size_t buflen,
			struct protoent **result)
{
    int ret;

    __UCLIBC_MUTEX_LOCK(mylock);
    setprotoent(proto_stayopen);
    while (!(ret=getprotoent_r(result_buf, buf, buflen, result)))
	if (result_buf->p_proto == proto_num)
	    break;
    if (!proto_stayopen)
	endprotoent();
    __UCLIBC_MUTEX_UNLOCK(mylock);
    return *result?0:ret;
}
Beispiel #25
0
struct protoent *
getprotobyname_p(const char *name, struct net_data *net_data) {
	struct irs_pr *pr;
	char **pap;

	if (!net_data || !(pr = net_data->pr))
		return (NULL);
	if (net_data->pr_stayopen && net_data->pr_last) {
		if (!strcmp(net_data->pr_last->p_name, name))
			return (net_data->pr_last);
		for (pap = net_data->pr_last->p_aliases; pap && *pap; pap++)
			if (!strcmp(name, *pap))
				return (net_data->pr_last);
	}
	net_data->pr_last = (*pr->byname)(pr, name);
	if (!net_data->pr_stayopen)
		endprotoent();
	return (net_data->pr_last);
}
Beispiel #26
0
struct protoent *
getprotobyname(const char *name)
{
register struct protoent *p;
register char **cp;

	setprotoent(_proto_stayopen);
	while (p = getprotoent()) {
		if (strcmp(p->p_name, name) == 0)
			break;
		for (cp = p->p_aliases; *cp != 0; cp++)
			if (strcmp(*cp, name) == 0)
				goto found;
	}
found:
	if (!_proto_stayopen)
		endprotoent();
	return (p);
}
Beispiel #27
0
int ex_get(void)
{
    struct protoent *pp;

    for (int i=0; i<5; i++) {
        errno = 0;
        if ( !(pp = getprotoent()) )
            break;

        dump_prot(pp); 
    }

    if ( errno != 0 &&  errno != ENOENT ) 
        fprintf(stderr, "%s: getprotoent(3) %d\n", strerror(errno),errno);

    endprotoent(); 

    return 0;
}
Beispiel #28
0
int ex_set(void)
{
    struct protoent *pp;

    errno = 0;

    if ( (pp = getprotoent())!=NULL ) dump_prot(pp); 
    if ( (pp = getprotoent())!=NULL ) dump_prot(pp); 

    setprotoent(FLAGS_stayopen); 

    if ( (pp = getprotoent())!=NULL ) dump_prot(pp); 
    if ( (pp = getprotoent())!=NULL ) dump_prot(pp); 

    endprotoent(); 

    return 0; 

}
Beispiel #29
0
static void
test_protocols (void)
{
  struct protoent *prptr;

  prptr = getprotobyname ("IP");
  output_protoent ("getprotobyname (\"IP\")", prptr);

  prptr = getprotobynumber (1);
  output_protoent ("getprotobynumber (1)", prptr);

  setprotoent (0);
  do
    {
      prptr = getprotoent ();
      output_protoent ("getprotoent ()", prptr);
    }
  while (prptr != NULL);
  endprotoent ();
}
Beispiel #30
0
static int read_services(void)
{
    struct servent *se;
    struct protoent *pe;
    struct service *item;

    setservent(1);
    while ((se = getservent())) {
	/* Allocate a service entry. */
	item = (struct service *) xmalloc(sizeof(struct service));
	item->name = strdup(se->s_name);
	item->number = se->s_port;

	/* Fill it in. */
	if (!strcmp(se->s_proto, "tcp")) {
	    add2list(&tcp_name, item);
	} else if (!strcmp(se->s_proto, "udp")) {
	    add2list(&udp_name, item);
	} else if (!strcmp(se->s_proto, "sctp")) {
	    add2list(&sctp_name, item);
	} else if (!strcmp(se->s_proto, "raw")) {
	    add2list(&raw_name, item);
	} else { /* ddp, dccp */
	    free(item->name);
	    free(item);
	}
    }
    endservent();
    setprotoent(1);
    while ((pe = getprotoent())) {
	/* Allocate a service entry. */
	item = (struct service *) xmalloc(sizeof(struct service));
	item->name = strdup(pe->p_name);
	item->number = htons(pe->p_proto);
	add2list(&raw_name, item);
    }
    endprotoent();
    return (0);
}