buglwIP - A Lightweight TCP/IP stack - Bugs: bug #21654, #ifndef FD_SET ... #endif region...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #21654: #ifndef FD_SET ... #endif region too large - should not include struct timeval

Submitter:  Mark Pettigrew <mpettigr>
Submitted:  Tue 27 Nov 2007 08:00:18 PM UTC
   
 
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  None

Sun 02 Dec 2007 03:32:48 PM UTC, comment #2: 

Fixed. #define LWIP_TIMEVAL_PRIVATE to 0 if you want to use the struct timeval provided by your system or compiler (and add an include for that in cc.h).

Simon Goldschmidt <goldsimon>
Group administrator
Tue 27 Nov 2007 08:10:19 PM UTC, comment #1: 

Hehe, just two days ago I was thinking about changing that part ;-)

Simon Goldschmidt <goldsimon>
Group administrator
Tue 27 Nov 2007 08:00:18 PM UTC, original submission:  

I am compiling LWIP v1.2.0 (stable) for the Xilinx Microblaze (GCC 3.4.1).

I get errors when I compile sockets.c.  The problem boils down to the following code excerpt in sockets.h:

/* FD_SET used for lwip_select */
#ifndef FD_SET
  #undef  FD_SETSIZE
  /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
  #define FD_SETSIZE    MEMP_NUM_NETCONN
  #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
  #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
  #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
  #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))

  typedef struct fd_set {
          unsigned char fd_bits [(FD_SETSIZE+7)/8];
        } fd_set;

/*

  • only define this in sockets.c so it does not interfere
  • with other projects namespaces where timeval is present

 */
#ifndef LWIP_TIMEVAL_PRIVATE
#define LWIP_TIMEVAL_PRIVATE 1
#endif

#if LWIP_TIMEVAL_PRIVATE
  struct timeval {
    long    tv_sec;         /* seconds */
    long    tv_usec;        /* and microseconds */
  };
#endif /* LWIP_TIMEVAL_PRIVATE */

#endif /* FD_SET */


The problem is that FD_SET is already defined in sys/types.h for the Microblaze so this section of code is skipped.  However, the struct timeval definition is used by a few lines down from here in the declaration of the function lwip_select:

int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
                struct timeval *timeout);

The solution is to move "#endif /* FD_SET */" above the definition of struct timeval.  That is,

===============
/* FD_SET used for lwip_select */
#ifndef FD_SET
  #undef  FD_SETSIZE
  /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
  #define FD_SETSIZE    MEMP_NUM_NETCONN
  #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
  #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
  #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
  #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))

  typedef struct fd_set {
          unsigned char fd_bits [(FD_SETSIZE+7)/8];
        } fd_set;
#endif /* FD_SET */

/*

  • only define this in sockets.c so it does not interfere
  • with other projects namespaces where timeval is present

 */
#ifndef LWIP_TIMEVAL_PRIVATE
#define LWIP_TIMEVAL_PRIVATE 1
#endif

#if LWIP_TIMEVAL_PRIVATE
  struct timeval {
    long    tv_sec;         /* seconds */
    long    tv_usec;        /* and microseconds */
  };
#endif /* LWIP_TIMEVAL_PRIVATE */

In this solution, struct timeval is always defined in sockets.h because it is always used by the lwip_select declaration.

Mark Pettigrew <mpettigr>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by mpettigr (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-12-02 goldsimon StatusConfirmed Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2007-11-27 goldsimon StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code