# \[PATCH 37/45\] include/uapi/linux/socket.h: include sys/socket.h in userspace

- Subsystems: NETWORKING \[SOCKETS\], THE REST
- Maintainers: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn, Linus Torvalds
- List: linux-api
- 4 messages, 2 authors
- Page: https://ratatoskr.run/linux-api/2015/02/4432065/t

## \[PATCH 37/45\] include/uapi/linux/socket.h: include sys/socket.h in userspace

- From: Mikko Rapeli \<hidden\>
- Date: 2015-02-16 23:10:48 
- Message: https://ratatoskr.run/linux-api/2015/02/4432065.md

```text
This libc header has sockaddr definition for userspace.
Fixes compilation errors like:
error: field ‘ifru_addr’ has incomplete type
struct sockaddr ifru_addr;

Signed-off-by: Mikko Rapeli <redacted>
---
 include/uapi/linux/socket.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
index 76ab0c6..8a81197 100644
--- a/include/uapi/linux/socket.h
+++ b/include/uapi/linux/socket.h
@@ -1,6 +1,10 @@
 #ifndef _UAPI_LINUX_SOCKET_H
 #define _UAPI_LINUX_SOCKET_H
 
+#ifndef __KERNEL__
+#include <sys/socket.h>
+#endif
+
 /*
  * Desired design of maximum size and alignment (see RFC2553)
  */
-- 
2.1.4
```

## Re: \[PATCH 37/45\] include/uapi/linux/socket.h: include sys/socket.h in userspace

- From: Arnd Bergmann \<arnd@arndb.de\>
- Date: 2015-02-17 09:14:36 
- Message: https://ratatoskr.run/linux-api/2015/02/4432357.md

```text
On Tuesday 17 February 2015 00:05:40 Mikko Rapeli wrote:
> This libc header has sockaddr definition for userspace.
> Fixes compilation errors like:
> error: field ‘ifru_addr’ has incomplete type
> struct sockaddr ifru_addr;
> 
> Signed-off-by: Mikko Rapeli <redacted>
> ---
>  include/uapi/linux/socket.h | 4 ++++
>  1 file changed, 4 insertions(+)

This looks wrong: where do you see a use of ifru_addr
in uapi/linux/socket.h?

	Arnd
```

## Re: \[PATCH 37/45\] include/uapi/linux/socket.h: include sys/socket.h in userspace

- From: Mikko Rapeli \<hidden\>
- Date: 2015-03-11 00:38:21 
- Message: https://ratatoskr.run/linux-api/2015/03/4448015.md

```text
On Tue, Feb 17, 2015 at 10:14:10AM +0100, Arnd Bergmann wrote:
> On Tuesday 17 February 2015 00:05:40 Mikko Rapeli wrote:
> > This libc header has sockaddr definition for userspace.
> > Fixes compilation errors like:
> > error: field ‘ifru_addr’ has incomplete type
> > struct sockaddr ifru_addr;
> > 
> > Signed-off-by: Mikko Rapeli <redacted>
> > ---
> >  include/uapi/linux/socket.h | 4 ++++
> >  1 file changed, 4 insertions(+)
> 
> This looks wrong: where do you see a use of ifru_addr
> in uapi/linux/socket.h?

Indeed, this one seems completely wrong. Based on the test logs the
change should have gone to linux/if.h.

-Mikko
```

## Re: \[PATCH 37/45\] include/uapi/linux/socket.h: include sys/socket.h in userspace

- From: Mikko Rapeli \<hidden\>
- Date: 2015-03-11 00:59:39 
- Message: https://ratatoskr.run/linux-api/2015/03/4448025.md

```text
On Wed, Mar 11, 2015 at 02:38:15AM +0200, Mikko Rapeli wrote:
> On Tue, Feb 17, 2015 at 10:14:10AM +0100, Arnd Bergmann wrote:
> > On Tuesday 17 February 2015 00:05:40 Mikko Rapeli wrote:
> > > This libc header has sockaddr definition for userspace.
> > > Fixes compilation errors like:
> > > error: field ‘ifru_addr’ has incomplete type
> > > struct sockaddr ifru_addr;
> > > 
> > > Signed-off-by: Mikko Rapeli <redacted>
> > > ---
> > >  include/uapi/linux/socket.h | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > 
> > This looks wrong: where do you see a use of ifru_addr
> > in uapi/linux/socket.h?
> 
> Indeed, this one seems completely wrong. Based on the test logs the
> change should have gone to linux/if.h.

Hmm, turns out this was not so straight forward. If I drop this I get 20
more errors from headers which include linux/socket.h and expect sockaddr
to be defined which is not true since it comes from sys/socket.h.

One way to fix this for all linux/socket.h users is to include sys/socket.h
already in linux/socket.h. After this I get rid of all compile test errors from
missing sockaddr definitions except cases where headers fail to include even
linux/socket.h.

Other option would be to include sys/socket.h in all headers using sockaddr.

I would prefer to include sys/socket.h already in linux/socket.h but I will
improve the commit message with this detail.

-Mikko
```
