blob: 83894d638cc9cee2b95fe7893b7482a86bfba3b5 [file] [log] [blame]
/******************************************************************************
*
* <:copyright-BRCM:2016:DUAL/GPL:standard
*
* Copyright (c) 2016 Broadcom
* All Rights Reserved
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed
* to you under the terms of the GNU General Public License version 2
* (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
* with the following added to such license:
*
* As a special exception, the copyright holders of this software give
* you permission to link this software with independent modules, and
* to copy and distribute the resulting executable under terms of your
* choice, provided that you also meet, for each linked independent
* module, the terms and conditions of the license of that module.
* An independent module is a module which is not derived from this
* software. The special exception does not apply to any modifications
* of the software.
*
* Not withstanding the above, under no circumstances may you combine
* this software in any way with any other Broadcom software provided
* under a license other than the GPL, without Broadcom's express prior
* written consent.
*
* :>
*
*****************************************************************************/
/**
* @file bal_app_common_utils.c
* @brief BAL app common Utilities functionality
*
* @addtogroup util
*/
/*@{*/
#include "bal_app_common_utils.h"
/*****************************************************************************/
/**
* @brief app_util_parse_ip_port
*
* This routine is used to parse the user supplied IP address and port of the
* remote MAC device.
*
* @param ip_port A string containing the IP:port to parse
*
* @param ip The IP address that results from the parsing function
*
* @param port The port that results from the parsing function
*
* @return bcmos_errno
*/
/*****************************************************************************/
bcmos_errno app_util_parse_ip_port(const char *ip_port, uint32_t *ip, uint16_t *port)
{
int n;
uint32_t ip1, ip2, ip3, ip4, pp;
if (!ip_port)
{
bcmos_printf("ERR: ip_port is not set\n");
return BCM_ERR_PARM;
}
n = sscanf(ip_port, "%u.%u.%u.%u:%u", &ip1, &ip2, &ip3, &ip4, &pp);
if (n != 5 || ip1 > 0xff || ip2 > 0xff || ip3 > 0xff || ip4 > 0xff || pp > 0xffff)
{
bcmos_printf("ERR: Can't parse %s. Must be ip_address:port\n", ip_port);
return BCM_ERR_PARM;
}
*ip = (ip1 << 24) | (ip2 << 16) | (ip3 << 8) | ip4;
*port = pp;
return BCM_ERR_OK;
}
/*@}*/