[SSSD] [PATCH] SDAP: Use portable constant as level in setsockopt

Lukas Slebodnik lslebodn at redhat.com
Sat May 31 16:47:10 UTC 2014


ehlo,

The macros SOL_TCP and IPPROTO_TCP have the same value on linux,
but the first one is not portable.

I checked source code of other projects and they use constant IPPROTO_TCP
for seting TCP_NODELAY on tcp socket.

c-ares
   ares_process.c:1026:  if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
   ares_process.c-1027-                 (void *)&opt, sizeof(opt)) == -1)
   ares_process.c-1028-    {

cups
   http.c-222-
   http.c-223-  val = 1;
   http.c:224:  setsockopt(http->fd, IPPROTO_TCP, TCP_NODELAY, CUPS_SOCAST &val, sizeof(val));
   http.c-225-

audit
   auditd-listen.c-816-
   auditd-listen.c-817-    /* Connection is accepted...start setting it up */
   auditd-listen.c:818:    setsockopt(afd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof (int));
   auditd-listen.c:819:    setsockopt(afd, SOL_SOCKET, SO_KEEPALIVE, (char *)&one, sizeof (int));
   auditd-listen.c:820:    setsockopt(afd, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof (int));
   auditd-listen.c-821-    set_close_on_exec (afd);
   auditd-listen.c-822-

libtircp
   svc_vc.c-348-   len = 1;
   svc_vc.c-349-   /* XXX fvdl - is this useful? */
   svc_vc.c:350:   setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &len, sizeof (len));
   svc_vc.c-351-}
   svc_vc.c-352-

valgrind
   valgrind-di-server.c-1133-
   valgrind-di-server.c-1134-assert(one == 1);
   valgrind-di-server.c:1135:int ret = setsockopt( new_sd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
   valgrind-di-server.c-1136-assert(ret != -1);
   valgrind-di-server.c-1137-

openldap
   daemon.c-1918-            /* enable no delay */
   daemon.c-1919-            tmp = 1;
   daemon.c:1920:            rc = setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
   daemon.c-1921-                    (char *)&tmp, sizeof(tmp) );
   daemon.c-1922-            if ( rc == AC_SOCKET_ERROR ) {

Simple patch is attached.

LS
-------------- next part --------------
>From 090ffbdeb49b352dcbd97c8737c9f117b459ddf8 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Sat, 31 May 2014 18:33:40 +0200
Subject: [PATCH] SDAP: Use portable constant as level in setsockopt

The macros SOL_TCP and IPPROTO_TCP have the same value on linux,
but the first one is not portable.

man in.h says:
       The <netinet/in.h> header shall define the following macros for use as
       values of the level argument of getsockopt() and setsockopt():

       IPPROTO_IP       Internet protocol.
       IPPROTO_IPV6     Internet Protocol Version 6.
       IPPROTO_ICMP     Control message protocol.
       IPPROTO_RAW      Raw IP Packets Protocol.
       IPPROTO_TCP      Transmission control protocol.
       IPPROTO_UDP      User datagram protocol.
---
 src/util/sss_ldap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/sss_ldap.c b/src/util/sss_ldap.c
index a2101ecde4497c2045e2adb035eb33e2f790aca1..dd63b4b4f22f0aa1b540bc04ede211ac9cb88ebe 100644
--- a/src/util/sss_ldap.c
+++ b/src/util/sss_ldap.c
@@ -270,7 +270,7 @@ static errno_t set_fd_flags_and_opts(int fd)
                   strerror(ret));
     }
 
-    ret = setsockopt(fd, SOL_TCP, TCP_NODELAY, &dummy, sizeof(dummy));
+    ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &dummy, sizeof(dummy));
     if (ret != 0) {
         ret = errno;
         DEBUG(SSSDBG_FUNC_DATA,
-- 
1.9.3



More information about the sssd-devel mailing list