Ejemplo n.º 1
0
static struct protoent *
getprotoent46(void)
{
#ifdef INET6
	static enum {NONE, V4, V6} state = NONE;
	static struct protoent v;
	struct protoent *p;
	int l;

	switch (state) {
	case NONE:
		p = getprotoent();
		if (!p)
			return p;
		memcpy(&v, p, sizeof(v));
		state = V4;
		break;
	case V4:
		strcat(v.p_name, "4");
		state = V6;
		break;
	case V6:
		l = strlen(v.p_name);
		v.p_name[l - 1] = '6';
		state = NONE;
		break;
	}
	return &v;
#else
	return getprotoent();
#endif
}
Ejemplo n.º 2
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 );
}
Ejemplo n.º 3
0
struct protoent *wp_getprotoent (void)
{
	struct protoent *p;
	if ((p = getprotoent ()) == NULL)
		wp_warning ("getprotoent() error");
	return p;
}
Ejemplo n.º 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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
/*
 * Find the protox corresponding to name.
 */
static 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)) != NULL)
		return (tp);

	setprotoent(1);			/* make protocol lookup cheaper */
	while ((p = getprotoent()) != NULL) {
		/* assert: name not same as p->name */
		for (alias = p->p_aliases; *alias; alias++)
			if (strcmp(name, *alias) == 0) {
				endprotoent();
				return (knownname(p->p_name));
			}
	}
	endprotoent();
	return (NULL);
}
Ejemplo n.º 7
0
Archivo: proto.c Proyecto: 5kg/osv
struct protoent *getprotobyname(const char *name)
{
	struct protoent *p;
	endprotoent();
	do p = getprotoent();
	while (p && strcmp(name, p->p_name));
	return p;
}
Ejemplo n.º 8
0
Archivo: proto.c Proyecto: 5kg/osv
struct protoent *getprotobynumber(int num)
{
	struct protoent *p;
	endprotoent();
	do p = getprotoent();
	while (p && p->p_proto != num);
	return p;
}
Ejemplo n.º 9
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; 

}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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);
}
Ejemplo n.º 12
0
int main()
{
    struct protoent *pproto;
    int index = 1;
    while((pproto=getprotoent())!=NULL) {
        printf("\t\t---- %d ----\n",index);
        printf("\tname\n%s\n",pproto->p_name);
        char **names = pproto->p_aliases;
        printf("\talternate protocol names\n");
        for(int i=0; names[i]!=NULL; ++i) {
            printf("%s\n",names[i]);
        }
        printf("\ttype\n%d\n",pproto->p_proto);
        //printf("\ttype\n%s\n",(pproto->p_proto==AF_INET)?"IPv4":"Not IPv4");
        ++index;
    }
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
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;
}
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;
}
Ejemplo n.º 16
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);
}
Ejemplo n.º 17
0
PROTO_R_RETURN
getprotoent_r(struct protoent *pptr, PROTO_R_ARGS) {
	struct protoent *pe = getprotoent();
#ifdef PROTO_R_SETANSWER
	int n = 0;

	if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0)
		*answerp = NULL;
	else
		*answerp = pptr;
	
	return (n);
#else
	if (pe == NULL)
		return (PROTO_R_BAD);

	return (copy_protoent(pe, pptr, PROTO_R_COPY));
#endif
}
Ejemplo n.º 18
0
void ReadProtoFile (const char *fname)
{
  static int been_here = 0;

  if (!fname || !*fname)
     return;

  if (been_here)  /* loading multiple protocol files */
  {
    free (protoFname);
    fclose (protoFile);
    protoFile = NULL;
  }
  been_here = 1;

  protoFname = strdup (fname);
  if (!protoFname)
     return;

  setprotoent (1);
  if (!protoFile)
     return;

  while (1)
  {
    struct _protoent *p, *p2 = (struct _protoent*) getprotoent();

    if (!p2)
       break;

    p = malloc (sizeof(*p));
    if (!p)
    {
      outsnl ("Protocol-file too big!\7");
      break;
    }
    *p = *p2;
    p->next = _proto0;
    _proto0 = p;
  }
  rewind (protoFile);
  atexit (endprotoent);
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
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 ();
}
Ejemplo n.º 21
0
		void SocketProtocol::loadProtocols(){
			read_m.lock();
			if(__all_p.size() == 0){
				setprotoent(0);
				struct protoent *pro;
				while((pro = getprotoent()) != 0){
					SocketProtocol sp(pro->p_proto, pro->p_name);
					for(int i = 0; ; i++){
						if(pro->p_aliases[i] != 0){
							sp.addAlias(pro->p_aliases[i]);
						}
						else{
							break;
						}
					}
					__all_p.push_back(sp);
				}
			}
			read_m.unlock();
		}
