获取本地IP
char hostname[256];
gethostname(hostname, sizeof hostname);
hostent* pHostent = gethostbyname(hostname);
sockaddr_in sa;
memcpy(&sa.sin_addr.s_addr, pHostent->h_addr_list[0], pHostent->h_length);
sprintf(ip,"%s", inet_ntoa(sa.sin_addr));
gethostname(hostname, sizeof hostname);
hostent* pHostent = gethostbyname(hostname);
sockaddr_in sa;
memcpy(&sa.sin_addr.s_addr, pHostent->h_addr_list[0], pHostent->h_length);
sprintf(ip,"%s", inet_ntoa(sa.sin_addr));