dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog support/socket.c


From: Radek Polak
Subject: [dotgnu-pnet-commits] pnet ChangeLog support/socket.c
Date: Fri, 04 Jan 2008 23:46:33 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnet
Changes by:     Radek Polak <radekp>    08/01/04 23:46:33

Modified files:
        .              : ChangeLog 
        support        : socket.c 

Log message:
        IrDA device discovery and correct checking for return values from 
sockopt functions

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3530&r2=1.3531
http://cvs.savannah.gnu.org/viewcvs/pnet/support/socket.c?cvsroot=dotgnu-pnet&r1=1.28&r2=1.29

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3530
retrieving revision 1.3531
diff -u -b -r1.3530 -r1.3531
--- ChangeLog   30 Dec 2007 00:09:43 -0000      1.3530
+++ ChangeLog   4 Jan 2008 23:46:32 -0000       1.3531
@@ -1,3 +1,8 @@
+2008-01-05  Radek Polak  <address@hidden>
+
+       * support/socket.c: Implemented IrDA device discovery. Fixed checking 
for
+       return values from getsockopt and setsockopt.
+
 2007-12-30  Radek Polak  <address@hidden>
 
        * engine/debugger.c: Implemented local variables and function parameters

Index: support/socket.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/support/socket.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- support/socket.c    22 Oct 2007 08:20:21 -0000      1.28
+++ support/socket.c    4 Jan 2008 23:46:33 -0000       1.29
@@ -99,10 +99,30 @@
 #ifdef IN6ADDR_ANY_INIT
 #define        IL_IPV6_PRESENT         1
 #endif
-#ifdef LSAP_ANY
+#if defined(LSAP_ANY) || defined(IL_WIN32_PLATFORM)
 #define        IL_IRDA_PRESENT         1
 #endif
 
