Mercurial > dovecot > core-2.2
comparison src/lib/network.c @ 1485:8c28289a15a1 HEAD
s/host/addr/ in a few network functions
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 18 May 2003 19:37:04 +0300 |
parents | 0d9f0e617a1a |
children | e291bf36d57f |
comparison
equal
deleted
inserted
replaced
1484:8b3e16678100 | 1485:8c28289a15a1 |
---|---|
497 if (port != NULL) *port = sin_get_port(&so); | 497 if (port != NULL) *port = sin_get_port(&so); |
498 | 498 |
499 return 0; | 499 return 0; |
500 } | 500 } |
501 | 501 |
502 const char *net_ip2host(const struct ip_addr *ip) | 502 const char *net_ip2addr(const struct ip_addr *ip) |
503 { | 503 { |
504 #ifdef HAVE_IPV6 | 504 #ifdef HAVE_IPV6 |
505 char host[MAX_IP_LEN+1]; | 505 char addr[MAX_IP_LEN+1]; |
506 | 506 |
507 host[MAX_IP_LEN] = '\0'; | 507 addr[MAX_IP_LEN] = '\0'; |
508 if (inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN) == NULL) | 508 if (inet_ntop(ip->family, &ip->ip, addr, MAX_IP_LEN) == NULL) |
509 return NULL; | 509 return NULL; |
510 | 510 |
511 return t_strdup(host); | 511 return t_strdup(addr); |
512 #else | 512 #else |
513 unsigned long ip4; | 513 unsigned long ip4; |
514 | 514 |
515 if (ip->family != AF_INET) | 515 if (ip->family != AF_INET) |
516 return NULL; | 516 return NULL; |
523 (ip4 & 0x000000ff)); | 523 (ip4 & 0x000000ff)); |
524 #endif | 524 #endif |
525 return 0; | 525 return 0; |
526 } | 526 } |
527 | 527 |
528 int net_host2ip(const char *host, struct ip_addr *ip) | 528 int net_addr2ip(const char *addr, struct ip_addr *ip) |
529 { | 529 { |
530 if (strchr(host, ':') != NULL) { | 530 if (strchr(addr, ':') != NULL) { |
531 /* IPv6 */ | 531 /* IPv6 */ |
532 ip->family = AF_INET6; | 532 ip->family = AF_INET6; |
533 #ifdef HAVE_IPV6 | 533 #ifdef HAVE_IPV6 |
534 if (inet_pton(AF_INET6, host, &ip->ip) == 0) | 534 if (inet_pton(AF_INET6, addr, &ip->ip) == 0) |
535 return -1; | 535 return -1; |
536 #else | 536 #else |
537 ip->ip.s_addr = 0; | 537 ip->ip.s_addr = 0; |
538 #endif | 538 #endif |
539 } else { | 539 } else { |
540 /* IPv4 */ | 540 /* IPv4 */ |
541 ip->family = AF_INET; | 541 ip->family = AF_INET; |
542 if (inet_aton(host, (struct in_addr *) &ip->ip) == 0) | 542 if (inet_aton(addr, (struct in_addr *) &ip->ip) == 0) |
543 return -1; | 543 return -1; |
544 } | 544 } |
545 | 545 |
546 return 0; | 546 return 0; |
547 } | 547 } |
605 | 605 |
606 entry = getservbyport(htons(port), "tcp"); | 606 entry = getservbyport(htons(port), "tcp"); |
607 return entry == NULL ? NULL : entry->s_name; | 607 return entry == NULL ? NULL : entry->s_name; |
608 } | 608 } |
609 | 609 |
610 int is_ipv4_address(const char *host) | 610 int is_ipv4_address(const char *addr) |
611 { | 611 { |
612 while (*host != '\0') { | 612 while (*addr != '\0') { |
613 if (*host != '.' && !i_isdigit(*host)) | 613 if (*addr != '.' && !i_isdigit(*addr)) |
614 return 0; | 614 return 0; |
615 host++; | 615 addr++; |
616 } | 616 } |
617 | 617 |
618 return 1; | 618 return 1; |
619 } | 619 } |
620 | 620 |
621 int is_ipv6_address(const char *host) | 621 int is_ipv6_address(const char *addr) |
622 { | 622 { |
623 while (*host != '\0') { | 623 while (*addr != '\0') { |
624 if (*host != ':' && !i_isxdigit(*host)) | 624 if (*addr != ':' && !i_isxdigit(*addr)) |
625 return 0; | 625 return 0; |
626 host++; | 626 addr++; |
627 } | 627 } |
628 | 628 |
629 return 1; | 629 return 1; |
630 } | 630 } |