Esempio n. 1
0
int socket(int domain, int type, int protocol)
{
#if DEBUG
    fprintf(stderr, "socket: domain %d, type %d, protocol %d\n",
            domain, type, protocol);
#endif
    if (domain != AF_INET)
    {
#if DEBUG
        fprintf(stderr, "socket: bad domain %d\n", domain);
#endif
        errno= EAFNOSUPPORT;
        return -1;
    }
    if (type == SOCK_STREAM)
        return _tcp_socket(protocol);

    if (type == SOCK_DGRAM)
        return _udp_socket(protocol);

#if DEBUG
    fprintf(stderr, "socket: nothing for domain %d, type %d, protocol %d\n",
            domain, type, protocol);
#endif
    errno= EPROTOTYPE;
    return -1;
}
Esempio n. 2
0
int socket(int domain, int type, int protocol)
{
	int sock_type;

	sock_type = type & ~SOCK_FLAGS_MASK;

#if DEBUG
	fprintf(stderr, "socket: domain %d, type %d, protocol %d\n",
		domain, type, protocol);
#endif
	if (domain != AF_INET && domain != AF_UNIX)
	{
#if DEBUG
		fprintf(stderr, "socket: bad domain %d\n", domain);
#endif
		errno= EAFNOSUPPORT;
		return -1;
	}

	if (domain == AF_UNIX && (sock_type == SOCK_STREAM ||
				  sock_type == SOCK_DGRAM ||
				  sock_type == SOCK_SEQPACKET))
		return _uds_socket(type, protocol);

	if (domain == AF_INET && sock_type == SOCK_STREAM)
		return _tcp_socket(type, protocol);

	if (domain == AF_INET && sock_type == SOCK_DGRAM)
		return _udp_socket(type, protocol);

	if (domain == AF_INET && sock_type == SOCK_RAW && protocol == IPPROTO_ICMP)
		return _raw_socket(type, protocol);

	if (domain == AF_INET && sock_type == SOCK_RAW && protocol == IPPROTO_UDP)
		return _raw_socket(type, protocol);

#if DEBUG
	fprintf(stderr, "socket: nothing for domain %d, type %d, protocol %d\n",
		domain, type, protocol);
#endif
	errno= EPROTOTYPE;
	return -1;
}