+#ifdef IL_WIN32_PLATFORM
+
+/*
+ * Defines from AF_Irda.h
+ * This file is not part of cygwin thus we provide necessary definitions here.
+ */
+
+#define AF_IRDA                                26
+#define SOL_IRLMP                      0xFF
+#define IRLMP_ENUMDEVICES      0x10
+
+struct sockaddr_irda
+{
+       u_short irdaAddressFamily;
+       u_char  irdaDeviceID[4];
+       char    irdaServiceName[25];
+};
+
+#endif
+
 /*
  * Address families at the C# level, which may not be the same
  * as those at the operating system level.
@@ -230,14 +250,24 @@
                {
                        return 0;
                }
+#if IL_WIN32_PLATFORM
+               addr->irda_addr.irdaAddressFamily = AF_IRDA;
+               addr->irda_addr.irdaDeviceID[0] = buf[2];
+               addr->irda_addr.irdaDeviceID[1] = buf[3];
+               addr->irda_addr.irdaDeviceID[2] = buf[4];
+               addr->irda_addr.irdaDeviceID[3] = buf[5];
+               ILMemCpy(addr->irda_addr.irdaServiceName, buf + 6, 24);
+#else
                addr->irda_addr.sir_family = AF_IRDA;
                addr->irda_addr.sir_lsap_sel = LSAP_ANY;
                value = ((((long)(buf[2])) << 24) |
                         (((long)(buf[3])) << 16) |
                         (((long)(buf[4])) << 8) |
                          ((long)(buf[5])));
+
                addr->irda_addr.sir_addr = htonl((long)value);
                ILMemCpy(addr->irda_addr.sir_name, buf + 6, 24);
+#endif
                *addrlen = sizeof(struct sockaddr_irda);
                return 1;
        }
@@ -336,12 +366,20 @@
                {
                        return 0;
                }
+#if IL_WIN32_PLATFORM
+               buf[2] = addr->irda_addr.irdaDeviceID[0];
+               buf[3] = addr->irda_addr.irdaDeviceID[1];
+               buf[4] = addr->irda_addr.irdaDeviceID[2];
+               buf[5] = addr->irda_addr.irdaDeviceID[3];
+               ILMemCpy(buf + 6, addr->irda_addr.irdaServiceName, 24);
+#else
                value = (long)(ntohl(addr->irda_addr.sir_addr));
                buf[2] = (unsigned char)(value >> 24);
                buf[3] = (unsigned char)(value >> 16);
                buf[4] = (unsigned char)(value >> 8);
                buf[5] = (unsigned char)value;
                ILMemCpy(buf + 6, addr->irda_addr.sir_name, 24);
+#endif
                return 1;
        }
 #endif
@@ -1126,7 +1164,7 @@
        _linger.l_onoff=enabled;
        _linger.l_linger=seconds;
        if(setsockopt((int)(ILNativeInt)handle, SOL_SOCKET, SO_LINGER,
-                                               (void *)&(_linger), 
sizeof(struct linger)) < 0)
+                                               (void *)&(_linger), 
sizeof(struct linger)) != 0)
        {
                return 0;
        }
@@ -1143,7 +1181,7 @@
        struct linger _linger;
        int size=sizeof(struct linger);
        if(getsockopt((int)(ILNativeInt)handle, SOL_SOCKET, SO_LINGER,
-                                 (void *)&(_linger), &size) < 0)
+                                 (void *)&(_linger), &size) != 0)
        {
                return 0;
        }
@@ -1177,9 +1215,69 @@
 int ILSysIODiscoverIrDADevices(ILSysIOHandle handle, unsigned char *buf,
                                                           ILInt32 bufLen)
 {
-       /* TODO */
+#if defined(HAVE_GETSOCKOPT) && defined(IL_WIN32_PLATFORM)
+       /*
+        * Note: we must compile with --disable-cygwin to make IrDA working on
+        * windows, because cygwin seems to be blocking irda socket options.
+        */
+       if(getsockopt((int)(ILNativeInt)handle, SOL_IRLMP, IRLMP_ENUMDEVICES,
+                                 buf, &bufLen) != 0)
+       {
+               return 0;
+       }
+       return 1;
+#elif defined(HAVE_GETSOCKOPT) && defined(IRLMP_ENUMDEVICES)
+       char *nativeBuf;
+       ILInt32 nativeLen;
+       struct irda_device_list *list;
+       int i;
+       int index;
+
+       /* Compute the option length for unix. Given option length is
+          4 bytes for device count and 32 bytes for each device info */
+       nativeLen = sizeof(struct irda_device_list) +
+                               sizeof(struct irda_device_info) * ((bufLen - 4) 
/ 32);
+
+       nativeBuf = (void *) ILMalloc(nativeLen);
+       if(nativeBuf == 0)
+       {
+               ILSysIOSetErrno(IL_ERRNO_ENOMEM);
+               return 0;
+       }
+
+       /* Perform a discovery and get device list */
+       if(getsockopt((int)(ILNativeInt)handle, SOL_IRLMP, IRLMP_ENUMDEVICES,
+                                                                               
        nativeBuf, &nativeLen) != 0)
+       {
+               ILFree(nativeBuf);
+               return 0;
+       }
+
+       /* Convert list to buf that is used to construct IrDADeviceInfo */
+       list = (struct irda_device_list *) nativeBuf;
+
+       ILMemCpy((void *)(buf), (const void *)(&(list->len)), 4);
+       index = 4;
+
+       for(i = 0; i < list->len; ++i)
+       {
+               ILMemCpy((void *)(buf + index),
+                                                                       (const 
void *)(&(list->dev[i].daddr)), 4);
+               index += 4;
+               ILMemCpy((void *)(buf + index), (const void 
*)(list->dev[i].info), 22);
+               index += 22;
+               ILMemCpy((void *)(buf + index), (const void 
*)(list->dev[i].hints), 2);
+               index += 2;
+               buf[index] = list->dev[i].charset;
+               index += 4;
+       }
+
+       ILFree(nativeBuf);
+       return 1;
+#else
        ILSysIOSetErrno(IL_ERRNO_EINVAL);
        return 0;
+#endif
 }
 
 #ifdef __cplusplus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]