免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: i802
打印 上一主题 下一主题

怎样读取命令行参数中的“点分IP地址”? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2007-04-08 18:17 |只看该作者
原帖由 flw2 于 2007-4-8 17:36 发表

?

MSDN WSAStringToAddress

论坛徽章:
0
12 [报告]
发表于 2007-04-08 18:21 |只看该作者
无题
* int
* inet_pton4(src, dst)
*        like inet_aton() but without all the hexadecimal and shorthand.
* return:
*        1 if `src' is a valid dotted quad, else 0.
* notice:
*        does not touch `dst' unless it's returning 1.
* author:
*        Paul Vixie, 1996.
*/
static int
inet_pton4(src, dst)
        const char *src;
        unsigned char *dst;
{
        static const char digits[] = "0123456789";
        int saw_digit, octets, ch;
        unsigned char tmp[NS_INADDRSZ], *tp;

        saw_digit = 0;
        octets = 0;
        *(tp = tmp) = 0;
        while ((ch = *src++) != '\0') {
                const char *pch;

                if ((pch = strchr(digits, ch)) != NULL) {
                        unsigned int new = *tp * 10 + (pch - digits);

                        if (new > 255)
                                return (0);
                        *tp = new;
                        if (! saw_digit) {
                                if (++octets > 4)
                                        return (0);
                                saw_digit = 1;
                        }
                } else if (ch == '.' && saw_digit) {
                        if (octets == 4)
                                return (0);
                        *++tp = 0;
                        saw_digit = 0;
                } else
                        return (0);
        }
        if (octets < 4)
                return (0);
        memcpy(dst, tmp, NS_INADDRSZ);
        return (1);
}

论坛徽章:
0
13 [报告]
发表于 2007-04-08 23:06 |只看该作者
长知识了,:)

论坛徽章:
0
14 [报告]
发表于 2007-04-09 09:20 |只看该作者
原帖由 koolcoy 于 2007-4-8 16:24 发表

somecmd.exe 呵呵


人家是gcc -o somecmd.exe 不可以么
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP