#include <time.h>
#include <unistd.h>
-#ifndef SOL_TCP
-#define SOL_TCP IPPROTO_TCP
-#endif
-
#ifndef MSG_MORE
#define MSG_MORE 0
#endif
int tcp_set_nodelay(int sock, const char *arg)
{
- return setsockopt(sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
+ return setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
}
int tcp_set_nolinger(int sock, const char *arg)
{
#ifdef TCP_QUICKACK
/* warning: do not use during connect if nothing is to be sent! */
- return setsockopt(sock, SOL_TCP, TCP_QUICKACK, &zero, sizeof(zero));
+ return setsockopt(sock, IPPROTO_TCP, TCP_QUICKACK, &zero, sizeof(zero));
#else
return 0;
#endif
#endif
#endif
-/* FreeBSD doesn't define SOL_IP and prefers IPPROTO_IP */
-#ifndef SOL_IP
-#define SOL_IP IPPROTO_IP
-#endif
-
-/* same for SOL_TCP */
-#ifndef SOL_TCP
-#define SOL_TCP IPPROTO_TCP
-#endif
-
/* If IPv6 is supported, define IN6_IS_ADDR_V4MAPPED() if missing. */
#if defined(IPV6_TCLASS) && !defined(IN6_IS_ADDR_V4MAPPED)
#define IN6_IS_ADDR_V4MAPPED(a) \
else {
#ifdef IP_BIND_ADDRESS_NO_PORT
static THREAD_LOCAL int bind_address_no_port = 1;
- setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int));
+ setsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int));
#endif
ret = quic_bind_socket(fd, flags, &src->source_addr, conn->src);
if (ret != 0)
else {
#ifdef IP_BIND_ADDRESS_NO_PORT
static THREAD_LOCAL int bind_address_no_port = 1;
- setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int));
+ setsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int));
#endif
ret = tcp_bind_socket(fd, flags, &src->source_addr, conn->src);
if (ret != 0)
* other families because v6-mapped IPv4 addresses are still
* reported as v4.
*/
- if (getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, sa, &salen) == 0)
+ if (getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST, sa, &salen) == 0)
return 0;
#endif
return ret;
case AF_INET:
#if defined(IP_TRANSPARENT)
val = 0; len = sizeof(val);
- if (getsockopt(fd, SOL_IP, IP_TRANSPARENT, &val, &len) == 0 && val)
+ if (getsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &val, &len) == 0 && val)
return 1;
#endif
#if defined(IP_FREEBIND)
val = 0; len = sizeof(val);
- if (getsockopt(fd, SOL_IP, IP_FREEBIND, &val, &len) == 0 && val)
+ if (getsockopt(fd, IPPROTO_IP, IP_FREEBIND, &val, &len) == 0 && val)
return 1;
#endif
#if defined(IP_BINDANY)
break;
case AF_INET6:
-#if defined(IPV6_TRANSPARENT) && defined(SOL_IPV6)
+#if defined(IPV6_TRANSPARENT)
val = 0; len = sizeof(val);
- if (getsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &val, &len) == 0 && val)
+ if (getsockopt(fd, IPPROTO_IPV6, IPV6_TRANSPARENT, &val, &len) == 0 && val)
return 1;
#endif
#if defined(IP_FREEBIND)
val = 0; len = sizeof(val);
- if (getsockopt(fd, SOL_IP, IP_FREEBIND, &val, &len) == 0 && val)
+ if (getsockopt(fd, IPPROTO_IP, IP_FREEBIND, &val, &len) == 0 && val)
return 1;
#endif
#if defined(IPV6_BINDANY)
{
return
#if defined(IP_TRANSPARENT)
- setsockopt(fd, SOL_IP, IP_TRANSPARENT, &one, sizeof(one)) == 0 ||
+ setsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &one, sizeof(one)) == 0 ||
#endif
#if defined(IP_FREEBIND)
- setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == 0 ||
+ setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) == 0 ||
#endif
#if defined(IP_BINDANY)
setsockopt(fd, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) == 0 ||
int sock_inet6_make_foreign(int fd)
{
return
-#if defined(IPV6_TRANSPARENT) && defined(SOL_IPV6)
- setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &one, sizeof(one)) == 0 ||
+#if defined(IPV6_TRANSPARENT)
+ setsockopt(fd, IPPROTO_IPV6, IPV6_TRANSPARENT, &one, sizeof(one)) == 0 ||
#endif
#if defined(IP_FREEBIND)
- setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == 0 ||
+ setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) == 0 ||
#endif
#if defined(IPV6_BINDANY)
setsockopt(fd, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) == 0 ||
/* re-enable quickack if it was disabled to ack all data and avoid
* retransmits from the client that might trigger a real reset.
*/
- setsockopt(conn->handle.fd, SOL_TCP, TCP_QUICKACK, &one, sizeof(one));
+ setsockopt(conn->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
#endif
/* lingering must absolutely be disabled so that we don't send a
* shutdown(), this is critical to the TCP_REPAIR trick. When no stream
fdtab[conn->handle.fd].linger_risk = 1;
#ifdef TCP_REPAIR
- if (setsockopt(conn->handle.fd, SOL_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) {
+ if (setsockopt(conn->handle.fd, IPPROTO_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) {
/* socket will be quiet now */
goto out;
}
*/
#ifdef IP_TTL
if (conn->src && conn->src->ss_family == AF_INET)
- setsockopt(conn->handle.fd, SOL_IP, IP_TTL, &one, sizeof(one));
+ setsockopt(conn->handle.fd, IPPROTO_IP, IP_TTL, &one, sizeof(one));
#endif
#ifdef IPV6_UNICAST_HOPS
-#if defined(SOL_IPV6)
- if (conn->src && conn->src->ss_family == AF_INET6)
- setsockopt(conn->handle.fd, SOL_IPV6, IPV6_UNICAST_HOPS, &one, sizeof(one));
-#elif defined(IPPROTO_IPV6)
if (conn->src && conn->src->ss_family == AF_INET6)
setsockopt(conn->handle.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &one, sizeof(one));
#endif
-#endif
out:
/* kill the stream if any */
if (strm) {
/* The fd may not be available for the tcp_info struct, and the
syscal can fail. */
optlen = sizeof(info);
- if (getsockopt(conn->handle.fd, SOL_TCP, TCP_INFO, &info, &optlen) == -1)
+ if (getsockopt(conn->handle.fd, IPPROTO_TCP, TCP_INFO, &info, &optlen) == -1)
return 0;
/* extract the value. */