rmnetctl: Fix compilation warnings for 64bit support

Fix compilation warnings & KW warnings to support 64 bit.

CRs-Fixed: 609463
Change-Id: Ib74cc09551b0c63e215873dd6ece68392aab1c8e
Acked-by: Sivan Reinstein <sivanr@qti.qualcomm.com>
diff --git a/Android.mk b/Android.mk
index 9f4279d..5053e7d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,5 +1 @@
-ifneq (, $(filter aarch64 arm64, $(TARGET_ARCH)))
-    $(info TODOAArch64: $(LOCAL_PATH)/Android.mk: Enable build support for 64 bit)
-else
 include $(call all-subdir-makefiles)
-endif # $(TARGET_ARCH)
diff --git a/rmnetctl/cli/rmnetcli.c b/rmnetctl/cli/rmnetcli.c
index f6b387e..fdbe3c6 100644
--- a/rmnetctl/cli/rmnetcli.c
+++ b/rmnetctl/cli/rmnetcli.c
@@ -352,6 +352,7 @@
 		if (!egress_dev_name) {
 			print_rmnet_api_status(RMNETCTL_LIB_ERR,
 			RMNETCTL_CFG_FAILURE_EGRESS_DEV_NAME_NULL);
+			rmnetctl_cleanup(handle);
 			return RMNETCTL_LIB_ERR;
 		}
 		return_code = rmnet_get_logical_ep_config(handle,
@@ -361,6 +362,7 @@
 			printf("rmnet_mode is %u\n", rmnet_mode);
 			printf("egress_dev_name is %s\n", egress_dev_name);
 		}
