Browse Source

move and improve SA_LEN emulation

If sa_family is not set, sa_len should be zero.
OPENBSD_5_7
Brent Cook 10 years ago
parent
commit
12bfe6dafa
3 changed files with 25 additions and 13 deletions
  1. +1
    -1
      include/Makefile.am
  2. +24
    -0
      include/netinet/in.h
  3. +0
    -12
      include/sys/socket.h

+ 1
- 1
include/Makefile.am View File

@ -1,8 +1,8 @@
noinst_HEADERS = noinst_HEADERS =
noinst_HEADERS += signal.h noinst_HEADERS += signal.h
noinst_HEADERS += unistd.h noinst_HEADERS += unistd.h
noinst_HEADERS += netinet/in.h
noinst_HEADERS += sys/types.h noinst_HEADERS += sys/types.h
noinst_HEADERS += sys/socket.h
noinst_HEADERS += sys/time.h noinst_HEADERS += sys/time.h
noinst_HEADERS += imsg.h noinst_HEADERS += imsg.h
noinst_HEADERS += string.h noinst_HEADERS += string.h


+ 24
- 0
include/netinet/in.h View File

@ -0,0 +1,24 @@
/*
* Public domain
* netinet/in.h compatibility shim
*/
#include_next <netinet/in.h>
#ifndef SA_LEN
static inline socklen_t sockaddr_len(void *a)
{
struct sockaddr *sa = a;
switch (sa->sa_family) {
case AF_INET:
return sizeof(struct sockaddr_in);
case AF_INET6:
return sizeof(struct sockaddr_in6);
case AF_UNSPEC:
return sizeof(struct sockaddr);
default:
return 0;
}
}
#define SA_LEN(X) sockaddr_len(X)
#endif

+ 0
- 12
include/sys/socket.h View File

@ -1,12 +0,0 @@
/*
* Public domain
* sys/socket.h compatibility shim
*/
#include_next <sys/socket.h>
#ifndef SA_LEN
#define SA_LEN(X) \
(((struct sockaddr*)(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
((struct sockaddr*)(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
#endif

Loading…
Cancel
Save