Esempio n. 1
0
socket_internal_t *socket_base_get_socket(int s)
{
    if (socket_base_exists_socket(s)) {
        return &(socket_base_sockets[s - 1]);
    }
    else {
        return NULL;
    }
}
Esempio n. 2
0
bool udp_socket_compliancy(int s)
{
    if ((socket_base_exists_socket(s)) &&
        (socket_base_get_socket(s)->socket_values.domain == PF_INET6) &&
        (socket_base_get_socket(s)->socket_values.type == SOCK_DGRAM) &&
        ((socket_base_get_socket(s)->socket_values.protocol == IPPROTO_UDP) ||
         (socket_base_get_socket(s)->socket_values.protocol == 0))) {
        return true;
    }
    else {
        return false;
    }
}
Esempio n. 3
0
int udp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid)
{
    int i;

    if (!socket_base_exists_socket(s)) {
        return -1;
    }

    for (i = 1; i < MAX_SOCKETS + 1; i++) {
        if (udp_socket_compliancy(i) &&
            (socket_base_get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) {
            return -1;
        }
    }

    memcpy(&socket_base_get_socket(s)->socket_values.local_address, name, namelen);
    socket_base_get_socket(s)->recv_pid = pid;
    return 0;
}
Esempio n. 4
0
int socket_base_bind(int s, sockaddr6_t *addr, int addrlen)
{
    if (socket_base_exists_socket(s)) {
        socket_t *current_socket = &socket_base_get_socket(s)->socket_values;

        switch (current_socket->domain) {
            case (PF_INET): {
                /* Not provided */
                return -1;
                break;
            }

            case (PF_INET6): {
                switch (current_socket->type) {
                        /* TCP */
                    case (SOCK_STREAM): {
                        if ((current_socket->protocol == 0) ||
                            (current_socket->protocol == IPPROTO_TCP)) {
                            return tcp_bind_socket(s, addr, addrlen,
                                                   thread_getpid());
                            break;
                        }
                        else {
                            return -1;
                            break;
                        }

                        break;
                    }

                    /* UDP */
                    case (SOCK_DGRAM): {
                        if ((current_socket->protocol == 0) ||
                            (current_socket->protocol == IPPROTO_UDP)) {
                            return udp_bind_socket(s, addr, addrlen,
                                                   thread_getpid());
                            break;
                        }
                        else {
                            return -1;
                            break;
                        }

                        break;
                    }

                    case (SOCK_SEQPACKET): {
                        /* not provided */
                        return -1;
                        break;
                    }

                    case (SOCK_RAW): {
                        /* not provided */
                        return -1;
                        break;
                    }

                    default: {
                        return -1;
                        break;
                    }
                }

                break;
            }

            case (PF_UNIX): {
                /* Not provided */
                return -1;
                break;
            }
        }
    }
    else {
        printf("SOCKET DOES NOT EXIST!\n");
        return -1;
    }

    return -1;
}