Skip to content

Commit f2bea4d

Browse files
committedSep 23, 2016
Installed-header hygiene (BZ#20366): conditionally defined structures.
Several network-related structures are defined conditionally under __USE_MISC, but unconditionally used by other headers. The path of least resistance is usually to condition the uses on __USE_MISC as well. * sysdeps/mach/hurd/net/if_ppp.h * sysdeps/unix/sysv/linux/net/if_ppp.h: Only define struct ifpppstatsreq and struct ifpppcstatsreq if __USE_MISC is defined, to ensure struct ifreq is declared. * inet/netinet/ether.h: Condition all function prototypes on __USE_MISC, to ensure struct ether_addr is declared. sys/socket.h defines struct osockaddr only under __USE_MISC, whereas protocols/talkd.h requires it unconditionally. Here it doesn't make sense to condition the entire body of protocols/talkd.h on __USE_MISC. Rather than complicate sys/socket.h with a __need macro or duplicate the definition, I am introducing a new concept: tiny headers named bits/types/TYPE.h that define TYPE and nothing else. This can, I hope, ultimately replace *all* the __need macros. The guard macro for such headers will be __TYPE_defined, just in case application or third-party library code is looking at them. * socket/bits/types/struct_osockaddr.h: New header. * include/bits/types/struct_osockaddr.h: New wrapper. * socket/Makefile: Install the new header. * socket/sys/socket.h, inet/protocols/talkd.h: Refer to bits/types/struct_osockaddr.h for the definition of struct osockaddr.
1 parent 11160cb commit f2bea4d

File tree

9 files changed

+42
-8
lines changed

9 files changed

+42
-8
lines changed
 

‎ChangeLog

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2016-09-23 Zack Weinberg <zackw@panix.com>
2+
3+
* sysdeps/mach/hurd/net/if_ppp.h
4+
* sysdeps/unix/sysv/linux/net/if_ppp.h:
5+
Only define struct ifpppstatsreq and struct ifpppcstatsreq
6+
if __USE_MISC is defined, to ensure struct ifreq is declared.
7+
8+
* inet/netinet/ether.h: Condition all function prototypes
9+
on __USE_MISC, to ensure struct ether_addr is declared.
10+
11+
* socket/bits/types/struct_osockaddr.h: New header.
12+
* include/bits/types/struct_osockaddr.h: New wrapper.
13+
* socket/Makefile: Install the new header.
14+
* socket/sys/socket.h, inet/protocols/talkd.h:
15+
Refer to bits/types/struct_osockaddr.h for the definition of
16+
struct osockaddr.
17+
118
2016-09-23 Zack Weinberg <zackw@panix.com>
219

320
* bits/in.h, gmon/sys/gmon.h, inet/netinet/igmp.h

‎include/bits/types/struct_osockaddr.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../../socket/bits/types/struct_osockaddr.h"

‎inet/netinet/ether.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/* Get definition of `struct ether_addr'. */
2525
#include <netinet/if_ether.h>
2626

27+
#ifdef __USE_MISC
2728
__BEGIN_DECLS
2829

2930
/* Convert 48 bit Ethernet ADDRess to ASCII. */
@@ -49,5 +50,6 @@ extern int ether_line (const char *__line, struct ether_addr *__addr,
4950
char *__hostname) __THROW;
5051

5152
__END_DECLS
53+
#endif /* Use misc. */
5254

5355
#endif /* netinet/ether.h */

‎inet/protocols/talkd.h

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <sys/types.h>
5454
#include <sys/socket.h>
5555
#include <stdint.h>
56+
#include <bits/types/struct_osockaddr.h>
5657

5758
/*
5859
* Client->server request message format.

‎socket/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ subdir := socket
2323
include ../Makeconfig
2424

2525
headers := sys/socket.h sys/un.h bits/sockaddr.h bits/socket.h \
26-
bits/socket2.h sys/socketvar.h net/if.h
26+
bits/socket2.h bits/types/struct_osockaddr.h \
27+
sys/socketvar.h net/if.h
2728

2829
routines := accept bind connect getpeername getsockname getsockopt \
2930
listen recv recvfrom recvmsg send sendmsg sendto \

‎socket/bits/types/struct_osockaddr.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __osockaddr_defined
2+
#define __osockaddr_defined 1
3+
4+
/* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
5+
format in the grotty old 4.3 `talk' protocol. */
6+
struct osockaddr
7+
{
8+
unsigned short int sa_family;
9+
unsigned char sa_data[14];
10+
};
11+
12+
#endif

‎socket/sys/socket.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ __BEGIN_DECLS
3838
#include <bits/socket.h>
3939

4040
#ifdef __USE_MISC
41-
/* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
42-
format in the grotty old 4.3 `talk' protocol. */
43-
struct osockaddr
44-
{
45-
unsigned short int sa_family;
46-
unsigned char sa_data[14];
47-
};
41+
# include <bits/types/struct_osockaddr.h>
4842
#endif
4943

5044
/* The following constants should be used for the second parameter of

‎sysdeps/mach/hurd/net/if_ppp.h

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ struct ppp_option_data {
119119
int transmit;
120120
};
121121

122+
/* 'struct ifreq' is only available from net/if.h under __USE_MISC. */
123+
#ifdef __USE_MISC
122124
struct ifpppstatsreq {
123125
struct ifreq b;
124126
struct ppp_stats stats; /* statistic information */
@@ -131,6 +133,7 @@ struct ifpppcstatsreq {
131133

132134
#define ifr__name b.ifr_ifrn.ifrn_name
133135
#define stats_ptr b.ifr_ifru.ifru_data
136+
#endif
134137

135138
/*
136139
* Ioctl definitions.

‎sysdeps/unix/sysv/linux/net/if_ppp.h

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ struct ppp_option_data {
118118
int transmit;
119119
};
120120

121+
/* 'struct ifreq' is only available from net/if.h under __USE_MISC. */
122+
#ifdef __USE_MISC
121123
struct ifpppstatsreq {
122124
struct ifreq b;
123125
struct ppp_stats stats; /* statistic information */
@@ -130,6 +132,7 @@ struct ifpppcstatsreq {
130132

131133
#define ifr__name b.ifr_ifrn.ifrn_name
132134
#define stats_ptr b.ifr_ifru.ifru_data
135+
#endif
133136

134137
/*
135138
* Ioctl definitions.

0 commit comments

Comments
 (0)
Please sign in to comment.