blob: 463a45d09ef03d1bfa7c903bec2576284000d40e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/* Copyright (c) 2016, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "config.h"
#include <odp/helper/ip.h>
#include <stdio.h>
#include <string.h>
int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str)
{
unsigned byte[ODPH_IPV4ADDR_LEN];
int i;
memset(byte, 0, sizeof(byte));
if (sscanf(str, "%u.%u.%u.%u",
&byte[0], &byte[1], &byte[2], &byte[3]) != ODPH_IPV4ADDR_LEN)
return -1;
for (i = 0; i < ODPH_IPV4ADDR_LEN; i++)
if (byte[i] > 255)
return -1;
*ip_addr = byte[0] << 24 | byte[1] << 16 | byte[2] << 8 | byte[3];
return 0;
}
|