如何在z/OS上的C ++中使用C套接字API [英] How to use the C socket API in C++ on z/OS

查看:101
本文介绍了如何在z/OS上的C ++中使用C套接字API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使C套接字API在z/OSC++中正常工作时遇到问题.

I'm having issues getting the C sockets API to work properly in C++ on z/OS.

尽管我包括了sys/socket.h,但仍然出现编译时错误,告诉我 AF_INET未定义.

Although I am including sys/socket.h, I still get compile time errors telling me that AF_INET is not defined.

我是否遗漏了一些明显的东西,或者这与以下事实有关:在z/OS上使我的问题更加复杂了?

Am I missing something obvious, or is this related to the fact that being on z/OS makes my problems much more complicated?

更新:经过进一步调查,我发现我正在击中#ifdef.显然,除非我定义要使用的套接字的类型",否则z/OS不会满意:

Update : Upon further investigation, I discovered that there is an #ifdef that I'm hitting. Apparently z/OS isn't happy unless I define which "type" of sockets I'm using with:

#define _OE_SOCKETS

现在,我个人不知道此_OE_SOCKETS的实际用途,因此,如果有任何z/OS套接字程序员在那里(你们三个人),也许您可​​以给我一个总结一下这一切的工作原理?

Now, I personally have no idea what this _OE_SOCKETS is actually for, so if any z/OS sockets programmers are out there (all 3 of you), perhaps you could give me a rundown of how this all works?

测试应用

#include <sys/socket.h>

int main()
{
    return AF_INET;
}

编译/链接输出:

cxx -Wc,xplink -Wl,xplink -o inet_test inet.C

"./inet.C", line 5.16: CCN5274 (S) The name lookup for "AF_INET" did not find a declaration.
CCN0797(I) Compilation failed for file ./inet.C. Object file not created.


检查sys/sockets.h确实包含了我需要的定义,据我所知,它没有被任何#ifdef语句阻止.


A check of sys/sockets.h does include the definition I need, and as far as I can tell, it is not being blocked by any #ifdef statements.

但是我发现它包含以下内容:

I have however noticed it contains the following:

#ifdef __cplusplus
  extern "C" {
#endif

哪个基本上封装了整个文件?不确定是否重要.

which encapsulates basically the whole file? Not sure if it matters.

推荐答案

方便地保留IBM手册的副本:

Keep a copy of the IBM manuals handy:

  • z/OS V1R11.0 XL C/C++ Programming Guide
  • z/OS V1R11.0 XL C/C++ Run-Time Library Reference

IBM出版物通常非常好,但是您需要习惯它们的格式,以及知道在哪里寻找答案.您会经常发现您要使用的功能受功能测试宏"保护

The IBM publications are generally very good, but you need to get used to their format, as well as knowing where to look for an answer. You'll find quite often that a feature that you want to use is guarded by a "feature test macro"

您应该请友好的系统程序员安装 XL C/C ++运行时库参考:手册页 在您的系统上.然后,您可以执行"man connect"之类的操作来拉出socket connect()API的手册页.当我这样做时,这就是我看到的:

You should ask your friendly system programmer to install the XL C/C++ Run-Time Library Reference: Man Pages on your system. Then you can do things like "man connect" to pull up the man page for the socket connect() API. When I do that, this is what I see:

FORMAT

X/打开

#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/socket.h>

int connect(int socket, const struct sockaddr *address, socklen_t address_len);

Berkeley插座

Berkeley Sockets

#define _OE_SOCKETS
#include <sys/types.h>
#include <sys/socket.h>

int connect(int socket, struct sockaddr *address, int address_len);

这篇关于如何在z/OS上的C ++中使用C套接字API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