Open Bug 442294 Opened 16 years ago Updated 2 years ago

NSPR doesn't provide any mechanism for disconnecting UDP sockets

Categories

(NSPR :: NSPR, defect)

x86
macOS
defect

Tracking

(Not tracked)

REOPENED

People

(Reporter: alex, Unassigned)

References

Details

Attachments

(1 file)

For UDP sockets, POSIX connect() can be called to (re-)connect or disconnect the socket. The latter is done by calling connect() with a "null address". According to Stevens' Unix Network Programming (Vol 1, 3rd ed., sec. 8.11, p. 254): "The most portable solution is to zero out an address structure, set the family to AF_UNSPEC and pass it to connect."

Unfortunately NSPR's PR_Connect() doesn't accept PRNetAddr structures with family PR_AF_UNSPEC - at least not the implementation in ptio.c (pt_Connect).
One easy way of getting it to work for pt_Connect is to remove the assertion
    PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
and change _PR_NetAddrSize() to return something like sizeof(addr->raw) instead of 0 for PR_AF_UNSPEC addresses. I'm a little unsure about the wider implications though.
We should be able to change PR_Connect() to allow this.
Could you test your proposed changes?  They seem good to
me.
Status: NEW → ASSIGNED
I've discovered that calling PR_Connect with PR_AF_INET "0.0.0.0" (or PR_AF_INET6 "::", as appropriate for a given socket) works just as well as PR_AF_UNSPEC. I've tested this on Linux, OS X and Windows. 
So it looks like the changes I was proposing above aren't needed... they only worked for platforms using ptio.c anyway.
Shall I close the bug as INVALID?
OK.  It would still be nice if you could attach your
patch to this bug report for future reference.
Someone who reads Stevens' is likely to try PR_AF_UNSPEC
first, so supporting that could still be useful.  We
could easily adapt your changes to ptio.c for
platforms using prsocket.c.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → WONTFIX
Resolution: WONTFIX → INVALID
It turns out that PR_AF_INET/PR_AF_INET6 don't work on Linux after all; the linux networking code explicitly checks for AF_UNSPEC for disconnecting sockets. My unit test didn't pick this up as I only tested the loopback interface.

So it would be great if we could legalize PR_AD_UNSPEC after all. Patch coming up.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Attached patch patch v1Splinter Review
Proposed patch allowing a PR_AF_UNSPEC address to be passed to pt_Connect.
Attachment #332262 - Flags: review?(wtc)

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: wtc → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: