小编Dim*_*782的帖子

在C ++中创建交互式提示

我有一个程序应从控制台读取命令,并根据命令执行以下几种操作之一。这是我到目前为止的内容:

void ConwayView::listening_commands() {
    string command;

    do {
        cin >> command;

        if ("tick" == command)
        {
            // to do
        }
        else if ("start" == command)
        {
            // to do for start
        }
        ...

    } while (EXIT != command);
}
Run Code Online (Sandbox Code Playgroud)

如果存在大量命令switch,则使用代替if语句会有所帮助。您建议使用什么模式来提供交互式命令行?

c++ oop parameters design-patterns

4
推荐指数
3
解决办法
6917
查看次数

如何查询服务器并获取MX,A,NS记录

我正在尝试获取A,MX和NS A服务器记录,如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <resolv.h>
#include <netdb.h>

#define N 4096

int main (int argc, char *argv[])
{
    u_char nsbuf[N];
    char dispbuf[N];
    ns_msg msg;
    ns_rr rr;
    int i, l;

    if (argc < 2) {
        printf ("Usage: %s <domain>\n", argv[0]);
        exit (1);
    }

    // HEADER
    printf("Domain : %s\n", argv[1]);
    // ------

    // A RECORD
    printf("A records : \n");
    l = res_query(argv[1], ns_c_any, ns_t_a, nsbuf, sizeof(nsbuf));
    if (l < 0)
    {
      perror(argv[1]);
    }
    ns_initparse(nsbuf, l, &msg); …
Run Code Online (Sandbox Code Playgroud)

c unix sockets dns libresolv

4
推荐指数
1
解决办法
4333
查看次数

标签 统计

c ×1

c++ ×1

design-patterns ×1

dns ×1

libresolv ×1

oop ×1

parameters ×1

sockets ×1

unix ×1