Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * <:copyright-BRCM:2016:DUAL/GPL:standard |
| 4 | * |
| 5 | * Copyright (c) 2016 Broadcom |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Unless you and Broadcom execute a separate written software license |
| 9 | * agreement governing use of this software, this software is licensed |
| 10 | * to you under the terms of the GNU General Public License version 2 |
| 11 | * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 12 | * with the following added to such license: |
| 13 | * |
| 14 | * As a special exception, the copyright holders of this software give |
| 15 | * you permission to link this software with independent modules, and |
| 16 | * to copy and distribute the resulting executable under terms of your |
| 17 | * choice, provided that you also meet, for each linked independent |
| 18 | * module, the terms and conditions of the license of that module. |
| 19 | * An independent module is a module which is not derived from this |
| 20 | * software. The special exception does not apply to any modifications |
| 21 | * of the software. |
| 22 | * |
| 23 | * Not withstanding the above, under no circumstances may you combine |
| 24 | * this software in any way with any other Broadcom software provided |
| 25 | * under a license other than the GPL, without Broadcom's express prior |
| 26 | * written consent. |
| 27 | * |
| 28 | * :> |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | |
| 32 | /** |
| 33 | * @file bal_app_common_utils.c |
| 34 | * @brief BAL app common Utilities functionality |
| 35 | * |
| 36 | * @addtogroup util |
| 37 | */ |
| 38 | |
| 39 | /*@{*/ |
| 40 | |
| 41 | #include "bal_app_common_utils.h" |
| 42 | |
| 43 | /*****************************************************************************/ |
| 44 | /** |
| 45 | * @brief app_util_parse_ip_port |
| 46 | * |
| 47 | * This routine is used to parse the user supplied IP address and port of the |
| 48 | * remote MAC device. |
| 49 | * |
| 50 | * @param ip_port A string containing the IP:port to parse |
| 51 | * |
| 52 | * @param ip The IP address that results from the parsing function |
| 53 | * |
| 54 | * @param port The port that results from the parsing function |
| 55 | * |
| 56 | * @return bcmos_errno |
| 57 | */ |
| 58 | /*****************************************************************************/ |
| 59 | bcmos_errno app_util_parse_ip_port(const char *ip_port, uint32_t *ip, uint16_t *port) |
| 60 | { |
| 61 | int n; |
| 62 | uint32_t ip1, ip2, ip3, ip4, pp; |
| 63 | |
| 64 | if (!ip_port) |
| 65 | { |
| 66 | bcmos_printf("ERR: ip_port is not set\n"); |
| 67 | return BCM_ERR_PARM; |
| 68 | } |
| 69 | n = sscanf(ip_port, "%u.%u.%u.%u:%u", &ip1, &ip2, &ip3, &ip4, &pp); |
| 70 | if (n != 5 || ip1 > 0xff || ip2 > 0xff || ip3 > 0xff || ip4 > 0xff || pp > 0xffff) |
| 71 | { |
| 72 | bcmos_printf("ERR: Can't parse %s. Must be ip_address:port\n", ip_port); |
| 73 | return BCM_ERR_PARM; |
| 74 | } |
| 75 | *ip = (ip1 << 24) | (ip2 << 16) | (ip3 << 8) | ip4; |
| 76 | *port = pp; |
| 77 | return BCM_ERR_OK; |
| 78 | } |
| 79 | |
| 80 | /*@}*/ |
| 81 | |