D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9384 - std.socket: UnixAddress broken on Linux and others
Summary: std.socket: UnixAddress broken on Linux and others
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-24 00:30 UTC by Rob T
Modified: 2013-09-08 05:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rob T 2013-01-24 00:30:51 UTC
std.socket is missing the following import:

import core.sys.posix.sys.un;

Even when adding in the missing import, the implementation of UnixAddress is broken.

Here's my quick fix for Linux (there may be problems with it), there also needs to be versions for OSX and FreeBSD because sockaddr_un is slightly different.

import std.c.linux.socket;
import core.sys.posix.sys.un;

class UnixAddress: Address
{
	private:
		sockaddr_un sun;

		this()
		{
		}

	public:
	
	    override @property sockaddr* name()
		{
			return cast(sockaddr*)&sun;
		}

		override @property const(sockaddr)* name() const
		{
			return cast(const(sockaddr)*)&sun;
		}

		override @property socklen_t nameLen() const
		{
			return cast(socklen_t) sun.sizeof;
		}

        this(in char[] path)
        {
            sun.sun_family = AF_UNIX;
            sun.sun_path.ptr[0..path.length] = cast(byte[])path;
            sun.sun_path.ptr[path.length] = 0;
        }

        @property string path() const
        {
            return to!string(sun.sun_path.ptr);
        }

        override string toString() const
        {
            return path;
        }
}