Пример #1
0
struct protoent *
getprotobyname_r(const char *name, struct protoent *pr,
    struct protoent_data *pd)
{
	struct protoent *p;
	char **cp;

	_DIAGASSERT(name != NULL);

	setprotoent_r(pd->stayopen, pd);
	while ((p = getprotoent_r(pr, pd)) != NULL) {
		if (strcmp(p->p_name, name) == 0)
			break;
		for (cp = p->p_aliases; *cp != NULL; cp++)
			if (strcmp(*cp, name) == 0)
				goto found;
	}
found:
	if (!pd->stayopen)
		if (pd->fp != NULL) {
			(void)fclose(pd->fp);
			pd->fp = NULL;
		}
	return p;
}
Пример #2
0
struct protoent * getprotoent(void)
{
    struct protoent *result;

    __initbuf();
    getprotoent_r(&proto, static_aliases, SBUFSIZE, &result);
    return result;
}
Пример #3
0
struct protoent *
getprotoent(void)
{
	static struct protoent proto;

	if (getprotoent_r(&proto, &_protoent_data) != 0)
		return (NULL);
	return (&proto);
}
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;
}
Пример #5
0
int
getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd)
{
	int error;

	setprotoent_r(pd->stayopen, pd);
	while ((error = getprotoent_r(pe, pd)) == 0)
		if (pe->p_proto == num)
			break;
	if (!pd->stayopen && pd->fp != NULL) {
		(void)fclose(pd->fp);
		pd->fp = NULL;
	}
	return (error);
}
Пример #6
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;
}
Пример #7
0
struct protoent *getprotobyname_r(const char *name, struct protoent *result,
								  char *buf, int bufsize)
{
	char **alias;

	pthread_mutex_lock(&proto_iterate_lock);
	setprotoent(0);
	while ((result = getprotoent_r(result, buf, bufsize)) != NULL) {
		/* Check the entry's name and aliases against the given name. */
		if (strcmp(result->p_name, name) == 0)
			break;
		for (alias = result->p_aliases; *alias != 0; alias++) {
			if (strcmp(*alias, name) == 0)
				break;
		}
	}
	pthread_mutex_unlock(&proto_iterate_lock);
	return result;
}
Пример #8
0
/*
 * call-seq:
 *    Proto.getprotoent
 *    Proto.getprotoent{ |struct| ... }
 *
 * In block form, yields each entry from /etc/protocols as a struct of type
 * Proto::ProtoStruct.  In non-block form, returns an array of
 * Proto::ProtoStruct objects.
	
 * The fields are 'name' (a String), 'aliases' (an Array of String's,
 * though often only one element), and 'proto' (a Fixnum).
 *
 * Example:
 *
 *   Net::Proto.getprotoent.each{ |prot|
 *      p prot.name
 *      p prot.aliases
 *      p prot.proto
 *   }
*/
static VALUE np_getprotoent(){
   struct protoent p;
   char buffer[BUF_SIZE];
   VALUE v_alias_array = Qnil;
   VALUE v_array = Qnil;
   VALUE v_struct = Qnil;
   
   if(!rb_block_given_p())
   	v_array = rb_ary_new();

   setprotoent(0);

   while(getprotoent_r(&p, buffer, BUF_SIZE)){
      v_alias_array = rb_ary_new();
      
      while(*p.p_aliases){
         rb_ary_push(v_alias_array ,rb_str_new2(*p.p_aliases));
         (void)p.p_aliases++;
      }
      
      v_struct = rb_struct_new(sProto,
      	rb_str_new2(p.p_name),
      	v_alias_array,
      	INT2FIX(p.p_proto)
      );

      OBJ_FREEZE(v_struct); /* This is read-only data */

      if(rb_block_given_p())
         rb_yield(v_struct);
      else
         rb_ary_push(v_array, v_struct);
   }

   endprotoent();

   return v_array; /* nil unless a block is given */
}
Пример #9
0
int getprotobyname_r(const char *name,
		    struct protoent *result_buf,
		    char *buf, size_t buflen,
		    struct protoent **result)
{
    register char **cp;
    int ret;

    __UCLIBC_MUTEX_LOCK(mylock);
    setprotoent(proto_stayopen);
    while (!(ret=getprotoent_r(result_buf, buf, buflen, result))) {
	if (strcmp(result_buf->p_name, name) == 0)
	    break;
	for (cp = result_buf->p_aliases; *cp != 0; cp++)
	    if (strcmp(*cp, name) == 0)
		goto found;
    }
found:
    if (!proto_stayopen)
	endprotoent();
    __UCLIBC_MUTEX_UNLOCK(mylock);
    return *result?0:ret;
}
Пример #10
0
struct protoent *getprotoent(void) {
  struct protoent* tmp;
  getprotoent_r(&__protoent_pw,__protoent_buf,sizeof(__protoent_buf),&tmp);
  return tmp;
}
struct protoent * getprotoent(void)
{
    struct protoent *result;
    getprotoent_r(&proto, static_aliases, sizeof(static_aliases), &result);
    return result;
}