Can we use C socket API in C++ on z/OS, yes, how?

C/C++ and Java for MVS & zOS.
Previous topicNext topic

Topic Author
Deepika P
New Member
Posts: 3
Joined: Sat Sep 20, 2014 11:05 am

Can we use C socket API in C++ on z/OS, yes, how?

Post by Deepika P » Thu May 14, 2015 2:50 pm

Hi,

I'm facing issues in making C sockets API to work properly in C++ on zOS. I have included sys and socket.h though I still get compile time errors stating AF_INET is not defined. I am not sure how to solve it? Is there something obvious which is not done? Or is it something to do with that it is on zOS? Please help.




enrico-sorichetti
Global Moderator
Global Moderator
Posts: 892
Joined: Wed Sep 11, 2013 3:57 pm

Re: Can we use C socket API in C++ on z/OS, yes, how?

Post by enrico-sorichetti » Thu May 14, 2015 5:35 pm

what has to be included before what has alway been a murky issue in the unix and unix-like world

for IBM is even a bit worse

to get the AF_INET defines You should provide a ...

Code: Select all

#define _OE_SOCKETS
but that is not enough

I got the AF_INET definition with this sequence

Code: Select all

#include <stdio.h>
#define _OE_SOCKETS
 #include <net/if.h>
#include <sys/socket.h>
 int main(int argc, char **argv)
{
    printf("AF_NET value is >>%d<<\n", AF_INET);
    return (0);
}
just play around with something similar
to find out what is going on


cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)

User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1379
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: Can we use C socket API in C++ on z/OS, yes, how?

Post by Robert Sample » Thu May 14, 2015 5:36 pm

AF_INET is defined as part of your TCP/IP stack. Hence you need to contact your site support group and work with them to get it defined.




enrico-sorichetti
Global Moderator
Global Moderator
Posts: 892
Joined: Wed Sep 11, 2013 3:57 pm

Re: Can we use C socket API in C++ on z/OS, yes, how?

Post by enrico-sorichetti » Thu May 14, 2015 5:46 pm

AF_INET is defined as part of your TCP/IP stack. Hence you need to contact your site support group and work with them to get it defined.
sadly as per my previous reply is obscurely #ifdeffed (**)

since I am a bit lazy, it was faster for me to look at socket.h instead of looking at the manuals

the net/if.h include (**) is a different can of worms

(**) both quirks are probably documented in the IBM manuals

/sandbox on

bot on linux and apple

things have changed over the years

a few years ago it had the prerequisite of sys/types.h

now socket.h compiles well without any prerequisites


cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)

Previous topicNext topic

Return to “C, C++ and Java for Mainframes.”