Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: Add getifaddrs stuff to posix #1579

Merged
merged 6 commits into from Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions ffi-cdecl/posix_decl.c
Expand Up @@ -22,6 +22,11 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <sched.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <linux/if_link.h>
#include <errno.h>

#include "ffi-cdecl.h"
Expand Down Expand Up @@ -217,3 +222,18 @@ cdecl_type(cpu_set_t)
cdecl_func(sched_getaffinity)
cdecl_func(sched_setaffinity)
cdecl_func(sched_yield)

cdecl_struct(sockaddr) // May be provided by lj-wpaclient (... which is platform-specific)
cdecl_struct(ifaddrs)
cdecl_const(NI_MAXHOST)
cdecl_func(getifaddrs)
cdecl_const(AF_INET)
cdecl_const(AF_INET6)
cdecl_func(getnameinfo)
cdecl_struct(in_addr)
cdecl_struct(sockaddr_in)
cdecl_struct(in6_addr)
cdecl_struct(sockaddr_in6)
cdecl_const(NI_NUMERICHOST)
cdecl_func(gai_strerror)
cdecl_func(freeifaddrs)
47 changes: 47 additions & 0 deletions ffi/posix_h.lua
Expand Up @@ -189,6 +189,53 @@ typedef struct {
int sched_getaffinity(int, size_t, cpu_set_t *) __attribute__((nothrow, leaf));
int sched_setaffinity(int, size_t, const cpu_set_t *) __attribute__((nothrow, leaf));
int sched_yield(void) __attribute__((nothrow, leaf));
struct sockaddr {
short unsigned int sa_family;
char sa_data[14];
};
struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
union {
struct sockaddr *ifu_broadaddr;
struct sockaddr *ifu_dstaddr;
} ifa_ifu;
void *ifa_data;
};
static const int NI_MAXHOST = 1025;
int getifaddrs(struct ifaddrs **) __attribute__((nothrow, leaf));
static const int AF_INET = 2;
static const int AF_INET6 = 10;
int getnameinfo(const struct sockaddr *restrict, unsigned int, char *restrict, unsigned int, char *restrict, unsigned int, int);
struct in_addr {
unsigned int s_addr;
};
struct sockaddr_in {
short unsigned int sin_family;
short unsigned int sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
};
struct in6_addr {
union {
uint8_t __u6_addr8[16];
uint16_t __u6_addr16[8];
uint32_t __u6_addr32[4];
} __in6_u;
};
struct sockaddr_in6 {
short unsigned int sin6_family;
short unsigned int sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
static const int NI_NUMERICHOST = 1;
const char *gai_strerror(int) __attribute__((nothrow, leaf));
void freeifaddrs(struct ifaddrs *) __attribute__((nothrow, leaf));
]]

-- clock_gettime & friends require librt on old glibc (< 2.17) versions...
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/lj-wpaclient/CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ ep_get_source_dir(SOURCE_DIR)
ko_write_gitclone_script(
GIT_CLONE_SCRIPT_FILENAME
https://github.com/koreader/lj-wpaclient.git
4f95110298b89d80e762215331159657ae36b4ef
2f93beb3071e6ebb57c783bd5b92f83aa5ebb757
${SOURCE_DIR}
)

Expand Down