Example #1
0
        unsafe internal static IPEndPoint GetIPEndPoint(IntPtr sockaddr, bool map)
        {
            sockaddr *sa = (sockaddr *)sockaddr;

            byte[] addr = new byte[64];
            int    r;

            if (sa->sin_family == 2)
            {
                r = uv_ip4_name(sockaddr, addr, (IntPtr)addr.Length);
            }
            else
            {
                r = uv_ip6_name(sockaddr, addr, (IntPtr)addr.Length);
            }
            Ensure.Success(r);

            IPAddress ip = IPAddress.Parse(System.Text.Encoding.ASCII.GetString(addr, 0, strlen(addr)));

            var bytes = ip.GetAddressBytes();

            if (map && ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 && IsMapping(bytes))
            {
                ip = GetMapping(bytes);
            }

            return(new IPEndPoint(ip, ntohs(sa->sin_port)));
        }
Example #2
0
        unsafe internal static IPEndPoint GetIPEndPoint(IntPtr sockaddr)
        {
            sockaddr *sa = (sockaddr *)sockaddr;

            byte[] addr = new byte[64];
            if (sa->sin_family == 2)
            {
                uv_ip4_name(sockaddr, addr, (IntPtr)addr.Length);
            }
            else
            {
                uv_ip6_name(sockaddr, addr, (IntPtr)addr.Length);
            }

            int i = 0;

            while (i < addr.Length && addr[i] != 0)
            {
                i++;
            }

            IPAddress ip = IPAddress.Parse(System.Text.Encoding.ASCII.GetString(addr, 0, i));

            return(new IPEndPoint(ip, ntohs(sa->sin_port)));
        }
Example #3
0
 /// <summary>
 /// Adds a connect to the Submission Queue without it being submitted.
 /// The actual submission can be deferred to avoid unnecessary memory barriers.
 /// </summary>
 /// <param name="fd">The socket to connect on</param>
 /// <param name="addr">The address to connect to</param>
 /// <param name="addrLen">The length of the address</param>
 /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param>
 /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param>
 /// <returns><code>false</code> if the submission queue is full. <code>true</code> otherwise.</returns>
 /// <exception cref="SubmissionQueueFullException">If no more free space in the Submission Queue is available</exception>
 public void PrepareConnect(int fd, sockaddr *addr, socklen_t addrLen, ulong userData = 0, SubmissionOption options = SubmissionOption.None)
 {
     if (!TryPrepareConnect(fd, addr, addrLen, userData, options))
     {
         ThrowSubmissionQueueFullException();
     }
 }
Example #4
0
        //__socketcall int bind(int, const struct sockaddr *, int);


        //__socketcall ssize_t recvfrom(int, void*, size_t, unsigned int, const struct sockaddr *, socklen_t*);
        public unsafe static int recvfrom(
            this SOCKET s,
            byte *buf,
            int len,
            uint flags,
            sockaddr *from,
            int *fromlen
            )
        {
            return(default(int));
        }
