socket length arg fix (SAMBA_2_0 branch)

Tim Rice tim at trr.metro.NET
Sun Dec 13 01:22:56 GMT 1998


Attached is a patch to address the fact that newer systems have
socket API call-by-reference parameters that give buffer lengths are not int.
Example:
....
UX:acomp: WARNING: "../samba/source/smbd/server.c", line 213: argument is incomp
atible with prototype: arg #3
....
Hmm, line 213 of smbd/server.c says
	Client = accept(s,&addr,&in_addrlen);
Loking at the man page,
SYNOPSIS
      cc [options] file -lsocket -lnsl
      #include <sys/types.h>
      #include <sys/socket.h>
      int accept(int s, struct sockaddr *addr, size_t *addrlen);
                                               ^^^^^^

This patch uses socklen_t which by default is typedefed int so this
patch will NOT break any other systems.
So in the above example,
	int in_addrlen = sizeof(addr);
becomes
	socklen_t in_addrlen = sizeof(addr);

For systems that need something other than int you can use the new
---with-CONFIG_SOCKARGLENTYPE=  option of configure.

For UnixWare configure will set CONFIG_SOCKARGLENTYPE to size_t
Other systems that need this can be added later to the case statement
in configure.in that handles this.


Enjoy,

-- 
Tim Rice			Multitalents	(707) 887-1469 (voice)
tim at trr.metro.net

-------------- next part --------------
*** configure.in.old	Fri Dec 11 15:51:13 1998
--- configure.in	Fri Dec 11 17:09:40 1998
***************
*** 802,807 ****
--- 802,847 ----
  fi
  
  #################################################
