Пример #1
0
 static extern int sendto( uint s, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] string buf, int len, int flags, ref sockaddr to, int tolen);
Пример #2
0
 public static extern unsafe size_t sendto(int sockfd, void* buf, size_t len, int flags, sockaddr* dest_addr, socklen_t addrlen);
Пример #3
0
 public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error)
 {
     return Check(_uv_ip6_addr(ip, port, out addr), out error);
 }
Пример #4
0
 static extern int recvfrom(uint s, IntPtr buf, int len, int flags, ref sockaddr from, ref int fromlen);
Пример #5
0
 public static extern unsafe int bind(int sockfd, sockaddr* addr, socklen_t addrlen);
Пример #6
0
 public static extern int uv_ip6_addr(string ip, int port, out sockaddr addr);
Пример #7
0
 public static extern unsafe size_t recvfrom(int sockfd, void* buf, size_t len, int flags, sockaddr* dest_addr, socklen_t* addrlen);
Пример #8
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); }
Пример #9
0
 public static extern int sendto([In] IntPtr socketHandle, [In] byte[] pinnedBuffer, [In] int len, [In] SocketFlags socketFlags, ref sockaddr SockAdd, [In] int Size);
Пример #10
0
        public void AdressResolved(object sender, EventArgs info)
        {
            NSNetService ns = (NSNetService)sender;

            servicesFound.Remove(ns);

            ServiceLocation sl = new ServiceLocation(IPAddress.None, 0, "");

            foreach (var addr in ns.Addresses)
            {
                sockaddr socket_address = (sockaddr)Marshal.PtrToStructure(addr.Bytes, typeof(sockaddr));
                if (socket_address.sa_family != AF_INET)
                {
                    Logger.Info("Ignoring service since it's socket type is not AF_INET but {0:d}", socket_address.sa_family);
                    continue;
                }
                sockaddr_in IP4 = (sockaddr_in)Marshal.PtrToStructure(addr.Bytes, typeof(sockaddr_in));

                IPAddress address = new IPAddress(IP4.sin_addr);
                Logger.Info("Checking out service at {0}:{1}", address, ns.Port);
                sl = new ServiceLocation(address, (int)ns.Port, ns.Name);
                Logger.Debug("Got IP " + address.ToString());
                if (createdInterfaces.Keys.Contains(sl))
                {
                    Logger.Info("Skipping registration of service at {0}:{1} since already registerd", address, ns.Port);
                    return;
                }
            }

            Logger.Info("A new ethernet interface was found at {0}:{1}", sl.ip, sl.port);
            Logger.Info("Starting new thread to instantiate Ethernet scope");
            Thread EtherScopeInstantiationThread = new Thread(delegate()
            {
                SmartScopeInterfaceEthernet ethif = null;
                try
                {
                    ethif = new SmartScopeInterfaceEthernet(
                        sl.ip, sl.port, OnInterfaceDisconnect);
                    if (ethif.Connected)
                    {
                        createdInterfaces.Add(sl, ethif);
                        if (onConnect != null)
                        {
                            onConnect(ethif, true);
                        }
                    }
                    else
                    {
                        LabNation.Common.Logger.Info("... but could not connect to ethernet interface");
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to connect to ethernet scope {0}:{1}", e.GetType(), e.Message);
                    if (ethif != null)
                    {
                        if (createdInterfaces.ContainsKey(sl))
                        {
                            createdInterfaces.Remove(sl);
                            if (onConnect != null)
                            {
                                onConnect(ethif, false);
                            }
                        }
                    }
                }
            });

            EtherScopeInstantiationThread.Name = "Ethernet Scope instantiation";
            EtherScopeInstantiationThread.Start();
        }
Пример #11
0
 private static extern int bind(IntPtr socket, ref sockaddr addr, int namelen);
Пример #12
0
 private static extern int connect(IntPtr Sock, ref sockaddr SockAdd, int Size);
Пример #13
0
 public static extern int getpeername([In] IntPtr socketHandle, ref sockaddr SockAdd, ref int Size);
Пример #14
0
 public static extern unsafe int connect(int sockfd, sockaddr* addr, socklen_t addrlen);
Пример #15
0
 public static extern int connect(IntPtr socketHandle, ref sockaddr Address, ref int Addresslen);
Пример #16
0
 private static (ptr <netFD>, error) unixSocket(context.Context ctx, @string net, sockaddr laddr, sockaddr raddr, @string mode, Func <@string, @string, syscall.RawConn, error> ctrlFn)
 {
     ptr <netFD> _p0 = default !;
Пример #17
0
 public static extern int getpeername(IntPtr s, ref sockaddr Address, ref int namelen);
Пример #18
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); }
Пример #19
0
 // socket returns a network file descriptor that is ready for
 // asynchronous I/O using the network poller.
 private static (ptr <netFD>, error) socket(context.Context ctx, @string net, long family, long sotype, long proto, bool ipv6only, sockaddr laddr, sockaddr raddr, Func <@string, @string, syscall.RawConn, error> ctrlFn)
 {
     ptr <netFD> fd  = default !;
Пример #20
0
 public static extern int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags);
