Changeset 1451 for trunk/src


Ignore:
Timestamp:
Oct 26, 1999, 1:17:20 AM (26 years ago)
Author:
phaller
Message:

Fix: invalid structure alignment for asynchronous operations

Location:
trunk/src/wsock32
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wsock32/async.cpp

    r1450 r1451  
    1 /* $Id: async.cpp,v 1.7 1999-10-25 22:48:27 phaller Exp $ */
     1/* $Id: async.cpp,v 1.8 1999-10-25 23:17:18 phaller Exp $ */
    22
    33/*
     
    605605{
    606606  struct hostent* pHostent;
    607   USHORT          usLength;
     607  USHORT          usLength = sizeof(struct Whostent);
    608608  USHORT          rc;
     609  struct Whostent* pwhostent = (struct Whostent*)pRequest->pBuffer;
    609610
    610611  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetHostByAddr (%08xh, %08xh)\n",
     
    613614
    614615  // result buffer length
    615   usLength = min(pRequest->ulBufferLength, sizeof(struct hostent));
    616 
    617   // call API
    618   pHostent = gethostbyaddr((char*)pRequest->ul1,
    619                            (int)        pRequest->ul2,
    620                            (int)        pRequest->ul3);
    621   if (pHostent == NULL) // error ?
    622   {
    623     rc = sock_errno();   // assuming OS/2 return codes are
     616  if (pRequest->ulBufferLength < sizeof(struct Whostent))
     617  {
     618    rc = WSAEINVAL;
    624619    WSASetLastError(rc); // same as Winsock return codes
    625620  }
    626621  else
    627622  {
    628     // build result buffer
    629     memcpy (pRequest->pBuffer,
    630             pHostent,
    631             usLength);
    632     rc = 0;
     623    // call API
     624    pHostent = gethostbyaddr((char*)pRequest->ul1,
     625                             (int)        pRequest->ul2,
     626                             (int)        pRequest->ul3);
     627    if (pHostent == NULL) // error ?
     628    {
     629      rc = sock_errno();   // assuming OS/2 return codes are
     630      WSASetLastError(rc); // same as Winsock return codes
     631    }
     632    else
     633    {
     634      // translate result to Wsock32-style structure
     635      pwhostent->h_name      = pHostent->h_name;
     636      pwhostent->h_aliases   = pHostent->h_aliases;
     637      pwhostent->h_addrtype  = pHostent->h_addrtype;
     638      pwhostent->h_length    = pHostent->h_length;
     639      pwhostent->h_addr_list = pHostent->h_addr_list;
     640      rc = 0;
     641    }
    633642  }
    634643
     
    657666void WSAAsyncWorker::asyncGetHostByName   (PASYNCREQUEST pRequest)
    658667{
    659   struct hostent* pHostent;
    660   USHORT          usLength;
    661   USHORT          rc;
     668  struct hostent*  pHostent;
     669  USHORT           usLength = sizeof(struct Whostent);
     670  USHORT           rc;
     671  struct Whostent* pwhostent = (struct Whostent*)pRequest->pBuffer;
    662672
    663673  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetHostByName (%08xh, %08xh)\n",
     
    666676
    667677  // result buffer length
    668   usLength = min(pRequest->ulBufferLength, sizeof(struct hostent));
    669 
    670   // call API
    671   pHostent = gethostbyname((char*)pRequest->ul1);
    672   if (pHostent == NULL) // error ?
    673   {
    674     rc = sock_errno();   // assuming OS/2 return codes are
     678  if (pRequest->ulBufferLength < sizeof(struct Whostent))
     679  {
     680    rc = WSAEINVAL;
    675681    WSASetLastError(rc); // same as Winsock return codes
    676682  }
    677683  else
    678684  {
    679     // build result buffer
    680     memcpy (pRequest->pBuffer,
    681             pHostent,
    682             usLength);
    683     rc = 0;
     685    // call API
     686    pHostent = gethostbyname((char*)pRequest->ul1);
     687    if (pHostent == NULL) // error ?
     688    {
     689      rc = sock_errno();   // assuming OS/2 return codes are
     690      WSASetLastError(rc); // same as Winsock return codes
     691
     692      dprintf (("  pHostent==NULL -> rc=%d\n", rc));
     693    }
     694    else
     695    {
     696      // translate result to Wsock32-style structure
     697      pwhostent->h_name      = pHostent->h_name;
     698      pwhostent->h_aliases   = pHostent->h_aliases;
     699      pwhostent->h_addrtype  = pHostent->h_addrtype;
     700      pwhostent->h_length    = pHostent->h_length;
     701      pwhostent->h_addr_list = pHostent->h_addr_list;
     702      rc = 0;
     703    }
    684704  }
    685705
     
    709729{
    710730  struct protoent* pProtoent;
    711   USHORT           usLength;
     731  USHORT           usLength = sizeof(struct Wprotoent);
    712732  USHORT           rc;
     733  struct Wprotoent* pwprotoent= (struct Wprotoent*)pRequest->pBuffer;
    713734
    714735  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetProtoByName (%08xh, %08xh)\n",
     
    717738
    718739  // result buffer length
    719   usLength = min(pRequest->ulBufferLength, sizeof(struct protoent));
    720 
    721   // call API
    722   pProtoent = getprotobyname((char*)pRequest->ul1);
    723   if (pProtoent == NULL) // error ?
    724   {
    725     rc = sock_errno();   // assuming OS/2 return codes are
     740  if (pRequest->ulBufferLength < sizeof(struct Wprotoent))
     741  {
     742    rc = WSAEINVAL;
    726743    WSASetLastError(rc); // same as Winsock return codes
    727744  }
    728745  else
    729746  {
    730     // build result buffer
    731     memcpy (pRequest->pBuffer,
    732             pProtoent,
    733             usLength);
    734     rc = 0;
     747    // call API
     748    pProtoent = getprotobyname((char*)pRequest->ul1);
     749    if (pProtoent == NULL) // error ?
     750    {
     751      rc = sock_errno();   // assuming OS/2 return codes are
     752      WSASetLastError(rc); // same as Winsock return codes
     753    }
     754    else
     755    {
     756      // build result buffer
     757      pwprotoent->p_name    = pProtoent->p_name;
     758      pwprotoent->p_aliases = pProtoent->p_aliases;
     759      pwprotoent->p_proto   = pProtoent->p_proto;
     760      rc = 0;
     761    }
    735762  }
    736763
     
    760787{
    761788  struct protoent* pProtoent;
    762   USHORT           usLength;
     789  USHORT           usLength  = sizeof(struct Wprotoent);
    763790  USHORT           rc;
     791  struct Wprotoent* pwprotoent= (struct Wprotoent*)pRequest->pBuffer;
    764792
    765793  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetProtoByNumber (%08xh, %08xh)\n",
     
    768796
    769797  // result buffer length
    770   usLength = min(pRequest->ulBufferLength, sizeof(struct protoent));
    771 
    772   // call API
    773   pProtoent = getprotobyname(( char*)pRequest->ul1);
    774   if (pProtoent == NULL) // error ?
    775   {
    776     rc = sock_errno();   // assuming OS/2 return codes are
     798  if (pRequest->ulBufferLength < sizeof(struct Wprotoent))
     799  {
     800    rc = WSAEINVAL;
    777801    WSASetLastError(rc); // same as Winsock return codes
    778802  }
    779803  else
    780804  {
    781     // build result buffer
    782     memcpy (pRequest->pBuffer,
    783             pProtoent,
    784             usLength);
    785     rc = 0;
     805    // call API
     806    pProtoent = getprotobyname(( char*)pRequest->ul1);
     807    if (pProtoent == NULL) // error ?
     808    {
     809      rc = sock_errno();   // assuming OS/2 return codes are
     810      WSASetLastError(rc); // same as Winsock return codes
     811    }
     812    else
     813    {
     814      // build result buffer
     815      pwprotoent->p_name    = pProtoent->p_name;
     816      pwprotoent->p_aliases = pProtoent->p_aliases;
     817      pwprotoent->p_proto   = pProtoent->p_proto;
     818      rc = 0;
     819    }
    786820  }
    787821
     
    811845{
    812846  struct servent* pServent;
    813   USHORT          usLength;
     847  USHORT          usLength = sizeof(struct Wservent);
    814848  USHORT          rc;
     849  struct Wservent* pwservent= (struct Wservent*)pRequest->pBuffer;
    815850
    816851  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetServByName (%08xh, %08xh)\n",
     
    819854
    820855  // result buffer length
    821   usLength = min(pRequest->ulBufferLength, sizeof(struct servent));
    822 
    823   // call API
    824   pServent = getservbyname((char*)pRequest->ul1,
    825                            (char*)pRequest->ul2);
    826   if (pServent == NULL) // error ?
    827   {
    828     rc = sock_errno();   // assuming OS/2 return codes are
     856  if (pRequest->ulBufferLength < sizeof(struct Wservent))
     857  {
     858    rc = WSAEINVAL;
    829859    WSASetLastError(rc); // same as Winsock return codes
    830860  }
    831861  else
    832862  {
    833     // build result buffer
    834     memcpy (pRequest->pBuffer,
    835             pServent,
    836             usLength);
    837     rc = 0;
     863    // call API
     864    pServent = getservbyname((char*)pRequest->ul1,
     865                             (char*)pRequest->ul2);
     866    if (pServent == NULL) // error ?
     867    {
     868      rc = sock_errno();   // assuming OS/2 return codes are
     869      WSASetLastError(rc); // same as Winsock return codes
     870    }
     871    else
     872    {
     873      // build result buffer
     874      pwservent->s_name    = pServent->s_name;
     875      pwservent->s_aliases = pServent->s_aliases;
     876      pwservent->s_port    = pServent->s_port;
     877      pwservent->s_proto   = pServent->s_proto;
     878      rc = 0;
     879    }
    838880  }
    839881
     
    863905{
    864906  struct servent* pServent;
    865   USHORT          usLength;
     907  USHORT          usLength = sizeof(struct Wservent);
    866908  USHORT          rc;
     909  struct Wservent* pwservent= (struct Wservent*)pRequest->pBuffer;
    867910
    868911  dprintf(("WSOCK32-ASYNC: WSAAsyncWorker::asyncGetServByPort (%08xh, %08xh)\n",
     
    871914
    872915  // result buffer length
    873   usLength = min(pRequest->ulBufferLength, sizeof(struct servent));
    874 
    875   // call API
    876   pServent = getservbyport((int        )pRequest->ul1,
    877                            (char*)pRequest->ul2);
    878   if (pServent == NULL) // error ?
    879   {
    880     rc = sock_errno();   // assuming OS/2 return codes are
     916  if (pRequest->ulBufferLength < sizeof(struct Whostent))
     917  {
     918    rc = WSAEINVAL;
    881919    WSASetLastError(rc); // same as Winsock return codes
    882920  }
    883921  else
    884922  {
    885     // build result buffer
    886     memcpy (pRequest->pBuffer,
    887             pServent,
    888             usLength);
    889     rc = 0;
     923    // call API
     924    pServent = getservbyport((int        )pRequest->ul1,
     925                             (char*)pRequest->ul2);
     926    if (pServent == NULL) // error ?
     927    {
     928      rc = sock_errno();   // assuming OS/2 return codes are
     929      WSASetLastError(rc); // same as Winsock return codes
     930    }
     931    else
     932    {
     933      // build result buffer
     934      pwservent->s_name    = pServent->s_name;
     935      pwservent->s_aliases = pServent->s_aliases;
     936      pwservent->s_port    = pServent->s_port;
     937      pwservent->s_proto   = pServent->s_proto;
     938
     939      rc = 0;
     940    }
    890941  }
    891942
  • trunk/src/wsock32/makefile

    r1393 r1451  
    1 # $Id: makefile,v 1.11 1999-10-21 14:58:54 phaller Exp $
     1# $Id: makefile,v 1.12 1999-10-25 23:17:19 phaller Exp $
    22
    33#
     
    2121TARGET = wsock32
    2222
    23 OBJS =  wsock32.obj notify.obj initterm.obj unknown.obj async.obj
     23OBJS =  wsock32.obj initterm.obj unknown.obj async.obj
    2424
    2525all: $(TARGET).dll $(TARGET).lib
     
    4141
    4242wsock32.obj: wsock32.cpp wsock32.h wsock32const.h
    43 notify.obj:  notify.cpp wsock32.h
    4443unknown.obj: unknown.cpp wsock32.h
    4544async.obj:   async.cpp wsock32const.h
  • trunk/src/wsock32/wsock32.h

    r1372 r1451  
    1 /* $Id: wsock32.h,v 1.5 1999-10-20 10:03:54 phaller Exp $ */
     1/* $Id: wsock32.h,v 1.6 1999-10-25 23:17:19 phaller Exp $ */
    22
    33/* WSOCK32.H--definitions & conversions for Odin's wsock32.dll.
     
    7373 */
    7474typedef u_int           SOCKET;
    75 
    76 
    77 
    78 
    79 typedef struct AsyncStatus {
    80     HWND hwnd;     // owner's hwindow
    81     u_int msg;     // message to send when event occurs
    82     ULONG event;    // event that may occur
    83     SOCKET socket; // the socket
    84     int status;    // blocking yes/no
    85     TID threadID;  // Thread ID for async
    86     int MsgStat;   // has message been sent yet?
    87     struct AsyncStatus *Next; // pointer to next AsyncStatus in the list
    88     struct AsyncStatus *Prev; // pointer to previous AsyncStatus in the list
    89 } AsyncStatus;
    90 
    91 
    92 
    9375
    9476
     
    201183#define WSIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
    202184#define WSIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
    203 
    204 /*
    205  * Structures returned by network data base library, taken from the
    206  * BSD file netdb.h.  All addresses are supplied in host order, and
    207  * returned in network order (suitable for use in system calls).
    208  */
    209 
    210 struct  Whostent {
    211         char     * h_name;           /* official name of host */
    212         char     *  * h_aliases;  /* alias list */
    213         short   h_addrtype;             /* host address type */
    214         short   h_length;               /* length of address */
    215         char     *  * h_addr_list; /* list of addresses */
    216 #define h_addr  h_addr_list[0]          /* address, for backward compat */
    217 };
    218 
    219 /*
    220  * It is assumed here that a network number
    221  * fits in 32 bits.
    222  */
    223 struct  Wnetent {
    224         char     * n_name;           /* official name of net */
    225         char     *  * n_aliases;  /* alias list */
    226         short   n_addrtype;             /* net address type */
    227         u_long  n_net;                  /* network # */
    228 };
    229 
    230 struct  Wservent {
    231         char     * s_name;           /* official service name */
    232         char     *  * s_aliases;  /* alias list */
    233         short   s_port;                 /* port # */
    234         char     * s_proto;          /* protocol to use */
    235 };
    236 
    237 struct  Wprotoent {
    238         char     * p_name;           /* official protocol name */
    239         char     *  * p_aliases;  /* alias list */
    240         short   p_proto;                /* protocol # */
    241 };
    242185
    243186/*
  • trunk/src/wsock32/wsock32const.h

    r1384 r1451  
    1 /* $Id: wsock32const.h,v 1.2 1999-10-20 20:11:03 phaller Exp $ */
     1/* $Id: wsock32const.h,v 1.3 1999-10-25 23:17:20 phaller Exp $ */
    22
    33/* WSOCK32.H--definitions & conversions for Odin's wsock32.dll.
     
    174174#define OS2WSAGETSELECTERROR(lParam)           HIWORD(lParam)
    175175
     176
     177/*
     178 * Structures returned by network data base library, taken from the
     179 * BSD file netdb.h.  All addresses are supplied in host order, and
     180 * returned in network order (suitable for use in system calls).
     181 */
     182
     183struct  Whostent {
     184        char     * h_name;           /* official name of host */
     185        char     *  * h_aliases;  /* alias list */
     186        short   h_addrtype;             /* host address type */
     187        short   h_length;               /* length of address */
     188        char     *  * h_addr_list; /* list of addresses */
     189#define h_addr  h_addr_list[0]          /* address, for backward compat */
     190};
     191
     192/*
     193 * It is assumed here that a network number
     194 * fits in 32 bits.
     195 */
     196struct  Wnetent {
     197        char     * n_name;           /* official name of net */
     198        char     *  * n_aliases;  /* alias list */
     199        short   n_addrtype;             /* net address type */
     200        u_long  n_net;                  /* network # */
     201};
     202
     203struct  Wservent {
     204        char     * s_name;           /* official service name */
     205        char     *  * s_aliases;  /* alias list */
     206        short   s_port;                 /* port # */
     207        char     * s_proto;          /* protocol to use */
     208};
     209
     210struct  Wprotoent {
     211        char     * p_name;           /* official protocol name */
     212        char     *  * p_aliases;  /* alias list */
     213        short   p_proto;                /* protocol # */
     214};
     215
     216
    176217#endif  /* _WINSOCK32CONST_ */
    177218
Note: See TracChangeset for help on using the changeset viewer.