Skip to content

Instantly share code, notes, and snippets.

@forthxu
Created January 23, 2014 09:15
Show Gist options
  • Save forthxu/5295454466d2e4aa2ce9 to your computer and use it in GitHub Desktop.
Save forthxu/5295454466d2e4aa2ce9 to your computer and use it in GitHub Desktop.
自己在使用云风的skynet https://github.com/cloudwu/skynet 自带客户端做测试的时候发现对域名地址是不支持的 在客户端代码增加一个判断,c域名转ip
#include <netdb.h>
struct sockaddr_in my_addr;
my_addr.sin_addr.s_addr=inet_addr(argv[1]);
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(strtol(argv[2],NULL,10));
if (my_addr.sin_addr.s_addr == INADDR_NONE)
{
struct hostent *lphost;
lphost = gethostbyname(argv[1]);
//printf("addr:%s\n",lphost->h_name);
//printf("IP Address :%s\n",inet_ntoa(*((struct in_addr *)lphost->h_addr)));
if (lphost != NULL)
my_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)lphost->h_addr)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment