Some socket options

In fact, both network socket client & server will call a set_common_sockopts function which will set some socket options according to command line options:

void
set_common_sockopts(int s, int af)
{
    int x = 1;

    if (Sflag) {
        if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
            &x, sizeof(x)) == -1)
            err(1, NULL);
    }
    if (Dflag) {
        if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
            &x, sizeof(x)) == -1)
            err(1, NULL);
    }
    if (Tflag != -1) {
        if (af == AF_INET && setsockopt(s, IPPROTO_IP,
            IP_TOS, &Tflag, sizeof(Tflag)) == -1)
            err(1, "set IP ToS");

        else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
            IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
            err(1, "set IPv6 traffic class");
    }
    if (Iflag) {
        if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
            &Iflag, sizeof(Iflag)) == -1)
            err(1, "set TCP receive buffer size");
    }
    if (Oflag) {
        if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
            &Oflag, sizeof(Oflag)) == -1)
            err(1, "set TCP send buffer size");
    }

    if (ttl != -1) {
        if (af == AF_INET && setsockopt(s, IPPROTO_IP,
            IP_TTL, &ttl, sizeof(ttl)))
            err(1, "set IP TTL");

        else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
            IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)))
            err(1, "set IPv6 unicast hops");
    }

    if (minttl != -1) {
        if (af == AF_INET && setsockopt(s, IPPROTO_IP,
            IP_MINTTL, &minttl, sizeof(minttl)))
            err(1, "set IP min TTL");

        else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
            IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
            err(1, "set IPv6 min hop count");
    }
}

Below is the table which summarize these options:

VariableCommand optionSocket level & optionMeaning
Sflag-SIPPROTO_TCP&TCP_MD5SIGUses TCP MD5 signatures per RFC 2385
Dflag-DSOL_SOCKET&SO_DEBUGEnables recording of debugging information
Tflag-TIPPROTO_IP&IP_TOS IPPROTO_IPV6&IPV6_TCLASSChanges IPv4 TOS value (refer process_tos_opt function) or sets IPv6 traffic class field
Iflag-I lengthSOL_SOCKET&SO_RCVBUFSets buffer size for input
Oflag -O lengthSOL_SOCKET&SO_SNDBUFSets buffer size for output
ttl -M ttlIPPROTO_IP&IP_TTL IPPROTO_IPV6&IPV6_UNICAST_HOPSSets the TTL / hop limit of outgoing packets
minttl -m minttlIPPROTO_IP&IP_MINTTL IPPROTO_IPV6&IPV6_MINHOPCOUNTDiscards packets with a TTL lower than the option value

results matching ""

    No results matching ""