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

Submitted by:  Mark Pettigrew <mpettigr>
Submitted on:  Tue 27 Nov 2007 08:00:18 PM UTC  
 
Category: sockets/netconnSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned 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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 02 Dec 2007 03:32:48 PM UTCgoldsimonStatusConfirmed=>Fixed
      Assigned toNone=>goldsimon
      Open/ClosedOpen=>Closed
    Tue 27 Nov 2007 08:10:19 PM UTCgoldsimonStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1