comparison src/core/ngx_inet.c @ 3267:fb4f7605505f

replace inet_addr() with ngx_inet_addr()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Nov 2009 13:51:10 +0000
parents 798141791ad3
children c6a40c815d45
comparison
equal deleted inserted replaced
3266:798141791ad3 3267:fb4f7605505f
641 641
642 if (u->no_resolve) { 642 if (u->no_resolve) {
643 return NGX_OK; 643 return NGX_OK;
644 } 644 }
645 645
646 if (len++) { 646 if (len) {
647 647 sin->sin_addr.s_addr = ngx_inet_addr(host, len);
648 p = ngx_alloc(len, pool->log);
649 if (p == NULL) {
650 return NGX_ERROR;
651 }
652
653 (void) ngx_cpystrn(p, host, len);
654
655 sin->sin_addr.s_addr = inet_addr((const char *) p);
656 648
657 if (sin->sin_addr.s_addr == INADDR_NONE) { 649 if (sin->sin_addr.s_addr == INADDR_NONE) {
650 p = ngx_alloc(++len, pool->log);
651 if (p == NULL) {
652 return NGX_ERROR;
653 }
654
655 (void) ngx_cpystrn(p, host, len);
656
658 h = gethostbyname((const char *) p); 657 h = gethostbyname((const char *) p);
658
659 ngx_free(p);
659 660
660 if (h == NULL || h->h_addr_list[0] == NULL) { 661 if (h == NULL || h->h_addr_list[0] == NULL) {
661 ngx_free(p); 662 ngx_free(p);
662 u->err = "host not found"; 663 u->err = "host not found";
663 return NGX_ERROR; 664 return NGX_ERROR;
667 } 668 }
668 669
669 if (sin->sin_addr.s_addr == INADDR_ANY) { 670 if (sin->sin_addr.s_addr == INADDR_ANY) {
670 u->wildcard = 1; 671 u->wildcard = 1;
671 } 672 }
672
673 ngx_free(p);
674 673
675 } else { 674 } else {
676 sin->sin_addr.s_addr = INADDR_ANY; 675 sin->sin_addr.s_addr = INADDR_ANY;
677 u->wildcard = 1; 676 u->wildcard = 1;
678 } 677 }
813 in_addr_t in_addr; 812 in_addr_t in_addr;
814 ngx_uint_t i; 813 ngx_uint_t i;
815 struct hostent *h; 814 struct hostent *h;
816 struct sockaddr_in *sin; 815 struct sockaddr_in *sin;
817 816
818 host = ngx_alloc(u->host.len + 1, pool->log);
819 if (host == NULL) {
820 return NGX_ERROR;
821 }
822
823 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
824
825 /* AF_INET only */ 817 /* AF_INET only */
826 818
827 port = htons(u->port); 819 port = htons(u->port);
828 820
829 in_addr = inet_addr((char *) host); 821 in_addr = ngx_inet_addr(u->host.data, u->host.len);
830 822
831 if (in_addr == INADDR_NONE) { 823 if (in_addr == INADDR_NONE) {
824 host = ngx_alloc(u->host.len + 1, pool->log);
825 if (host == NULL) {
826 return NGX_ERROR;
827 }
828
829 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
830
832 h = gethostbyname((char *) host); 831 h = gethostbyname((char *) host);
833 832
834 ngx_free(host); 833 ngx_free(host);
835 834
836 if (h == NULL || h->h_addr_list[0] == NULL) { 835 if (h == NULL || h->h_addr_list[0] == NULL) {
881 u->addrs[i].name.data = p; 880 u->addrs[i].name.data = p;
882 } 881 }
883 882
884 } else { 883 } else {
885 884
886 ngx_free(host);
887
888 /* MP: ngx_shared_palloc() */ 885 /* MP: ngx_shared_palloc() */
889 886
890 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t)); 887 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
891 if (u->addrs == NULL) { 888 if (u->addrs == NULL) {
892 return NGX_ERROR; 889 return NGX_ERROR;