Skip to content

Commit 274328c

Browse files
committed
Avoid use of int64_t, which seems not to be very portable. Simplify
padding logic for struct sockaddr_storage --- original version did not do what it claimed to when SALEN is defined.
1 parent bbac418 commit 274328c

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/include/libpq/pqcomm.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: pqcomm.h,v 1.88 2003/06/24 01:49:22 momjian Exp $
12+
* $Id: pqcomm.h,v 1.89 2003/07/15 17:54:34 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -34,41 +34,35 @@
3434

3535
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
3636
/* Define a struct sockaddr_storage if we don't have one. */
37-
/*
38-
* Desired design of maximum size and alignment
39-
*/
40-
#define _SS_MAXSIZE 128 /* Implementation specific max size */
41-
#define _SS_ALIGNSIZE (sizeof (int64_t))
42-
/* Implementation specific desired alignment */
43-
/*
44-
* Definitions used for sockaddr_storage structure paddings design.
45-
*/
46-
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (sa_family_t))
47-
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t) + \
48-
_SS_PAD1SIZE + _SS_ALIGNSIZE))
37+
38+
#define _SS_MAXSIZE 128 /* Implementation specific max size */
4939

5040
#ifdef __CYGWIN__
5141
typedef unsigned short sa_family_t;
5242
#endif
5343

44+
/* This must exactly match the non-padding fields of sockaddr_storage! */
45+
struct nopad_sockaddr_storage {
46+
#ifdef SALEN
47+
uint8 __ss_len; /* address length */
48+
#endif
49+
sa_family_t ss_family; /* address family */
50+
51+
int64 __ss_align; /* ensures struct is properly aligned */
52+
};
53+
5454
struct sockaddr_storage {
5555
#ifdef SALEN
56-
uint8_t __ss_len; /* address length */
56+
uint8 __ss_len; /* address length */
5757
#endif
58-
sa_family_t ss_family; /* address family */
59-
60-
char __ss_pad1[_SS_PAD1SIZE];
61-
/* 6 byte pad, this is to make implementation
62-
* specific pad up to alignment field that
63-
* follows explicit in the data structure */
64-
int64_t __ss_align;
65-
/* field to force desired structure
66-
* storage alignment */
67-
char __ss_pad2[_SS_PAD2SIZE];
68-
/* 112 byte pad to achieve desired size,
69-
* _SS_MAXSIZE value minus size of ss_family
70-
* __ss_pad1, __ss_align fields is 112 */
58+
sa_family_t ss_family; /* address family */
59+
60+
int64 __ss_align; /* ensures struct is properly aligned */
61+
62+
char __ss_pad[_SS_MAXSIZE - sizeof(struct nopad_sockaddr_storage)];
63+
/* ensures struct has desired size */
7164
};
65+
7266
#elif !defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY)
7367
# ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
7468
# define ss_family __ss_family

0 commit comments

Comments
 (0)