Ejemplo n.º 1
0
char *get_sname(int socknumber, char *proto, int numeric)
{
    static char buffer[64], init = 0;
    struct service *item;

    if (socknumber == 0)
	return ("*");
    if (numeric) {
	sprintf(buffer, "%d", ntohs(socknumber));
	return (buffer);
    }
    if (!init) {
	(void) read_services();
	init = 1;
    }
    buffer[0] = '\0';
    if (!strcmp(proto, "tcp")) {
	if ((item = searchlist(tcp_name, socknumber)) != NULL)
	    sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "udp")) {
	if ((item = searchlist(udp_name, socknumber)) != NULL)
	    sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "raw")) {
	if ((item = searchlist(raw_name, socknumber)) != NULL)
	    sprintf(buffer, "%s", item->name);

    }
    if (!buffer[0])
	sprintf(buffer, "%d", ntohs(socknumber));
    return (buffer);
}
Ejemplo n.º 2
0
const char *get_sname(int socknumber, const char *proto, int numeric)
{
    static char buffer[64], init = 0;
    struct service *item;

    if (socknumber == 0)
	return ("*");
    if (numeric)
	goto do_ntohs;

    if (!init) {
	(void) read_services();
	init = 1;
    }
    buffer[0] = '\0';
    if (!strcmp(proto, "tcp"))
	item = searchlist(tcp_name, socknumber);
    else if (!strcmp(proto, "udp"))
	item = searchlist(udp_name, socknumber);
    else if (!strcmp(proto, "raw"))
	item = searchlist(raw_name, socknumber);
    else
	item = NULL;
    if (item) {
	strncpy(buffer, item->name, sizeof(buffer));
	buffer[sizeof(buffer) - 1] = '\0';
    }

    if (!buffer[0]) {
 do_ntohs:
	sprintf(buffer, "%d", ntohs(socknumber));
    }
    return (buffer);
}