Qt 域名转成IP

#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <arpa/inet.h>
struct
hostent *h; QByteArray ba = ui->lineEdit->text().toLatin1(); h = gethostbyname(ba.data()); if(h == NULL) { qDebug()<<"get hostbyname error!"; exit(1); } struct in_addr *in=(in_addr *)h->h_addr; char *ch = inet_ntoa(*in); QString str = QString(QLatin1String(ch)); qDebug()<<"IP Address:"<<str; ui->lineEdit_2->setText(str);

 

posted @ 2014-04-07 22:42  wiessharling  阅读(1132)  评论(0编辑  收藏  举报