summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug1665511.c
blob: 68d35a0df08b50cd49bf65dd4877237fcfd0ca3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
   bug1665511.c
*/

#include <testfwk.h>

#ifndef __SDCC_pdk14 // Lack of memory - see RFE #605.

/* force alignment on sparc machines with gcc compiler */
#if defined(PORT_HOST) && defined(__sparc) && defined(__GNUC__)
# define LONG_ALIGNED __attribute__ ((aligned (4)))
#else
# define LONG_ALIGNED
#endif

typedef union
{
  unsigned char bytes[4];
  long l;
} IP_V4, *PIP_V4;

typedef union _short_map
{
  unsigned char chars[2];
  short shorts [1];
} Short_Map, *PShort_Map;

typedef Short_Map Port;
typedef Port *PPort;

struct sockaddr
{
  unsigned char bogus_ptr[3];              ///< Overhead for TNI native interface.
  unsigned char sin_addr[16] LONG_ALIGNED; ///< IP address. IPv4 address is in sin_addr[12-15] with MSB at sin_addr[12].
  unsigned char sin_port_high;             ///< most significant byte of port number for the socket.
  unsigned char sin_port_low;              ///< least significant byte of port number for the socket.
  unsigned char sin_family;                ///< Ignored by DS80C400 implementation.
};

typedef unsigned int SocketHandle;

#define INVALID_HANDLE_VALUE (SocketHandle) -1

int accept(SocketHandle handle, struct sockaddr * address, unsigned int size)
{
  handle;
  address;
  size;
  return 0x1234;
}

SocketHandle Accept(SocketHandle handle, PIP_V4 ip, PPort port)
{
  struct sockaddr address;
  int RetCode;

  RetCode = accept(handle, &address, sizeof(address));
  if (RetCode != INVALID_HANDLE_VALUE)
  {
    ip->l = ((PIP_V4) &address.sin_addr[12])->l;
    port->chars[0] = address.sin_port_low;
    port->chars[1] = address.sin_port_high;
  };

  return RetCode;
}
#endif

void testBug(void)
{
#ifndef __SDCC_pdk14 // Lack of memory.
  IP_V4 ip = {{1, 2, 3, 4}};
  Port port = {{5, 6}};
  ASSERT(Accept(1, &ip, &port) == 0x1234);
#endif
}