buglwIP - A Lightweight TCP/IP stack - Bugs: bug #29210, struct sockaddr

 
 

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

bug #29210: struct sockaddr

Submitted by:  hanhui <hanhui03>
Submitted on:  Sat 13 Mar 2010 04:31:59 AM UTC  
 
Category: sockets/netconnSeverity: 3 - Normal
Item Group: Change RequestStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned Release: None
lwIP version: CVS Head

Sun 14 Mar 2010 09:55:05 AM UTC, comment #5:

Fixed by checking for alignment in functions where casting from sockaddr to sockaddr_in.
Thanks for reporting.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Sat 13 Mar 2010 02:03:26 PM UTC, comment #4:

Unfortunately, that doesn't work as well, as it alignes both a1 and a2 on a 32-bit boundary and the struct gets 20 bytes long instead of 16 bytes.

Also the standard defines the struct to have a member of 'char sa_data[]', which means sizeof(sa_data) will return the size, which it won't for the define.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Sat 13 Mar 2010 01:37:03 PM UTC, comment #3:

I suggest that you can use the following definition:

struct sockaddr {
u8_t sa_len;
u8_t sa_family;
union {
char bytes[14];
struct {
u16_t a1;
u32_t a2;
} alignment;
} data;
#define sa_data data.bytes
};

hanhui <hanhui03>
Sat 13 Mar 2010 11:54:30 AM UTC, comment #2:

Yeah. sorry for the mess. I'll change it back to the old definition, didn't think of the standard defining it...

The downside is that we have to use memcpy then to copy the data from sockaddr to sockaddr_in in bind() and connect(). I'm not aware of any bug reports here, but the compiler warns about different alignment requirements when casting, which is correct.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Sat 13 Mar 2010 11:29:47 AM UTC, comment #1:

This was changed recently, and I agree that the current definition is a little odd. I don't want to change it back as it has probably been made like that for a reason. We need to find a better way to ensure the alignment requirements though, as the union is not a good solution for a structure like this that forms part of the standard API.

Kieran Mansley <kieranm>
Project Administrator
Sat 13 Mar 2010 04:31:59 AM UTC, original submission:

In most systems.

struct sockaddr is defined as:

struct sockaddr {
unsigned short sa_family;
char sa_data[14];
};

Definition of the lwip current method of sockaddr may cause compatibility problems.

for example: (a wifi driver example)
======================================================
struct sockaddr tmp;
memset(&tmp.sa_data, 0, 14);
======================================================

hanhui <hanhui03>

 

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 kieranm (Posted a comment)
  • -unavailable- added by hanhui03 (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 14 Mar 2010 09:55:05 AM UTCgoldsimonStatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Sat 13 Mar 2010 11:54:30 AM UTCgoldsimonStatusNone=>In Progress
      Assigned toNone=>goldsimon

    Back to the top


    Powered by Savane 3.1-cleanup1