什么是经常使用的网络编程功能/ code段? [英] What are often used network programming functions/code snippets?

查看:96
本文介绍了什么是经常使用的网络编程功能/ code段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们所有的人谁仍然做一些网络编程(TCP / UDP,DNS或客户机/服务器)用C多次反复使用一些code片段。

All of us who still do some kind of network programming (TCP/UDP, DNS or Client/Server) in C repeatedly use some code snippets again and again.

我们做一些使用标准库,但随后也我们写一些code很多时候这是不存在的一个库。

We do use some standard libraries but then also we do write some code very often which is not there in one library.

有没有经常用到这种code片段的集合。如果没有,那么在这里可以建立它。

Is there a collection of such code snippets that are used very often. If not then lets build it here.

推荐答案

好问题!

下面是一个解析功能

    struct hostent {
        char *h_name; // main name
        char **h_aliases; // alternative names (aliases)
        int h_addrtype; // address type (usually AF_INET)
        int h_length; // length of address (in octets)
        char **h_addr_list; // alternate addresses (in Network Byte Order)
    };
    #define h_addr h_addr_list[0] // First address of h_addr_list.


    struct hostent *info_stackoverflow;
    int i = 0;
    info_stackoverflow = gethostbyname( "www.stackoverflow.com" );
    printf("The IP address of %s is %s", 
           info_stackoverflow->h_name, 
           inet_ntoa( * ((struct in_addr *)info_stackoverflow->h_addr )));
    /* aliases */
    while( *(pc_ip->h_aliases + i) != NULL )
    {
        printf("\n\tAlias: %s", *(pc_ip->h_aliases + i) );
        i++;
    }

这篇关于什么是经常使用的网络编程功能/ code段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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