+ #
+ # Some vendors have changed the socket API so that
+ # call-by-reference parameters that give buffer
+ # lengths are not int; this must be dealt with to
+ # get the code to compile.  Note that we only emit
+ # the define if the type is not an int; we do this
+ # so include/includes.h can include code that assumes the
+ # default so folks don't have to rerun configure.
+ #
+ # set SOCKARGLENTYPE type
+ AC_ARG_WITH(CONFIG_SOCKARGLENTYPE,
+ [  --with-CONFIG_SOCKARGLENTYPE=   int vs size_t vs unsigned long vs ... ],
+ [ case "$withval" in
+   yes|no)
+   #
+   # Just in case anybody does it
+   #
+     AC_MSG_WARN([--with-CONFIG_SOCKARGLENTYPE= called without argument])
+   ;;
+   * )
+     CONFIG_SOCKARGLENTYPE="$withval"
+     ;;
+   esac ]
+ )
+ 
+ test "$CONFIG_SOCKARGLENTYPE" || {		# int vs unsigned long vs ...
+ 	case $target in
+ 	# XXX fill in for newer systems
+ 	*-univel-*)	CONFIG_SOCKARGLENTYPE=size_t;;
+ 	*-UnixWare-*)	CONFIG_SOCKARGLENTYPE=size_t;;
+ 	*)		CONFIG_SOCKARGLENTYPE=int;;
+ 	esac
+ }
+ 
+ if [ test "$CONFIG_SOCKARGLENTYPE" != int ]; then
+ 	AC_MSG_RESULT(... using $CONFIG_SOCKARGLENTYPE for call-by-reference socket length params)
+ 	AC_DEFINE_UNQUOTED(SOCKARGLENTYPE, $CONFIG_SOCKARGLENTYPE)
+ fi
+ 
+ #################################################
  # check for smbwrapper support
  AC_MSG_CHECKING(whether to use smbwrapper)
  AC_ARG_WITH(smbwrapper,
*** include/config.h.in.old	Fri Dec 11 15:51:13 1998
--- include/config.h.in	Fri Dec 11 17:09:40 1998
***************
*** 824,826 ****
--- 824,830 ----
  
  /* Define if you have the socket library (-lsocket).  */
  #undef HAVE_LIBSOCKET
+ 
+ /* socket API call-by-reference parameters */
+ #undef SOCKARGLENTYPE
+ 
*** include/includes.h.old	Mon Dec  7 18:59:54 1998
--- include/includes.h	Fri Dec 11 17:09:40 1998
***************
*** 754,757 ****
--- 754,769 ----
  /* yuck, I'd like a better way of doing this */
  #define DIRP_SIZE (256 + 32)
  
+ /* 
+     Some vendors have changed the socket API so that
+     call-by-reference parameters that give buffer
+     lengths are not int;
+ */
+ #ifdef SOCKARGLENTYPE
+ 	typedef SOCKARGLENTYPE socklen_t;
+ #else
+ 	typedef int socklen_t;
+ #endif
+ 
+ 
  #endif /* _INCLUDES_H */
*** smbd/server.c.old	Thu Nov 26 10:50:01 1998
--- smbd/server.c	Fri Dec 11 17:09:40 1998
***************
*** 197,203 ****
  		   accept on these. */
  		for( ; num > 0; num--) {
  			struct sockaddr addr;
! 			int in_addrlen = sizeof(addr);
  			
  			s = -1;
  			for(i = 0; i < num_interfaces; i++) {
--- 197,203 ----
  		   accept on these. */
  		for( ; num > 0; num--) {
  			struct sockaddr addr;
! 			socklen_t in_addrlen = sizeof(addr);
  			
  			s = -1;
  			for(i = 0; i < num_interfaces; i++) {
*** smbd/oplock.c.old	Thu Dec 10 15:59:19 1998
--- smbd/oplock.c	Fri Dec 11 17:09:40 1998
***************
*** 68,74 ****
  BOOL open_oplock_ipc(void)
  {
    struct sockaddr_in sock_name;
!   int len = sizeof(sock_name);
  
    DEBUG(3,("open_oplock_ipc: opening loopback UDP socket.\n"));
  
--- 68,74 ----
  BOOL open_oplock_ipc(void)
  {
    struct sockaddr_in sock_name;
!   socklen_t len = sizeof(sock_name);
  
    DEBUG(3,("open_oplock_ipc: opening loopback UDP socket.\n"));
  
***************
*** 117,123 ****
  BOOL receive_local_message(fd_set *fds, char *buffer, int buffer_len, int timeout)
  {
    struct sockaddr_in from;
!   int fromlen = sizeof(from);
    int32 msg_len = 0;
  
    smb_read_error = 0;
--- 117,123 ----
  BOOL receive_local_message(fd_set *fds, char *buffer, int buffer_len, int timeout)
  {
    struct sockaddr_in from;
!   socklen_t fromlen = sizeof(from);
    int32 msg_len = 0;
  
    smb_read_error = 0;
*** lib/util_sock.c.old	Thu Dec 10 15:58:26 1998
--- lib/util_sock.c	Fri Dec 11 17:09:40 1998
***************
*** 50,57 ****
  ****************************************************************************/
  BOOL is_a_socket(int fd)
  {
!   int v,l;
!   l = sizeof(int);
    return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0);
  }
  
--- 50,58 ----
  ****************************************************************************/
  BOOL is_a_socket(int fd)
  {
!   int v;
!   socklen_t l;
!   l = sizeof(v);
    return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0);
  }
  
***************
*** 200,206 ****
  {
    ssize_t ret;
    struct sockaddr_in sock;
!   int socklen;
    
    socklen = sizeof(sock);
    memset((char *)&sock,'\0',socklen);
--- 201,207 ----
  {
    ssize_t ret;
    struct sockaddr_in sock;
!   socklen_t socklen;
    
    socklen = sizeof(sock);
    memset((char *)&sock,'\0',socklen);
***************
*** 777,783 ****
  {
  	struct sockaddr sa;
  	struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
! 	int     length = sizeof(sa);
  	static pstring name_buf;
  	struct hostent *hp;
  	static int last_fd=-1;
--- 778,784 ----
  {
  	struct sockaddr sa;
  	struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
! 	socklen_t     length = sizeof(sa);
  	static pstring name_buf;
  	struct hostent *hp;
  	static int last_fd=-1;
***************
*** 823,829 ****
  {
  	struct sockaddr sa;
  	struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
! 	int     length = sizeof(sa);
  	static fstring addr_buf;
  	static int last_fd = -1;
  
--- 824,830 ----
  {
  	struct sockaddr sa;
  	struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
! 	socklen_t     length = sizeof(sa);
  	static fstring addr_buf;
  	static int last_fd = -1;
  


More information about the samba-technical mailing list