Пример #21
0
 public static extern int connect(IntPtr socketHandle, ref sockaddr Address, ref int Addresslen);
Пример #22
0
 public int sceNetInetBind(int SocketId, sockaddr *Address, socklen_t AddressLength)
 {
     throw(new NotImplementedException());
 }
Пример #23
0
 public static extern int getpeername(IntPtr s, ref sockaddr Address, ref int namelen);
Пример #24
0
 public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags)
 {
     handle.Validate();
     Check(_uv_tcp_bind(handle, ref addr, flags));
 }
Пример #25
0
        // Implemented functions from IDevice
        public DevicePool Inquire()
        {
            DevicePool pool = new DevicePool();
            IntPtr lpwsaqueryset = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WSAQUERYSET)));
            WSAQUERYSET wsaqueryset = new WSAQUERYSET();
            wsaqueryset.dwSize = Marshal.SizeOf(typeof(WSAQUERYSET));
            wsaqueryset.dwNameSpace = 16;
            WSAData data = new WSAData();
            data.wHighVersion = 2;
            data.wVersion = 2;
            Marshal.StructureToPtr(wsaqueryset,lpwsaqueryset,false);
            int flags = (int)0x0002;
            flags |= (int)(0x1000|0x0010|0x0100);
            Int32 handle = 0;

            int result = 0;

            result = WSAStartup(36,data);
            if(result != 0)
            {
                throw new Exception("WSA Error, make sure you have the newest version (at least 2.2) of Winsock2!");
            }
            result = WSALookupServiceBegin(wsaqueryset,flags,ref handle);

            if (result == -1)
            {
                int error = WSAGetLastError();
                if (error == 10108) // No device attached
                {
                    throw new Exception("You do not have a bluetooth device on your system.");
                }
            }
            while (0 == result)
            {
                Int32 dwBuffer = 0x10000;
                IntPtr pBuffer = Marshal.AllocHGlobal(dwBuffer);

                WSAQUERYSET qsResult = new WSAQUERYSET() ;

                result = WSALookupServiceNext(handle, flags,
                ref dwBuffer, pBuffer);

                if (0==result)
                {
                    Marshal.PtrToStructure(pBuffer, qsResult);
                    CS_ADDR_INFO addr = new CS_ADDR_INFO();
                    Marshal.PtrToStructure(qsResult.lpcsaBuffer, addr);
                    sockaddr sa = new sockaddr();
                    Marshal.PtrToStructure(addr.RemoteAddr.lpSockaddr,sa);
                    monotooth.BluetoothAddress ba = new BluetoothAddress();
                    for (int i = 5; i >= 0; i--)
                    {
                        ba.Array[i] = sa.sa_data[i];
                    }
                    WindowsRemoteDevice dev = new WindowsRemoteDevice(ba, qsResult.szServiceInstanceName);
                    pool.Add(dev);

                } else
                {
                WSALookupServiceEnd(handle);
                }
                Marshal.FreeHGlobal(pBuffer);
            }

            Marshal.FreeHGlobal(lpwsaqueryset);
            WSACleanup();
            return pool;
        }
Пример #26
0
        static int recvfrom_Hooked(uint s, IntPtr buf, int len, int flags, ref sockaddr from, ref int fromlen)
        {
            int res = 0;
            try
            {
                MalMonInject This = (MalMonInject)HookRuntimeInfo.Callback;
                res = This.NetApis.recvfromFunc(s, buf, len, flags, ref from, ref fromlen);

                lock (This.Queue)
                {
                    //Time + Pid + Tid + Api + Content
                    This.Queue.Push(ActivityMonitor.FormatMessage(DateTime.Now, "recvfrom", Marshal.PtrToStringUni(buf)));
                }
            }
            catch
            {
            }

            return res;

        }
