如何在C中获得套接字选项的名称?

时间:2019-03-06 19:12:27

标签: c networking libc

我有一些看起来像这样的代码:

    switch (option) {
        case MVM_SO_BROADCAST:
        case MVM_SO_KEEPALIVE:
        case MVM_SO_REUSEADDR:
        case MVM_SO_DONTROUTE:
        case MVM_SO_SNDBUF:
        case MVM_SO_RCVBUF:
        case MVM_SO_OOBINLINE:
        case MVM_TCP_NODELAY: {
            int input;
            len = sizeof(int);
            e = getsockopt(s, SOL_SOCKET, (int)option, (char *)&input, &len);
            output = input;
            break;
        }
        case MVM_SO_LINGER: {
            struct linger input;
            len = sizeof(struct linger);
            e = getsockopt(s, SOL_SOCKET, (int)option, (char *)&input, &len);
            // Match Java's behaviour with SO_LINGER
            output = (input.l_onoff >= 0) ? input.l_linger : -1;
            break;
        }
        default:
            MVM_exception_throw_adhoc(tc, "this socket option is not supported by MoarVM: %d", (int)option);
            break;
    }

MVM_SO_BROADCAST等是SO_BROADCAST等的宏。在开关的默认情况下,我要打印给定的套接字选项的名称,而不是其值,这对最终用户是无用的。 libc中是否有为此功能的功能?

0 个答案:

没有答案