Skip to content

Commit

Permalink
Added Unix Implementations for Extracting Elements of addrInfo
Browse files Browse the repository at this point in the history
To extract length, family, socktype, protocol from addrInfo of OMRAddrInfoNode struct

- The OMRAddrInfoNode has two elements, which first element, named
  addrInfo, is a pointer to the first addrinfo node in a linked list
  of addrinfo nodes.
- The Unix addrinfo structs contains many elements which stores
  a variety of information about a socket address.
- Extracts unix addrinfo elements by passing in a pointer to a
  OMRAddrInfoNode and the index of which one of the linked list of
  addrinfo nodes to extract.
- Currently implemented the element extractions of what is needed
  to create a socket.

Issue: eclipse-omr#4745

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed Feb 6, 2020
1 parent e7da600 commit 649f56c
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,79 @@ omrsock_getaddrinfo(struct OMRPortLibrary *portLibrary, char *node, char *servic

int32_t
omrsock_getaddrinfo_length(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t handle, uint32_t *length)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
{
if (NULL == handle) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

*length = handle->length;
return 0;
}

int32_t
omrsock_getaddrinfo_family(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t handle, int32_t *family, int32_t index)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
{
if (NULL == handle) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

omr_os_addrinfo *info = handle->addrInfo;
int32_t i = 0;

if ((NULL == info) || (index > handle->length)) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

for (i = 0; i < index; i++) {
info = info->ai_next;
}

*family = info->ai_family;
return 0;
}

int32_t
omrsock_getaddrinfo_socktype(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t handle, int32_t *socktype, int32_t index)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
if (NULL == handle) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

omr_os_addrinfo *info = handle->addrInfo;
int32_t i = 0;

if ((NULL == info) || (index > handle->length)) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

for (i = 0; i < index; i++) {
info = info->ai_next;
}

*socktype = info->ai_socktype;
return 0;
}

int32_t
omrsock_getaddrinfo_protocol(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t handle, int32_t *protocol, int32_t index)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
if (NULL == handle) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

omr_os_addrinfo *info = handle->addrInfo;
int32_t i = 0;

if ((NULL == info) || (index > handle->length)) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

for (i = 0; i < index; i++) {
info = info->ai_next;
}

*protocol = info->ai_protocol;
return 0;
}

int32_t
Expand Down

0 comments on commit 649f56c

Please sign in to comment.