I\'m having issues getting the C sockets API to work properly in C++ on z/OS.
Although I am including sys/socket.h
, I still get compile time errors telling m
DISCLAIMER: I am not a C++ programmer, however I know C really well. I adapated these calls from some C code I have.
Also markdown put these strange _ as my underscores.
You should just be able to write an abstraction class around the C sockets with something like this:
class my_sock {
private int sock;
private int socket_type;
private socklen_t sock_len;
private struct sockaddr_in server_addr;
public char *server_ip;
public unsigned short server_port;
};
Then have methods for opening, closing, and sending packets down the socket.
For example, the open call might look something like this:
int my_socket_connect()
{
int return_code = 0;
if ( this->socket_type != CLIENT_SOCK ) {
cout << "This is a not a client socket!\n";
return -1;
}
return_code = connect( this->local_sock, (struct sockaddr *) &this->server_addr, sizeof(this->server_addr));
if( return_code < 0 ) {
cout << "Connect() failure! %s\n", strerror(errno);
return return_code;
}
return return_code;
}
I've had no trouble using the BSD sockets API in C++, in GNU/Linux. Here's the sample program I used:
#include <sys/socket.h>
int
main()
{
return AF_INET;
}
So my take on this is that z/OS is probably the complicating factor here, however, because I've never used z/OS before, much less programmed in it, I can't say this definitively. :-P
So try
#define _OE_SOCKETS
before you include sys/socket.h