tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: struct sockaddr_storage issues



Sad Clouds <cryintothebluesky%gmail.com@localhost> writes:

> Hi, I'm seeing issues on NetBSD where connect() returns error and sets
> errno to "Invalid argument". Below is a fragment of code that causes
> this:
>
> struct sockaddr_storage addr
> ...
> fd = socket(addr.ss_family, SOCK_STREAM, 0)
> connect(fd, (struct sockaddr *)&addr, sizeof(addr))

How are you setting the fields?

> If I replace the above connect() with
>
> connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr))
>
> then connect() succeeds. Looks like NetBSD is not happy about the size
> of struct sockaddr_storage. On Linux this works correctly.

How does casting to a different pointer type change the assembly
language?  I don't mean that in a theoretical way - I mean compile them
both with -S and diff.

> sizeof(struct sockaddr)=16
> sizeof(struct sockaddr_storage)=128

You left out the likely important part, how you initialized the fields
in the sockaddr, which needs to actually be of the type corresponding to
the AF.

> Is this a NetBSD specific bug, or am I not using sockaddr_storage
> correctly?

My guess is that you are doing something that leads to UB, said vaguely
and broadly.

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index