+		free(egress_dev_name);
 	} else if (!strcmp(*argv, "addvnctcflow")) {
 		_RMNETCLI_CHECKNULL(argv[1]);
 		_RMNETCLI_CHECKNULL(argv[2]);
diff --git a/rmnetctl/inc/librmnetctl_hndl.h b/rmnetctl/inc/librmnetctl_hndl.h
index e88d040..c020e7b 100644
--- a/rmnetctl/inc/librmnetctl_hndl.h
+++ b/rmnetctl/inc/librmnetctl_hndl.h
@@ -57,7 +57,7 @@
 struct rmnetctl_hndl_s {
 	 uint32_t pid;
 	 uint32_t transaction_id;
-	 uint32_t netlink_fd;
+	 int netlink_fd;
 	 struct sockaddr_nl src_addr, dest_addr;
 };
 
diff --git a/rmnetctl/src/librmnetctl.c b/rmnetctl/src/librmnetctl.c
index efd5d20..893fa15 100644
--- a/rmnetctl/src/librmnetctl.c
+++ b/rmnetctl/src/librmnetctl.c
@@ -98,13 +98,15 @@
 * @return RMNETCTL_API_ERR_MESSAGE_TYPE if the request and response type do not
 * match
 */
-static int rmnetctl_transact(rmnetctl_hndl_t *hndl,
+static uint16_t rmnetctl_transact(rmnetctl_hndl_t *hndl,
 			struct rmnet_nl_msg_s *request,
 			struct rmnet_nl_msg_s *response) {
 	uint8_t *request_buf, *response_buf;
 	struct nlmsghdr *nlmsghdr_val;
 	struct rmnet_nl_msg_s *rmnet_nl_msg_s_val;
-	int bytes_read = -1, return_code = RMNETCTL_API_ERR_HNDL_INVALID;
+	ssize_t bytes_read = -1;
+	uint16_t return_code = RMNETCTL_API_ERR_HNDL_INVALID;
+	struct sockaddr_nl* __attribute__((__may_alias__)) saddr_ptr;
 	request_buf = NULL;
 	response_buf = NULL;
 	nlmsghdr_val = NULL;
@@ -150,12 +152,13 @@
 	rmnet_nl_msg_s_val->crd = RMNET_NETLINK_MSG_COMMAND;
 	hndl->transaction_id++;
 
+	saddr_ptr = &hndl->dest_addr;
 	socklen_t addrlen = sizeof(struct sockaddr_nl);
 	if (sendto(hndl->netlink_fd,
 			request_buf,
 			MAX_BUF_SIZE,
 			RMNETCTL_SOCK_FLAG,
-			(struct sockaddr *) &hndl->dest_addr,
+			(struct sockaddr*)saddr_ptr,
 			sizeof(struct sockaddr_nl)) < 0) {
 		return_code = RMNETCTL_API_ERR_MESSAGE_SEND;
 		free(request_buf);
@@ -163,11 +166,12 @@
 		break;
 	}
 
+	saddr_ptr = &hndl->src_addr;
 	bytes_read = recvfrom(hndl->netlink_fd,
 			response_buf,
 			MAX_BUF_SIZE,
 			RMNETCTL_SOCK_FLAG,
-			(struct sockaddr *) &hndl->src_addr,
+			(struct sockaddr*)saddr_ptr,
 			&addrlen);
 	if (bytes_read < 0) {
 		return_code = RMNETCTL_API_ERR_MESSAGE_RECEIVE;
@@ -227,10 +231,10 @@
 * @return RMNETCTL_SUCCESS if successful
 * @return RMNETCTL_LIB_ERR if there was a library error. Check error_code
 */
-static inline int _rmnetctl_check_len(int str_len, uint16_t *error_code) {
+static inline int _rmnetctl_check_len(size_t str_len, uint16_t *error_code) {
 	int return_code = RMNETCTL_LIB_ERR;
 	do {
-	if ((str_len < 0) || (str_len > RMNET_MAX_STR_LEN)) {
+	if (str_len > RMNET_MAX_STR_LEN) {
 		*error_code = RMNETCTL_API_ERR_STRING_TRUNCATION;
 		break;
 	}
@@ -294,7 +298,7 @@
 	if (error_val == RMNET_CONFIG_OK)
 		return_code = RMNETCTL_SUCCESS;
 	else
-		*error_code = error_val + RMNETCTL_KERNEL_FIRST_ERR;
+		*error_code = (uint16_t)error_val + RMNETCTL_KERNEL_FIRST_ERR;
 	return return_code;
 }
 
@@ -304,7 +308,9 @@
 
 int rmnetctl_init(rmnetctl_hndl_t **hndl, uint16_t *error_code)
 {
-	int pid = -1, netlink_fd = -1, return_code = RMNETCTL_LIB_ERR;
+	pid_t pid = 0;
+	int netlink_fd = -1, return_code = RMNETCTL_LIB_ERR;
+	struct sockaddr_nl* __attribute__((__may_alias__)) saddr_ptr;
 	do {
 	if ((!hndl) || (!error_code)){
 		return_code = RMNETCTL_INVALID_ARG;
@@ -325,7 +331,7 @@
 		*error_code = RMNETCTL_INIT_ERR_PROCESS_ID;
 		break;
 	}
-	(*hndl)->pid = pid;
+	(*hndl)->pid = (uint32_t)pid;
 	netlink_fd = socket(PF_NETLINK, SOCK_RAW, RMNET_NETLINK_PROTO);
 	if (netlink_fd < MIN_VALID_SOCKET_FD) {
 		free(*hndl);
@@ -340,8 +346,9 @@
 	(*hndl)->src_addr.nl_family = AF_NETLINK;
 	(*hndl)->src_addr.nl_pid = (*hndl)->pid;
 
+	saddr_ptr = &(*hndl)->src_addr;
 	if (bind((*hndl)->netlink_fd,
-		(struct sockaddr *)&(*hndl)->src_addr,
+		(struct sockaddr*)saddr_ptr,
 		sizeof(struct sockaddr_nl)) < 0) {
 		close((*hndl)->netlink_fd);
 		free(*hndl);
@@ -374,7 +381,8 @@
 				   uint8_t assoc_dev)
 {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
 		((assoc_dev != RMNETCTL_DEVICE_ASSOCIATE) &&
@@ -389,7 +397,7 @@
 		request.message_type = RMNET_NETLINK_UNASSOCIATE_NETWORK_DEVICE;
 
 	request.arg_length = RMNET_MAX_STR_LEN;
-	str_len = strlcpy((char *)(request.data), dev_name, RMNET_MAX_STR_LEN);
+	str_len = strlcpy((char *)(request.data), dev_name, (size_t)RMNET_MAX_STR_LEN);
 	if (_rmnetctl_check_len(str_len, error_code) != RMNETCTL_SUCCESS)
 		break;
 
@@ -408,7 +416,8 @@
 					int *register_status,
 					uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int  return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!register_status) || (!error_code) ||
 	_rmnetctl_check_dev_name(dev_name)) {
@@ -443,7 +452,8 @@
 				      const char *dev_name,
 				      uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int  return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
 	    ((~EGRESS_FLAGS_MASK) & egress_flags)) {
@@ -484,7 +494,8 @@
 				      uint16_t *agg_count,
 				      uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int  return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!egress_flags) || (!agg_size) || (!agg_count) ||
 	(!error_code) || _rmnetctl_check_dev_name(dev_name)) {
@@ -521,7 +532,8 @@
 						 const char *dev_name,
 						 uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int  return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!error_code) || _rmnetctl_check_dev_name(dev_name) ||
 	    ((~INGRESS_FLAGS_MASK) & ingress_flags)) {
@@ -559,7 +571,8 @@
 						 uint8_t  *tail_spacing,
 						 uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int  return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!error_code) ||
 		_rmnetctl_check_dev_name(dev_name)) {
@@ -601,7 +614,8 @@
 				const char *next_dev,
 				uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || ((ep_id < -1) || (ep_id > 31)) || (!error_code) ||
 		_rmnetctl_check_dev_name(dev_name) ||
@@ -645,7 +659,8 @@
 				  const char *dev_name,
 				  uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int return_code = RMNETCTL_LIB_ERR;
 	do {
 
 	if ((!hndl) || ((ep_id < -1) || (ep_id > 31)) || (!error_code) ||
@@ -686,7 +701,8 @@
 				uint32_t next_dev_len,
 				uint16_t *error_code) {
 	struct rmnet_nl_msg_s request, response;
-	int str_len = -1, return_code = RMNETCTL_LIB_ERR;
+	size_t str_len = 0;
+	int return_code = RMNETCTL_LIB_ERR;
 	do {
 	if ((!hndl) || (!operating_mode) || (!error_code) || ((ep_id < -1) ||
 	    (ep_id > 31)) || _rmnetctl_check_dev_name(dev_name) || (!next_dev)
@@ -732,7 +748,7 @@
 {
 	struct rmnet_nl_msg_s request, response;
 	int return_code = RMNETCTL_LIB_ERR;
-	int str_len = -1;
+	size_t str_len = 0;
 	do {
 	if ((!hndl) || (!error_code) ||
 	((new_vnd != RMNETCTL_NEW_VND) && (new_vnd != RMNETCTL_FREE_VND))) {
@@ -804,7 +820,7 @@
 	if (_rmnetctl_check_data(response.crd, error_code) != RMNETCTL_SUCCESS)
 		break;
 
-	str_len = strlcpy(buf,
+	str_len = (uint32_t)strlcpy(buf,
 			  (char *)(response.vnd.vnd_name),
 			  buflen);
 	if (str_len >= buflen) {