ioctl (..., 666, ...)

 Hi folks,
 
 there is a nasty oversight in w3c-libwww-5.1b/Library/src/HTHost.c
 where it reads:
 
    #ifndef WWW_MSWINDOWS
       ret = ioctl(socket, 666, (unsigned long)&mtu);
    #endif /* WWW_MSWINDOWS */
    
 This looks as if someone had the idea to use the value of the MTU,
 but was to lazy to check the details how to obtain it in the manual,
 and wrote some code to sketch the the idea and forgot about it later ... 

 needless to say that this code is potentially harmful when you 
 compile without WWW_MSWINDOWS.
 
 The correct way to obtain the MTU for a socket is
 
    struct ifreq ifr;
    ...
    if (ioctl(socket, SIOCGIFMTU, &ifr) == 0) ...
    
 where ifreq is defined in <net/if.h>. The bad news is that this
 call fails on the provided sockets under Linux with "no such device"
 (Linux problem?). So that I added a 
 
     #define MTU 480
     
 to the code which deactivates the ioctl and assumes the given value.
 Since the MTU value is used for outgoing network traffic
 you won't be able to measure the difference between a supposedly 
 working MTU ioctl and this approximation in a client situation.
 
 Architecturally the check for the MTU should not be performed in 
 HTHost_findWriteDelay() which is called frequently by 
 HTBufferWriter_lazyFlush(), but it should be a field in the 
 HTHost structure and be initialized in HTHost_new(). 
 But this is a minor point.....
 
 best regards
 
 -gustaf neumann
====================================================================================
*** w3c-libwww-5.1b/Library/src/HTHost.c.ORIG	Sat Apr  5 02:26:19 1997
--- w3c-libwww-5.1b/Library/src/HTHost.c	Sat May  3 19:16:51 1997
***************
*** 25,30 ****
--- 25,34 ----
  #include "HTHost.h"					 /* Implemented here */
  #include "HTHstMan.h"
  
+ #ifndef WWW_MSWINDOWS
+ #include <net/if.h>
+ #endif
+ 
  #define HOST_TIMEOUT		43200L	     /* Default host timeout is 12 h */
  
  /*
***************
*** 1332,1348 ****
      return host ? host->delay : 0;
  }
  
  PUBLIC int HTHost_findWriteDelay (HTHost * host, ms_t lastFlushTime, int buffSize)
  {
!     unsigned short mtu;
!     int ret = -1;
!     int socket = HTChannel_socket(host->channel);
! #ifndef WWW_MSWINDOWS
!     ret = ioctl(socket, 666, (unsigned long)&mtu);
! #endif /* WWW_MSWINDOWS */
!     if ((ret == 0 && buffSize >= mtu) || host->forceWriteFlush)
! 	return 0;
!     return host->delay;
  }
  
  PUBLIC BOOL HTHost_setDefaultWriteDelay (ms_t delay)
--- 1336,1365 ----
      return host ? host->delay : 0;
  }
  
+ #define MTU 480
+ 
  PUBLIC int HTHost_findWriteDelay (HTHost * host, ms_t lastFlushTime, int buffSize)
  {
!     int delay = host->delay;
!     if  (host->forceWriteFlush) 
! 	delay = 0;
! #if !defined(WWW_MSWINDOWS)
! # if defined(SIOCGIFMTU) && !defined(MTU)
!     else {
! 	struct ifreq ifr;
! 	int socket = HTChannel_socket(host->channel);
! 
! 	if (ioctl(socket, SIOCGIFMTU, &ifr) == 0 && buffSize >= ifr.ifr_mtu) 
! 	    delay = 0;
!     }
! # else
!     else {
!         if (buffSize >= MTU)
! 	    delay = 0;
!     }
! # endif /* SIOCGIFMTU */
! #endif /* WWW_MSWINDOWS ... */
!     return delay;
  }
  
  PUBLIC BOOL HTHost_setDefaultWriteDelay (ms_t delay)


--
Wirtschaftsinformatik und Softwaretechnik        
Universitaet GH Essen, FB5
Altendorfer Strasse 97-101, Eingang B, D-45143 Essen
Tel.: +49 (0201) 81003-74, Fax:  +49 (0201) 81003-73
Gustaf.Neumann@uni-essen.de
http://mohegan.wi-inf.uni-essen.de/Neumann.html

Received on Sunday, 4 May 1997 11:55:14 UTC