Skip to content

Instantly share code, notes, and snippets.

@toots
Created December 1, 2019 11:18
Show Gist options
  • Save toots/4ad86eaf9812064474013e82704a7367 to your computer and use it in GitHub Desktop.
Save toots/4ad86eaf9812064474013e82704a7367 to your computer and use it in GitHub Desktop.
let c_headers = "
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#endif
#define SA_DATA_LEN (sizeof(((struct sockaddr*)0)->sa_data))
#define SA_FAMILY_LEN (sizeof(((struct sockaddr*)0)->sa_family))
#define SOCKLEN_T_LEN (sizeof(socklen_t))
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
#endif
#ifndef NI_MAXSERV
#define NI_MAXSERV 32
#endif
"
let () =
let fname = Sys.argv.(1) in
let oc = open_out_bin fname in
let format =
Format.formatter_of_out_channel oc
in
Format.fprintf format "%s@\n" c_headers;
Cstubs.Types.write_c format (module Sys_socket_constants.Def);
Format.pp_print_flush format ();
close_out oc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment