//send peer credentials null byte
        //different platforms do this in different ways
#if HAVE_CMSGCRED
        unsafe void WriteBsdCred()
        {
            //null credentials byte
            byte buf = 0;

            IOVector iov = new IOVector();

            iov.Base   = (IntPtr)(&buf);
            iov.Length = 1;

            msghdr msg = new msghdr();

            msg.msg_iov    = &iov;
            msg.msg_iovlen = 1;

            cmsg cm = new cmsg();

            msg.msg_control    = (IntPtr)(&cm);
            msg.msg_controllen = (uint)sizeof(cmsg);
            cm.hdr.cmsg_len    = (uint)sizeof(cmsg);
            cm.hdr.cmsg_level  = 0xffff;         //SOL_SOCKET
            cm.hdr.cmsg_type   = 0x03;           //SCM_CREDS

            int written = UnixSocket.sendmsg(socket.Handle, (IntPtr)(&msg), 0);

            UnixMarshal.ThrowExceptionForLastErrorIf(written);
            if (written != 1)
            {
                throw new Exception("Failed to write credentials");
            }
        }
Ejemplo n.º 2
0
        internal UnixSocket OpenAbstractUnix(string path)
        {
            byte[]     sa     = GetSockAddrAbstract(path);
            UnixSocket client = new UnixSocket();

            client.Connect(sa);
            return(client);
        }
        public override void Open(string path, bool @abstract)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException("path");
            }

            if (@abstract)
            {
                socket = OpenAbstractUnix(path);
            }
            else
            {
                socket = OpenUnix(path);
            }

            //socket.Blocking = true;
            SocketHandle = (long)socket.Handle;
            Stream       = new UnixStream((int)socket.Handle);
        }
        public UnixSocket OpenUnix(string path)
        {
            byte[] p = Encoding.Default.GetBytes(path);

            byte[] sa = new byte[2 + p.Length + 1];

            //we use BitConverter to stay endian-safe
            byte[] afData = BitConverter.GetBytes(UnixSocket.AF_UNIX);
            sa[0] = afData[0];
            sa[1] = afData[1];

            for (int i = 0; i != p.Length; i++)
            {
                sa[2 + i] = p[i];
            }
            sa[2 + p.Length] = 0;             //null suffix for domain socket addresses, see unix(7)

            UnixSocket client = new UnixSocket();

            client.Connect(sa);

            return(client);
        }
        protected UnixSocket OpenAbstractUnix(string path)
        {
            byte[] p = Encoding.Default.GetBytes(path);

            byte[] sa = new byte[2 + 1 + p.Length];

            //we use BitConverter to stay endian-safe
            byte[] afData = BitConverter.GetBytes(UnixSocket.AF_UNIX);
            sa[0] = afData[0];
            sa[1] = afData[1];

            sa[2] = 0;             //null prefix for abstract domain socket addresses, see unix(7)
            for (int i = 0; i != p.Length; i++)
            {
                sa[3 + i] = p[i];
            }

            UnixSocket client = new UnixSocket();

            client.Connect(sa);

            return(client);
        }
Ejemplo n.º 6
0
 public UnixStream(UnixSocket usock)
 {
     this.usock = usock;
 }
Ejemplo n.º 7
0
 public UnixStream(int fd)
 {
     this.usock = new UnixSocket (fd);
 }
Ejemplo n.º 8
0
		public UnixSocket OpenUnix (string path)
		{
			byte[] p = Encoding.Default.GetBytes (path);

			byte[] sa = new byte[2 + p.Length + 1];

			//we use BitConverter to stay endian-safe
			byte[] afData = BitConverter.GetBytes (UnixSocket.AF_UNIX);
			sa[0] = afData[0];
			sa[1] = afData[1];

			for (int i = 0 ; i != p.Length ; i++)
				sa[2 + i] = p[i];
			sa[2 + p.Length] = 0; //null suffix for domain socket addresses, see unix(7)

			UnixSocket client = new UnixSocket ();
			client.Connect (sa);

			return client;
		}
Ejemplo n.º 9
0
		protected UnixSocket OpenAbstractUnix (string path)
		{
			byte[] p = Encoding.Default.GetBytes (path);

			byte[] sa = new byte[2 + 1 + p.Length];

			//we use BitConverter to stay endian-safe
			byte[] afData = BitConverter.GetBytes (UnixSocket.AF_UNIX);
			sa[0] = afData[0];
			sa[1] = afData[1];

			sa[2] = 0; //null prefix for abstract domain socket addresses, see unix(7)
			for (int i = 0 ; i != p.Length ; i++)
				sa[3 + i] = p[i];

			UnixSocket client = new UnixSocket ();
			client.Connect (sa);

			return client;
		}
Ejemplo n.º 10
0
		public override void Open (string path, bool @abstract)
		{
			if (String.IsNullOrEmpty (path))
				throw new ArgumentException ("path");

			if (@abstract)
				socket = OpenAbstractUnix (path);
			else
				socket = OpenUnix (path);

			//socket.Blocking = true;
			SocketHandle = (long)socket.Handle;
			Stream = new UnixStream ((int)socket.Handle);
		}