Connecting to an IP camera using Pixhawk 6x

I am attempting to connect and communicate with a Bosch IP camera over their RCP protocol. This is working fine on my ubuntu PC however when I try to run similar code on my pixhawk it is unable to connect to the socket that I create. I have looked through the source code for similar uses of sockets in nuttx and mavlink so I am wondering why it isnt working for me. The error I get back from my program is “Network is unreachable”. I can ping the camera from the GQC shell.

Here is the function I call to connect:

typedef struct {
	char address[MAX_IP_LENGTH];
	int user_level;
	char password[MAX_PASSWORD_LENGTH];

	unsigned short client_id;

	struct sockaddr_in ctrl_addr;
	int control_socket;

} rcp_connection;

rcp_connection con;

int rcp_connect(const char* ip)
{
	strcpy(con.address, ip);
	struct hostent *hp;
	hp = gethostbyname(ip);

	PX4_INFO("Host name: %s", hp->h_addr_list[0]);

	PX4_INFO("Attempting connection to: %s", ip);

	memset(&con.ctrl_addr, 0, sizeof(struct sockaddr_in));

	con.ctrl_addr.sin_family = AF_INET;
	memcpy((char *)&con.ctrl_addr.sin_addr, hp->h_addr_list[0],  hp->h_length);
	con.ctrl_addr.sin_port = htons(RCP_CONTROL_PORT);

	PX4_INFO("sin_addr: %s", inet_ntoa(con.ctrl_addr.sin_addr));

	PX4_INFO("header length: %d", hp->h_length);

	con.control_socket = socket(PF_INET, SOCK_STREAM, 0);

	if (con.control_socket == -1)
	{
		PX4_INFO("Failed to create socket: %d - %s", errno, strerror(errno));
		return -1;
	}
	int res = connect(con.control_socket, (struct sockaddr *)&con.ctrl_addr, sizeof(con.ctrl_addr));
	if (res == -1)
	{
		PX4_INFO("Socket connection error%d - %s", errno, strerror(errno));
	}

	return 0;
}