如何显示在使用交流电插座方案报告客户端的IP地址? [英] How do i display client's ip address in the report using c socket program?

查看:131
本文介绍了如何显示在使用交流电插座方案报告客户端的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器报告需要在由服务器处理的报告显示客户端的IP地址,这是我需要显示从客户端发送的报告。我该怎么做呢?任何人可以帮助我吗?

I server report need to display the clients ip address in the report which is processed by the server,that is i need to display from which client the report is being sent. How do i do this? Can anybody help me out?

推荐答案

使用:

char clntName[INET6_ADDRSTRLEN];
char portName[6]; 

if (getnameinfo(&client_address,
                sizeof client_address,
                clntName,
                sizeof(clntName),
                NULL,
                0,
                NI_NUMERICHOST|NI_NUMERICSERV|NI_NUMERICSCOPE) == 0) {
    printf("Client = %s/%s\n",clntName,portName);
} else {
    printf("Unable to get address\n");
}

这篇关于如何显示在使用交流电插座方案报告客户端的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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