Skip to content

Instantly share code, notes, and snippets.

@dlevi309
Created July 12, 2021 22:52
Show Gist options
  • Select an option

  • Save dlevi309/a977b3a6ab4e8b7b66d0343bd9936252 to your computer and use it in GitHub Desktop.

Select an option

Save dlevi309/a977b3a6ab4e8b7b66d0343bd9936252 to your computer and use it in GitHub Desktop.
The missing NETRB.h
#ifndef NETRB_h
#define NETRB_h
#include <xpc/xpc.h>
#include <dispatch/dispatch.h>
#ifdef __cplusplus
extern "C" {
#endif
#define EXPORT __attribute__((visibility("default")))
#define PRIVATE __attribute__((visibility("hidden")))
#if TARGET_OS_EMBEDDED
#define MIS_SERVICE_CLIENT_DS_KEY "com.apple.MobileInternetSharing"
#else /* !TARGET_OS_EMBEDDED */
#define MIS_SERVICE_CLIENT_DS_KEY "com.apple.NetworkSharing"
#endif /* !TARGET_OS_EMBEDDED */
#if TARGET_OS_EMBEDDED
#define kMISLoggerID "com.apple.MobileInternetSharing"
#define kMISPrefID CFSTR("com.apple.MIS.logging.plist")
#define kMISDaemonLogging CFSTR("MISDLogging")
#else
#define kMISLoggerID "com.apple.NetworkSharing"
#define kMISPrefID CFSTR("com.apple.NS.logging.plist")
#define kMISDaemonLogging CFSTR("NSLogging")
#endif
#define NETRB_NAME_MAX 256
typedef char netrbName[NETRB_NAME_MAX];
#define NETRB_IFNAMSIZ 16
typedef char netrbIfName[NETRB_IFNAMSIZ];
#define NETRB_KEY_MAX 256
typedef char netrbKey[NETRB_KEY_MAX];
typedef struct NETRBClient *NETRBClientRef;
#if TARGET_OS_EMBEDDED
typedef enum {
NETRB_SVC_STATE_RESET = 1020,
NETRB_SVC_STATE_AUTH_UNKNOWN,
NETRB_SVC_STATE_OFF,
NETRB_SVC_STATE_ON,
} netrbState, *netrbStateRef;
/* temporary defines */
#define NETRB_SVC_STATE_CARRIER_OK NETRB_SVC_STATE_AUTH_UNKNOWN
#define NETRB_SVC_STATE_ENABLED NETRB_SVC_STATE_ON
#define NETRB_SVC_STATE_MIN NETRB_SVC_STATE_RESET
#define NETRB_SVC_STATE_MAX NETRB_SVC_STATE_ON
#define kNETRBPropVersion CFSTR("Version")
#define kNETRBPropState CFSTR("State")
typedef enum {
NETRB_SVC_REASON_NO_ERROR = 0,
NETRB_SVC_REASON_NOT_ALLOWED,
NETRB_SVC_REASON_IN_PROGRESS,
NETRB_SVC_REASON_AUTH_FAILURE,
NETRB_SVC_REASON_DATA_PREVENTED,
NETRB_SVC_REASON_AUTH_INCOMPLETE,
NETRB_SVC_REASON_MISC_ERROR,
} netrbReason, *netrbReasonRef;
#define kNETRBPropReason CFSTR("Reason")
#define kNETRBPropErrnum CFSTR("Errnum")
#define kNETRBPropHosts CFSTR("Hosts")
#define kNETRBPropHostsMax CFSTR("Max")
#define kNETRBPropHostsCurrent CFSTR("Current")
#define kNETRBPropHostsMoreAllowed CFSTR("MoreAllowed")
#define kNETRBPropHostsCurrentByType CFSTR("Type")
#define kNETRBPropHostsTypeEthernet CFSTR("Ethernet")
#define kNETRBPropHostsTypeAirPort CFSTR("AirPort")
#define kNETRBPropHostsTypeBluetooth CFSTR("Bluetooth")
#define kNETRBPropHostsTypeUSBEthernet CFSTR("USB-Ethernet")
#endif /* TARGET_OS_EMBEDDED */
#define kNETRBPropExternalInterface CFSTR("ExternalInterface")
#define kNETRBPropInternalInterfaces CFSTR("InternalInterfaces")
#define kNETRBPropExternalInterfaces CFSTR("ExternalInterfaces")
#define kNETRBForwardedPorts CFSTR("ForwardedPorts")
#define kNETRBForwardedPortsRangeLow CFSTR("Low")
#define kNETRBForwardedPortsRangeHigh CFSTR("High")
/*
* Valid interface device type values
*/
typedef enum {
NETRB_DEVTYPE_UNKNOWN = 0,
NETRB_DEVTYPE_AUTH,
NETRB_DEVTYPE_ETHERNET,
NETRB_DEVTYPE_AIRPORT,
NETRB_DEVTYPE_BLUETOOTH,
NETRB_DEVTYPE_USB_ETHERNET
} netrbIftype;
#define NETRB_DEVTYPE_MIN NETRB_DEVTYPE_ETHERNET
#define NETRB_DEVTYPE_MAX NETRB_DEVTYPE_USB_ETHERNET
#define NETRB_DEVTYPES (NETRB_DEVTYPE_MAX + 1)
typedef enum {
NETRB_DEFAULT_MODE = 200,
NETRB_INTERNET_SHARING_MODE,
NETRB_LOCAL_ONLY_MODE,
NETRB_LOCAL_WITH_DHCP_MODE
} netrbOpMode;
typedef enum {
NETRB_DEFAULT_BRIDGE = 300,
NETRB_NO_BRIDGE,
NETRB_LAN_BRIDGE,
NETRB_GUEST_BRIDGE
} netrbBridgeType;
typedef enum {
NETRB_AUTOMATIC_V4 = 400,
NETRB_MANUAL,
NETRB_AUTOMATIC_V6,
NETRB_MANUAL_V6,
NETRB_NONE
} netrbConfigMethod;
typedef enum {
NETRB_DEFAULT_NAT = 500,
NETRB_NONAT,
NETRB_NAT64
} netrbNatType;
/*
* Response id received in NETRBEventHandler block
*/
typedef enum {
NETRB_START_SERVICE = 1001,
NETRB_STOP_SERVICE,
NETRB_NOTIFICATION,
NETRB_NOTIFICATION_ERROR,
NETRB_INTERFACE_CREATE,
} response;
/*
* Notification Types
*/
typedef enum {
NETRB_EXTERNAL_SERVICE_LOST = 5000,
NETRB_EXTERNAL_SERVICE_RESTORED,
NETRB_SUCCESS,
NETRB_FAILURE,
} notification;
extern const char *netrbClientInterfaceName EXPORT;
extern const char *netrbClientDeviceType EXPORT;
extern const char *netrbClientInterfaceSpeed EXPORT;
extern const char *netrbClientInterfaceMTU EXPORT;
extern const char *netrbClientInterfaceInstance EXPORT;
extern const char *netrbClientInterfaceStartAddress EXPORT;
extern const char *netrbClientInterfaceEndAddress EXPORT;
extern const char *netrbClientInterfaceNetworkMask EXPORT;
extern char *netrbClientAnyExternal EXPORT;
extern const char *netrbClientNatType EXPORT;
extern const char *netrbClientNat64Param EXPORT;
extern const char *netrbClientDns64Prefix EXPORT;
extern const char *netrbClientRaPrefix EXPORT;
extern const char *netrbClientForwardedLowPort EXPORT;
extern const char *netrbClientForwardedHighPort EXPORT;
#if !TARGET_OS_EMBEDDED
extern const char *netrbClientMACAddress EXPORT;
extern const char *netrbClientMACUUID EXPORT;
extern const char *netrbClientSocketFD EXPORT;
#endif /* !TARGET_OS_EMBEDDED */
typedef int (^NETRBEventHandler)(response responseID, xpc_object_t events);
extern const char *netrbClientNotificationKey EXPORT;
extern NETRBClientRef _NETRBClientCreate(dispatch_queue_t eventQueue,
NETRBEventHandler eventHandlerBlock, xpc_object_t flags);
extern bool _NETRBClientDestroy(NETRBClientRef client);
extern bool _NETRBClientStartService(NETRBClientRef client, netrbIfName extName,
netrbOpMode opMode, netrbBridgeType bridgeType, xpc_object_t interfaceParam);
extern bool _NETRBClientStopService(NETRBClientRef client);
extern bool _NETRBClientGetDynamicStoreKey(NETRBClientRef client, netrbKey key);
#if TARGET_OS_EMBEDDED
extern bool _NETRBClientGetGlobalServiceState(NETRBClientRef client, netrbStateRef state,
netrbReasonRef reason);
extern bool _NETRBClientSetGlobalServiceState(NETRBClientRef client, netrbState state);
#endif /* TARGET_OS_EMBEDDED */
extern xpc_object_t _NETRBClientCopyFixtureForwardedPorts(NETRBClientRef client);
extern bool _NETRBClientSetFixtureForwardedPorts(NETRBClientRef client, xpc_object_t port);
#if TARGET_OS_EMBEDDED
extern bool _NETRBClientIsAllowedMoreHost(NETRBClientRef client);
extern bool _NETRBClientAddHost(NETRBClientRef client, netrbIftype type);
extern bool _NETRBClientRemoveHost(NETRBClientRef client, netrbIftype type);
extern bool _NETRBClientGetHostCount(NETRBClientRef client, uint32_t *max, uint32_t *current);
extern bool _NETRBClientSetHostCount(NETRBClientRef client, netrbIftype type, uint32_t count);
#endif /* TARGET_OS_EMBEDDED */
extern bool _NETRBClientGetExtName(NETRBClientRef client, netrbIfName extName);
#if !TARGET_OS_EMBEDDED
extern bool _NETRBClientNewInterface(NETRBClientRef client, netrbOpMode mode, uuid_t iid);
#endif
#ifdef __cplusplus
}
#endif
#endif /* NETRB_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment