Skip to content

Commit 4e6349c

Browse files
committed
implement inet_pton
1 parent 70c34ae commit 4e6349c

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_library(ogc STATIC
88
lwpcompat/lwpc_mq.c
99

1010
ogc_sockets/soc_init.c
11+
ogc_sockets/soc_inet_pton.c
1112
ogc_sockets/soc_common.c
1213
ogc_sockets/soc_socket.c
1314
ogc_sockets/soc_bind.c

libogc/ogc_sockets/soc_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string.h>
66
#include <sys/iosupport.h>
77
#include <gctypes.h>
8+
#include <gccore.h>
89
#include <network.h>
910

1011
#define SYNC_ERROR ENODEV

libogc/ogc_sockets/soc_inet_pton.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "soc_common.h"
2+
#include <arpa/inet.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
6+
7+
static int inet_pton4(const char *restrict src, void *restrict dst)
8+
{
9+
u8 ip[4] ATTRIBUTE_ALIGN(4);
10+
if(sscanf(src,"%hhu.%hhu.%hhu.%hhu",&ip[0], &ip[1], &ip[2], &ip[3]) != 4) return 0;
11+
12+
memcpy(dst,ip,4);
13+
return 1;
14+
}
15+
16+
17+
int inet_pton(int af, const char *restrict src, void *restrict dst)
18+
{
19+
if(af == AF_INET)
20+
{
21+
return inet_pton4(src,dst);
22+
}
23+
// only support IPv4
24+
errno = EAFNOSUPPORT;
25+
return -1;
26+
}

0 commit comments

Comments
 (0)