STCP/mysock_api.c
int mygetsockname(mysocket_t sd, struct sockaddr *addr, socklen_t *addrlen)
{
    mysock_context_t *ctx = _mysock_get_context(sd);

    assert(addr && addrlen);

    MYSOCK_CHECK(ctx != NULL, EBADF);
    MYSOCK_CHECK(addr != NULL && addrlen != NULL, EFAULT);

    *addr = ctx->network_state.local_addr;
    assert(!addr->sa_family || addr->sa_family == AF_INET);

    addr->sa_family = AF_INET;
    ((struct sockaddr_in *) addr)->sin_port =
        _network_get_port(&ctx->network_state);

    if (ctx->network_state.peer_addr_valid)
    {
        /* XXX: if local address has been bound, and local_addr is set,
         * we probably shouldn't override it here... although this
         * shouldn't really affect anything...
         */
        ((struct sockaddr_in *) addr)->sin_addr.s_addr =
            _network_get_local_addr(&ctx->network_state);
    }

    return 0;
}
/* fills in addr with current port associated with the mysocket descriptor.
 * like the regular getsockname(), this does not fill in the local IP
 * address unless it's known.
 */
fills in addr with current port associated with the mysocket descriptor.
like the regular getsockname(), this does not fill in the local IP
address unless it's known.
fills in addr with current port associated with the mysocket descriptor . like the regular getsockname () this does not fill in the local IP address unless it ' s known .
int mygetsockname(mysocket_t sd, struct sockaddr *addr, socklen_t *addrlen)
{
    mysock_context_t *ctx = _mysock_get_context(sd);
    assert(addr && addrlen);
    MYSOCK_CHECK(ctx != NULL, EBADF);
    MYSOCK_CHECK(addr != NULL && addrlen != NULL, EFAULT);
    *addr = ctx->network_state.local_addr;
    assert(!addr->sa_family || addr->sa_family == AF_INET);
    addr->sa_family = AF_INET;
    ((struct sockaddr_in *) addr)->sin_port =
        _network_get_port(&ctx->network_state);
    if (ctx->network_state.peer_addr_valid)
    {
        ((struct sockaddr_in *) addr)->sin_addr.s_addr =
            _network_get_local_addr(&ctx->network_state);
    }
    return 0;
}
int mygetsockname ( mysocket_t sd , struct sockaddr * addr , socklen_t * addrlen ) { mysock_context_t * ctx = _mysock_get_context ( sd ) ; assert ( addr && addrlen ) ; MYSOCK_CHECK ( ctx != NULL , EBADF ) ; MYSOCK_CHECK ( addr != NULL && addrlen != NULL , EFAULT ) ; * addr = ctx -> network_state . local_addr ; assert ( ! addr -> sa_family || addr -> sa_family == AF_INET ) ; addr -> sa_family = AF_INET ; ( ( struct sockaddr_in * ) addr ) -> sin_port = _network_get_port ( & ctx -> network_state ) ; if ( ctx -> network_state . peer_addr_valid ) { ( ( struct sockaddr_in * ) addr ) -> sin_addr . s_addr = _network_get_local_addr ( & ctx -> network_state ) ; } return 0 ; }
fills in addr with current port associated with the mysocket descriptor.
fills in addr with current port associated with the mysocket descriptor .
/* XXX: if local address has been bound, and local_addr is set,
         * we probably shouldn't override it here... although this
         * shouldn't really affect anything...
         */