lwip_connect:无效地址\”失败的错误?(lwip_connect: invalid ad

2019-10-24 06:31发布

我试图连接到使用RedPark的RedSocket SDK.Am提示以下错误:Xamarin绑定项目插座

lwip_connect:无效地址”在/Users/jeremy/Dev/Folsom/Folsom_570/RecEthernet/tcp/api/sockets.c在行495失败

但我没有看到任何用户在我的Mac存在同名,谁能帮助我理解的根本原因?

我结合项目的ApiDefinitions.cs代码

    namespace RedparkEthernetBinding
{
    using System.Net;
    using System;
    using Foundation;
    using RedparkEthernetBinding;

    // @protocol RedSocketManagerProtocol <NSObject>
    [Protocol]
    [BaseType (typeof(NSObject))]
     interface RedSocketManagerProtocol
    {
        // @required -(void)configureNetworkInterface:(NSString *)deviceIPAddress gateway:(NSString *)gateway netmask:(NSString *)netmask dns:(NSString *)dns;

        [Export ("configureNetworkInterface:gateway:netmask:dns:")]
        void ConfigureNetworkInterface (string deviceIPAddress, string gateway, string netmask, string dns);

        // @required -(NSString *)ipAddress;

        [Export ("ipAddress")]
        string IpAddress { get; }

        // @required -(NSString *)gatewayAddress;

        [Export ("gatewayAddress")]
        string GatewayAddress { get; }

        // @required -(NSString *)netmask;

        [Export ("netmask")]
        string Netmask { get; }

        // @required -(NSString *)dnsAddress;

        [Export ("dnsAddress")]
        string DnsAddress { get; }

        // @required -(int)socket:(int)domain type:(int)type protocol:(int)protocol;

        [Export ("socket:type:protocol:")]
        int Socket (int domain, int type, int protocol);

        // @required -(int)accept:(int)s addr:(struct sockaddr *)addr addrlen:(socklen_t *)addrlen;

        //[Abstract]
        [Export ("accept:addr:addrlen:")]
        unsafe int Accept (int s, IntPtr addr, uint addrlen);

        // @required -(void)acceptAsync:(int)listenSocket addr:(struct sockaddr *)addr addrlen:(socklen_t *)addrlen;

        [Export ("acceptAsync:addr:addrlen:")]
        unsafe void AcceptAsync (int listenSocket,IntPtr addr, uint addrlen);

        // @required -(int)bind:(int)s name:(const struct sockaddr *)name nameline:(socklen_t)namelen;

        [Export ("bind:name:nameline:")]
        unsafe int Bind (int s,IntPtr name, uint namelen);

        // @required -(int)shutdown:(int)s how:(int)how;

        [Export ("shutdown:how:")]
        int Shutdown (int s, int how);

        // @required -(int)getpeername:(int)s name:(struct sockaddr *)name namelen:(socklen_t *)namelen;

        [Export ("getpeername:name:namelen:")]
        unsafe int Getpeername (int s,IntPtr name, uint namelen);

        // @required -(int)getsockname:(int)s name:(struct sockaddr *)name namelen:(socklen_t *)namelen;

        [Export ("getsockname:name:namelen:")]
        unsafe int Getsockname (int s,IntPtr name, uint namelen);

        // @required -(int)getsockopt:(int)s level:(int)level optname:(int)optname optval:(void *)optval optlen:(socklen_t *)optlen;

        [Export ("getsockopt:level:optname:optval:optlen:")]
        unsafe int Getsockopt (int s, int level, int optname, IntPtr optval, uint optlen);

        // @required -(int)setsockopt:(int)s level:(int)level optname:(int)optname optval:(const void *)optval opelen:(socklen_t)optlen;

        [Export ("setsockopt:level:optname:optval:opelen:")]
        unsafe int Setsockopt (int s, int level, int optname, IntPtr optval, uint optlen);

        // @required -(int)close:(int)s;

        [Export ("close:")]
        int Close (int s);

        // @required -(int)connect:(int)s sockaddr:(const struct sockaddr *)name namelen:(socklen_t)namelen;

        [Export ("connect:sockaddr:namelen:")]
        unsafe int Connect (int s, IntPtr name, uint namelen);

        // @required -(int)listen:(int)s backlog:(int)backlog;

        [Export ("listen:backlog:")]
        int Listen (int s, int backlog);

        // @required -(int)recv:(int)s mem:(void *)mem len:(size_t)len flags:(int)flags;

        [Export ("recv:mem:len:flags:")]
        unsafe int Recv (int s, IntPtr mem, nuint len, int flags);

        // @required -(int)read:(int)s mem:(void *)mem len:(size_t)len;

        [Export ("read:mem:len:")]
        unsafe int Read (int s, IntPtr mem, nuint len);

        // @required -(int)recvfrom:(int)s mem:(void *)mem len:(size_t)len flags:(int)flags from:(struct sockaddr *)from fromlen:(socklen_t *)fromlen;

        [Export ("recvfrom:mem:len:flags:from:fromlen:")]
        unsafe int Recvfrom (int s, IntPtr mem, nuint len, int flags,IntPtr from, uint fromlen);

        // @required -(void)recvAsync:(int)sock buffer:(void *)buffer length:(size_t)length;

        [Export ("recvAsync:buffer:length:")]
        unsafe void RecvAsync (int sock, IntPtr buffer, nuint length);

        // @required -(int)send:(int)s dataptr:(const void *)dataptr size:(size_t)size flags:(int)flags;

        [Export ("send:dataptr:size:flags:")]
        unsafe int Send (int s, IntPtr dataptr, nuint size, int flags);

        // @required -(int)sendto:(int)s dataprt:(const void *)dataptr size:(size_t)size flags:(int)flags to:(const struct sockaddr *)to tolen:(socklen_t)tolen;

        [Export ("sendto:dataprt:size:flags:to:tolen:")]
        unsafe int Sendto (int s, IntPtr dataptr, nuint size, int flags, IntPtr to, uint tolen);

        // @required -(int)write:(int)s dataptr:(const void *)dataptr size:(size_t)size;

        [Export ("write:dataptr:size:")]
        unsafe int Write (int s, IntPtr dataptr, nuint size);

//      // @required -(int)select:(int)maxfdp1 readset:(fd_set *)readset writeset:(fd_set *)writeset exceptset:(fd_set *)exceptset timeout:(struct timeval *)timeout;
//   
//      [Export ("select:readset:writeset:exceptset:timeout:")]
//      unsafe int Select (int maxfdp1, fd_set readset, fd_set writeset, fd_set exceptset, timeval timeout);

        // @required -(int)ioctl:(int)s cmd:(long)cmd argp:(void *)argp;

        [Export ("ioctl:cmd:argp:")]
        unsafe int Ioctl (int s, nint cmd, IntPtr argp);

        // @required -(int)fcntl:(int)s cmd:(int)cmd val:(int)val;

        [Export ("fcntl:cmd:val:")]
        int Fcntl (int s, int cmd, int val);

        // @required -(int)abort_recv:(int)s;

        [Export ("abort_recv:")]
        int Abort_recv (int s);

        // @required -(int)abort_all:(int)s;

        [Export ("abort_all:")]
        int Abort_all (int s);

        [Export("Delegate"),NullAllowed]
        NSObject WeakDelegate { get; set;}

        [Wrap("WeakDelegate")]
        RedSocketManager Delegate{ get; set;}


        // @required -(BOOL)isCableConnected;

        [Export ("isCableConnected")]
        bool IsCableConnected { get; }

        // @required -(NSString *)getAccessoryFirmwareVersion;

        [Export ("getAccessoryFirmwareVersion")]
        string AccessoryFirmwareVersion { get; }

        // @required -(int)getRxCounter;

        [Export ("getRxCounter")]
        int RxCounter { get; }

        // @required -(void)resetRxCounter;

        [Export ("resetRxCounter")]
        void ResetRxCounter ();
    }

    // @protocol RedSocketManagerDelegate <NSObject>
    [Protocol, Model]
    [BaseType (typeof(NSObject))]
     interface RedSocketManagerDelegate
    {
        // @required -(void)cableConnected:(NSString *)protocol;
        [Abstract]
        [Export ("cableConnected:")]
        void CableConnected (string protocol);

        [Abstract]
        // @required -(void)cableDisconnected;
        [Export ("cableDisconnected")]
        void CableDisconnected ();

        // @optional -(void)didAssignIpAddress:(NSString *)deviceAddress gateway:(NSString *)gateway netmask:(NSString *)netmask;
        [Export ("didAssignIpAddress:gateway:netmask:")]
        void DidAssignIpAddress (string deviceAddress, string gateway, string netmask);

        // @optional -(void)didSocketRecv:(int)socket buffer:(void *)buffer bytesRead:(int)bytesRead;
        [Export ("didSocketRecv:buffer:bytesRead:")]
        unsafe void DidSocketRecv (int socket, IntPtr buffer, int bytesRead);

        // @optional -(void)didSocketAccept:(int)newSocket addr:(struct sockaddr *)addr addrlen:(socklen_t *)addrlen;
        [Export ("didSocketAccept:addr:addrlen:")]
        unsafe void DidSocketAccept (int newSocket,IntPtr addr, uint addrlen);
    }

//  [Protocol, Model]
//  [BaseType (typeof(NSObject))]
//  interface RedSocketManagerProtocol
//  {}
//
    // @interface RedSocketManager : NSObject
    [BaseType (typeof(NSObject))]
      interface RedSocketManager
    {
        [Static]
        // +(id<RedSocketManagerProtocol>)sharedInstance;
        [Export ("sharedInstance")]
        RedSocketManagerProtocol SharedInstance { get; }
    }
}

structures & Enums,

    public struct hostent
    {
    }

    static class CFunctions
    {
        // extern struct hostent * redsocket_gethostbyname (const char * name);
        [DllImport ("__Internal")]
        static extern unsafe hostent* redsocket_gethostbyname (sbyte* name);

        // extern UInt32 RedEthernet_calcCRC32 (UInt32 * buffer, unsigned int numWords);
        [DllImport ("__Internal")]
        static extern unsafe uint RedEthernet_calcCRC32 (uint* buffer, uint numWords);
    }

    [StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
    public struct sockaddr {

        /// u_short->unsigned short
        public ushort sa_family;

        /// char[14]
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=14)]
        public string sa_data;
    }

    [StructLayoutAttribute(LayoutKind.Sequential)]
    public struct fd_set {

        /// u_int->unsigned int
        public uint fd_count;

        /// SOCKET[64]
        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=64, ArraySubType=UnmanagedType.U4)]
        public uint[] fd_array;
    }

    [StructLayoutAttribute(LayoutKind.Sequential)]
    public struct timeval {

        /// int
        public int tv_sec;

        /// int
        public int tv_usec;
    }


    [StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
    public struct sockaddr_in {

        /// short
        public short sin_family;

        /// u_short->unsigned short
        public ushort sin_port;

        /// in_addr
        public in_addr sin_addr;

        /// char[8]
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=8)]
        public string sin_zero;
    }

    [StructLayoutAttribute(LayoutKind.Sequential)]
    public struct in_addr {
        public uint s_addr;
    }

谢谢你,拉维

Answer 1:

这个错误是因为即将到来结构体sockaddr指针不持有connect方法IP地址的详细信息。



文章来源: lwip_connect: invalid address\" failed error?