Example #5
0
        public unsafe LinuxSocket Accept4(sockaddr *addr, socklen_t *addrLen, int flags)
        {
            int rv;
            int error = 0;

            do
            {
                rv = accept4(_fd, addr, addrLen, flags);
            } while (rv == -1 && Retry(error = errno));
            if (rv == -1)
            {
                ThrowHelper.ThrowNewErrnoException(error);
            }

            return(rv);
Example #6
0
        /// <summary>
        /// Prepares this Submission Queue Entry as a connect.
        /// </summary>
        /// <param name="fd">The socket to connect on</param>
        /// <param name="addr">The address to connect to</param>
        /// <param name="addrLen">The length of the address</param>
        /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param>
        /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param>
        /// <param name="personality">The personality to impersonate for this submission</param>
        public void PrepareConnect(int fd, sockaddr *addr, socklen_t addrLen, ulong userData = 0, SubmissionOption options = SubmissionOption.None, ushort personality = 0)
        {
            var sqe = _sqe;

            unchecked
            {
                sqe->opcode      = IORING_OP_CONNECT;
                sqe->flags       = (byte)options;
                sqe->fd          = fd;
                sqe->off         = addrLen;
                sqe->addr        = (ulong)addr;
                sqe->user_data   = userData;
                sqe->personality = personality;
            }
        }
Example #7
0
        /// <summary>
        /// Prepares this Submission Queue Entry as an accept.
        /// </summary>
        /// <param name="fd">File descriptor to accept from</param>
        /// <param name="addr">(out) the address of the connected client.</param>
        /// <param name="addrLen">(out) the length of the address</param>
        /// <param name="flags">Flags as per accept4</param>
        /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param>
        /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param>
        /// <param name="personality">The personality to impersonate for this submission</param>
        public void PrepareAccept(int fd, sockaddr *addr, socklen_t *addrLen, int flags, ulong userData = 0, SubmissionOption options = SubmissionOption.None, ushort personality = 0)
        {
            var sqe = _sqe;

            unchecked
            {
                sqe->opcode       = IORING_OP_ACCEPT;
                sqe->flags        = (byte)options;
                sqe->fd           = fd;
                sqe->off          = (ulong)addrLen;
                sqe->addr         = (ulong)addr;
                sqe->accept_flags = (uint)flags;
                sqe->user_data    = userData;
                sqe->personality  = personality;
            }
        }
Example #8
0
 internal unsafe IpV6SocketAddress(sockaddr *address)
     : base(*(ushort *)address)
 {
     this._address = new IpV6Address(BitSequence.Merge(*(byte *)((IntPtr)address + 8L), *(byte *)((IntPtr)address + 8L + 1L), *(byte *)((IntPtr)address + 8L + 2L), *(byte *)((IntPtr)address + 8L + 3L), *(byte *)((IntPtr)address + 8L + 4L), *(byte *)((IntPtr)address + 8L + 5L), *(byte *)((IntPtr)address + 8L + 6L), *(byte *)((IntPtr)address + 8L + 7L), *(byte *)((IntPtr)address + 8L + 8L), *(byte *)((IntPtr)address + 8L + 9L), *(byte *)((IntPtr)address + 8L + 10L), *(byte *)((IntPtr)address + 8L + 11L), *(byte *)((IntPtr)address + 8L + 12L), *(byte *)((IntPtr)address + 8L + 13L), *(byte *)((IntPtr)address + 8L + 14L), *(byte *)((IntPtr)address + 8L + 15L)));
 }
Example #9
0
 /// <summary>
 /// Attempts to add a connect to the Submission Queue without it being submitted.
 /// The actual submission can be deferred to avoid unnecessary memory barriers.
 /// </summary>
 /// <param name="fd">The socket to connect on</param>
 /// <param name="addr">The address to connect to</param>
 /// <param name="addrLen">The length of the address</param>
 /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param>
 /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param>
 /// <returns><code>false</code> if the submission queue is full. <code>true</code> otherwise.</returns>
 public bool TryPrepareConnect(int fd, sockaddr *addr, socklen_t addrLen, ulong userData = 0, SubmissionOption options = SubmissionOption.None)
 {
     return(TryPrepareReadWrite(IORING_OP_CONNECT, fd, addr, 0, (uint)addrLen, 0, userData, options));
 }
Example #10
0
 public static extern unsafe int connect(int sockfd, sockaddr *addr, socklen_t addrlen);
Example #11
0
 public static extern unsafe size_t recvfrom(int sockfd, void *buf, size_t len, int flags, sockaddr *dest_addr, socklen_t *addrlen);
Example #12
0
 public static extern unsafe int getsockname(int sockfd, sockaddr *addr, socklen_t *addrlen);
Example #13
0
 public int sceNetInetAccept(int SocketId, sockaddr *Address, socklen_t *AddressLength)
 {
     throw new NotImplementedException();
 }
Example #14
0
 public static extern unsafe size_t sendto(int sockfd, void *buf, size_t len, int flags, sockaddr *dest_addr, socklen_t addrlen);
Example #15
0
 /// <summary>
 /// Attempts to add an accept to the Submission Queue without it being submitted.
 /// The actual submission can be deferred to avoid unnecessary memory barriers.
 /// </summary>
 /// <param name="fd">File descriptor to accept on</param>
 /// <param name="addr">(out) the address of the connected client.</param>
 /// <param name="addrLen">(out) the length of the address</param>
 /// <param name="flags">Flags as per accept4</param>
 /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param>
 /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param>
 /// <returns><code>false</code> if the submission queue is full. <code>true</code> otherwise.</returns>
 public bool TryPrepareAccept(int fd, sockaddr *addr, socklen_t *addrLen, int flags, ulong userData = 0, SubmissionOption options = SubmissionOption.None)
 => TryPrepareReadWrite(IORING_OP_ACCEPT, fd, addr, 0, (long)addrLen, flags, userData, options);
Example #16
0
 internal unsafe IpV4SocketAddress(sockaddr *address)
     : base(*(ushort *)address)
 {
     this._address = new IpV4Address((uint)IPAddress.HostToNetworkOrder(*(int *)((IntPtr)address + 4L)));
 }
Example #17
0
        //int setsockopt(int s, int level, int optname, const void* optval, int optlen);

        public unsafe static int bind(this SOCKET s, sockaddr *name, int namelen)
        {
            return(default(int));
        }
Example #18
0
 public static extern unsafe int getnameinfo(sockaddr *sa, socklen_t salen, StringBuilder host, socklen_t hostlen, StringBuilder serv, socklen_t servlen, int flags);
Example #19
0
 public static extern unsafe int accept(int sockfd, sockaddr *addr, socklen_t *addrlen);
Example #20
0
 public int sceNetInetBind(int SocketId, sockaddr *Address, socklen_t AddressLength)
 {
     throw(new NotImplementedException());
 }
Example #21
0
 public static extern unsafe int bind(int sockfd, sockaddr *addr, socklen_t addrlen);