Skip to content

Commit d0f4ea8

Browse files
committed
implement getsockname
1 parent daaa9b9 commit d0f4ea8

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(ogc STATIC
1717
ogc_sockets/soc_shutdown.c
1818
ogc_sockets/soc_accept.c
1919
ogc_sockets/soc_poll.c
20+
ogc_sockets/soc_getsockname.c
2021

2122
console.c
2223
lwp_queue.c
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "soc_common.h"
2+
#include <errno.h>
3+
#include <sys/socket.h>
4+
5+
6+
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
7+
{
8+
sockfd = soc_get_fd(sockfd);
9+
10+
if(sockfd < 0) {
11+
errno = -sockfd;
12+
return -1;
13+
}
14+
15+
int dev = FindDevice("soc:");
16+
if(dev < 0) {
17+
errno = ENODEV;
18+
return -1;
19+
}
20+
21+
int ret = net_getsockname(sockfd, addr, addrlen);
22+
23+
if (ret < 0 ) {
24+
errno = -ret;
25+
ret = -1;
26+
}
27+
return ret;
28+
}

0 commit comments

Comments
 (0)