Skip to content

Commit

Permalink
Added new define and required by ZOS
Browse files Browse the repository at this point in the history
Added a new definition to expose additional functions

- Added _OPEN_SYS_SOCK_IPV6 definition to ZOS to expose additional
  functions and definitions such as inet_pton and sockaddr_storage
  according to documentations.
- Added void pointer casting to inet_pton argument.
- Added new return case where slightly more details are returned to
  user.
- Added a conversion to allow proper enocding by ZOS.

Issue: eclipse-omr#5066

Signed-off-by: Haley Cao <[email protected]>
  • Loading branch information
Haley Cao committed May 25, 2020
1 parent 56abd35 commit eb30fa4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 0 additions & 1 deletion fvtest/porttest/omrsockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ TEST(PortSockTest, create_dotted_decimal_IPv4_socket_address)
EXPECT_EQ(OMRPORTLIB->sock_bind(OMRPORTLIB, socket, &sockAddr), 0);
EXPECT_EQ(OMRPORTLIB->sock_listen(OMRPORTLIB, socket, 10), 0);
EXPECT_EQ(OMRPORTLIB->sock_close(OMRPORTLIB, &socket), 0);

}

/**
Expand Down
7 changes: 4 additions & 3 deletions include_core/omrporterror.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,10 @@
#define OMRPORT_ERROR_SOCK_ADDRINFO_FAILED (OMRPORT_ERROR_SOCK_BASE - 2)
#define OMRPORT_ERROR_SOCK_SOCKET_CREATION_FAILED (OMRPORT_ERROR_SOCK_BASE - 3)
#define OMRPORT_ERROR_SOCK_SOCKET_CLOSE_FAILED (OMRPORT_ERROR_SOCK_BASE - 4)
#define OMRPORT_ERROR_SOCK_INET_PTON_FAILED (OMRPORT_ERROR_SOCK_BASE - 5)
#define OMRPORT_ERROR_SOCK_BIND_FAILED (OMRPORT_ERROR_SOCK_BASE - 6)
#define OMRPORT_ERROR_SOCK_LISTEN_FAILED (OMRPORT_ERROR_SOCK_BASE - 7)
#define OMRPORT_ERROR_SOCK_INVALID_ADDRESS (OMRPORT_ERROR_SOCK_BASE - 5)
#define OMRPORT_ERROR_SOCK_UNSUPPORTED_AF (OMRPORT_ERROR_SOCK_BASE - 6)
#define OMRPORT_ERROR_SOCK_BIND_FAILED (OMRPORT_ERROR_SOCK_BASE - 7)
#define OMRPORT_ERROR_SOCK_LISTEN_FAILED (OMRPORT_ERROR_SOCK_BASE - 8)
/**
* @}
*/
Expand Down
26 changes: 23 additions & 3 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include "omrporterror.h"
#include "omrsockptb.h"

#if defined(J9ZOS390) && !defined(OMR_EBCDIC)
#include "atoe.h"
#endif /* defined(J9ZOS390) && !defined(OMR_EBCDIC) */

/* Internal: OMRSOCK user interface constants TO OS dependent constants mapping. */

/**
Expand Down Expand Up @@ -560,14 +564,30 @@ omrsock_htonl(struct OMRPortLibrary *portLibrary, uint32_t val)
int32_t
omrsock_inet_pton(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const char *addr, uint8_t *addrNetworkOrder)
{
int32_t rc;
#if defined(J9ZOS390) && !defined(OMR_EBCDIC)
char * addrA2e;
#endif /* defined(J9ZOS390) && !defined(OMR_EBCDIC) */

if (NULL == addrNetworkOrder) {
return OMRPORT_ERROR_INVALID_ARGUMENTS;
}

if (1 != inet_pton(get_os_family(addrFamily), addr, addrNetworkOrder)) {
return OMRPORT_ERROR_SOCK_INET_PTON_FAILED;
}
#if defined(J9ZOS390) && !defined(OMR_EBCDIC)
addrA2e = a2e(addr, strlen(addr));
rc = inet_pton(get_os_family(addrFamily), addrA2e, (void *)addrNetworkOrder);
free(addrA2e);
#else /* defined(J9ZOS390) && !defined(OMR_EBCDIC) */
rc = inet_pton(get_os_family(addrFamily), addr, (void *)addrNetworkOrder);
#endif /* defined(J9ZOS390) && !defined(OMR_EBCDIC) */

if (rc == 0) {
portLibrary->error_set_last_error(portLibrary, 0, OMRPORT_ERROR_SOCK_INVALID_ADDRESS);
return OMRPORT_ERROR_SOCK_INVALID_ADDRESS;
} else if (rc == -1) {
portLibrary->error_set_last_error(portLibrary, errno, OMRPORT_ERROR_SOCK_UNSUPPORTED_AF);
return OMRPORT_ERROR_SOCK_UNSUPPORTED_AF;
}
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions port/unix_include/omrsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#define _OE_SOCKETS
#endif

/* This exposes some definitions needed by the socket api */
#if defined(OMR_OS_ZOS) && !defined(_OPEN_SYS_SOCK_IPV6)
#define _OPEN_SYS_SOCK_IPV6
#endif

#include <sys/types.h> /* Some historical implementations need this file, POSIX.1-2001 does not. */
#include <sys/socket.h>

Expand Down

0 comments on commit eb30fa4

Please sign in to comment.