Ejemplo n.º 22
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);
}
Ejemplo n.º 23
0
struct protoent *
nw_getprotoent(void) 
{
    return ((struct protoent *) getprotoent());
}
Ejemplo n.º 24
0
int
main(int argc, char *argv[])
{
	netsnmp_session session;
	struct protoent *p;
        char *cp;

	af = AF_UNSPEC;
        cp = strrchr( argv[0], '/' );
        if (cp)
            progname = cp+1;
        else
            progname = argv[0];

	switch (snmp_parse_args( argc, argv, &session, "C:iRs", optProc)) {
	case NETSNMP_PARSE_ARGS_ERROR:
	    exit(1);
	case NETSNMP_PARSE_ARGS_SUCCESS_EXIT:
	    exit(0);
	case NETSNMP_PARSE_ARGS_ERROR_USAGE:
	    usage();
	    exit(1);
	default:
	    break;
	}

	    /*
	     * Check argc vs optind ??
	     */
	argv += optind;
	argc -= optind;

    /*
     * Open an SNMP session.
     */
    SOCK_STARTUP;
    ss = snmp_open(&session);
    if (ss == NULL) {
        /*
         * diagnose snmp_open errors with the input netsnmp_session pointer 
         */
        snmp_sess_perror("snmpnetstat", &session);
        SOCK_CLEANUP;
        exit(1);
    }

	/*
	 * Omitted:
	 *     Privilege handling
	 *    "Backward Compatibility"
	 *     Kernel namelis handling
	 */

	if (mflag) {
            /*
		mbpr(nl[N_MBSTAT].n_value, nl[N_MBPOOL].n_value,
		    nl[N_MCLPOOL].n_value);
             */
		exit(0);
	}
	if (pflag) {
		printproto(tp, tp->pr_name);
		exit(0);
	}
	/*
	 * Keep file descriptors open to avoid overhead
	 * of open/close on each call to get* routines.
	 */
	sethostent(1);
	setnetent(1);
	if (iflag) {
		intpr(interval);
		exit(0);
	}
	if (rflag) {
             /*
		if (sflag)
			rt_stats();
		else
              */
		if (Lflag || routexpr(af) == 0) {
		    if (route4pr(af) == 0 && af == AF_INET) routepr();
		    route6pr(af);
		}
		exit(0);
	}
     /*
	if (gflag) {
		if (sflag) {
			if (af == AF_INET || af == AF_UNSPEC)
				mrt_stats(nl[N_MRTPROTO].n_value,
				    nl[N_MRTSTAT].n_value);
#ifdef NETSNMP_ENABLE_IPV6
			if (af == AF_INET6 || af == AF_UNSPEC)
				mrt6_stats(nl[N_MRT6PROTO].n_value,
				    nl[N_MRT6STAT].n_value);
#endif
		}
		else {
			if (af == AF_INET || af == AF_UNSPEC)
				mroutepr(nl[N_MRTPROTO].n_value,
				    nl[N_MFCHASHTBL].n_value,
				    nl[N_MFCHASH].n_value,
				    nl[N_VIFTABLE].n_value);
#ifdef NETSNMP_ENABLE_IPV6
			if (af == AF_INET6 || af == AF_UNSPEC)
				mroute6pr(nl[N_MRT6PROTO].n_value,
				    nl[N_MF6CTABLE].n_value,
				    nl[N_MIF6TABLE].n_value);
#endif
		}
		exit(0);
	}
     */
	setservent(1);
	if (af == AF_UNSPEC && Lflag) {
		setprotoent(1);
		/* ugh, this is O(MN) ... why do we do this? */
		while ((p = getprotoent())) {
			for (tp = protox; tp->pr_name; tp++)
				if (strcmp(tp->pr_name, p->p_name) == 0)
					if (tp->pr_name && tp->pr_wanted)
					    printproto(tp, p->p_name);
		}
		endprotoent();
	}
	if (af == AF_UNSPEC && !Lflag)
		for (tp = ipxprotox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
	if (af == AF_INET)
		for (tp = protox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
	if (af == AF_INET6)
		for (tp = ip6protox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
    /*
	if (af == AF_IPX || af == AF_UNSPEC)
		for (tp = ipxprotox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
	if (af == AF_NS || af == AF_UNSPEC)
		for (tp = nsprotox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
	if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
		unixpr(nl[N_UNIXSW].n_value);
	if (af == AF_APPLETALK || af == AF_UNSPEC)
		for (tp = atalkprotox; tp->pr_name; tp++)
			printproto(tp, tp->pr_name);
     */
	exit(0);
}