Пример #27
0
 public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags)
 {
     handle.Validate();
     Check(_uv_tcp_bind(handle, ref addr, flags));
 }
Пример #28
0
        static int sendto_Hooked( uint s, [MarshalAsAttribute(UnmanagedType.LPStr)] string buf, int len, int flags, ref sockaddr to, int tolen)
        {
            try
            {
                MalMonInject This = (MalMonInject)HookRuntimeInfo.Callback;

                lock (This.Queue)
                {
                    //Time + Pid + Tid + Api + Content
                    This.Queue.Push(ActivityMonitor.FormatMessage(DateTime.Now, "send", buf));
                }
            }
            catch
            {
            }

            return send(s, buf, len, flags);
        }
Пример #29
0
 public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error)
 {
     return(Check(_uv_ip4_addr(ip, port, out addr), out error));
 }
Пример #30
0
 public static extern unsafe int getsockname(int sockfd, sockaddr* addr, socklen_t* addrlen);
Пример #31
0
 public static extern unsafe int accept(int sockfd, sockaddr* addr, socklen_t* addrlen);
Пример #32
0
 public static extern unsafe int getnameinfo(sockaddr* sa, socklen_t salen, StringBuilder host, socklen_t hostlen, StringBuilder serv, socklen_t servlen, int flags);
Пример #33
0
        public TcpConnection accept()
        {
            Debug.Assert(dispatcher != null);
            Debug.Assert(context == null);
            if (dispatcher.interrupted())
            {
                throw InterruptedException();
            }

            ContextPair      contextPair     = new ContextPair();
            OperationContext listenerContext = new OperationContext();

            listenerContext.interrupted = false;
            listenerContext.context     = dispatcher.getCurrentContext();

            contextPair.writeContext = null;
            contextPair.readContext  = listenerContext;

            epoll_event listenEvent = new epoll_event();

            listenEvent.events   = EPOLLIN | EPOLLONESHOT;
            listenEvent.data.ptr = contextPair;
            string message;

            if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, listener, listenEvent) == -1)
            {
                message = "epoll_ctl failed, " + lastErrorMessage();
            }
            else
            {
                context = listenerContext;
                dispatcher.getCurrentContext().interruptProcedure = () =>
                {
                    Debug.Assert(dispatcher != null);
                    Debug.Assert(context != null);
                    OperationContext listenerContext = (OperationContext)context;
                    if (!listenerContext.interrupted)
                    {
                        epoll_event listenEvent = new epoll_event();
                        listenEvent.events   = EPOLLONESHOT;
                        listenEvent.data.ptr = null;

                        if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, listener, listenEvent) == -1)
                        {
                            throw new System.Exception("TcpListener::accept, interrupt procedure, epoll_ctl failed, " + lastErrorMessage());
                        }

                        listenerContext.interrupted = true;
                        dispatcher.pushContext(listenerContext.context);
                    }
                };

                dispatcher.dispatch();
                dispatcher.getCurrentContext().interruptProcedure = null;
                Debug.Assert(dispatcher != null);
                Debug.Assert(listenerContext.context == dispatcher.getCurrentContext());
                Debug.Assert(contextPair.writeContext == null);
                Debug.Assert(context == &listenerContext);
                context = null;
                listenerContext.context = null;
                if (listenerContext.interrupted)
                {
                    throw InterruptedException();
                }

                if ((listenerContext.events & (EPOLLERR | EPOLLHUP)) != 0)
                {
                    throw new System.Exception("TcpListener::accept, accepting failed");
                }

                sockaddr  inAddr     = new sockaddr();
                socklen_t inLen      = sizeof(sockaddr);
                int       connection = global::accept(listener, inAddr, inLen);
                if (connection == -1)
                {
                    message = "accept failed, " + lastErrorMessage();
                }
                else
                {
                    int flags = fcntl(connection, F_GETFL, 0);
                    if (flags == -1 || fcntl(connection, F_SETFL, flags | O_NONBLOCK) == -1)
                    {
                        message = "fcntl failed, " + lastErrorMessage();
                    }
                    else
                    {
                        return(new TcpConnection(dispatcher, connection));
                    }

                    int result = close(connection);
                    if (result != 0)
                    {
                    }
                    Debug.Assert(result != -1);
                }
            }

            throw new System.Exception("TcpListener::accept, " + message);
        }