USBMuxConnectByPort

From The iPhone Wiki
Revision as of 10:04, 16 May 2010 by Http (talk | contribs) (formatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Function that can be used to tunnel TCP connections over USB, useful for SSH and other stuff

//import iTunesMobileDevice.dll or link with MobileDevice.framework

int USBMuxConnectByPort(int connectionID, int iPhone_port_network_byte_order, int* outHandle);

Example code snippet:

//iphone_port - TCP service port to connect to on the iPhone
//target_device - get this from a device callback.. use AMDeviceNotificationSubscribe to register callback.
		int ret = USBMuxConnectByPort(AMDeviceGetConnectionID(target_device), htons(iphone_port), &handle);
		if (ret != ERR_SUCCESS) {
			printf("USBMuxConnectByPort = %x\n", ret);
			goto error_service;
		}
		
		ret = AFCConnectionOpen(handle, 0, &afc_con);
		if (ret != ERR_SUCCESS) {
			printf ( "AFCConnectionOpen = %i\n" , ret );
			goto error_service;
		}
//handle - handle to use for send/recv