方法1,、最可靠的方法:
if (inet_aton(bgpd_host,&(addr.sin_addr)) == 0)
{ //printf("ERROR:Can‘t set dest host address!\n"); //return -1; host = gethostbyname(bgpd_host); if (host == NULL); { ip_addr = inet_addr(bgpd_host); host = gethostbyaddr((char *)&ip_addr, 4, PF_INET); if (host == NULL) { //herror("gethostbyaddr"); fprintf(stderr, "HostName Error: %s\n\a",hstrerror(h_errno)); return -1; } } addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]); } 方法2、對于直接給出IP的情況,可以調(diào)用addr.sin_addr.s_addr = inet_addr(bgpd_host);
|
|