comparison libmpdemux/network.c @ 7513:cd2b939b2dfb

Display the IP address that has been resolved.
author bertrand
date Fri, 27 Sep 2002 19:20:20 +0000
parents 52b29760fe95
children 013c255225d8
comparison
equal deleted inserted replaced
7512:0df2e3079aa4 7513:cd2b939b2dfb
147 int err, err_len; 147 int err, err_len;
148 int ret,count = 0; 148 int ret,count = 0;
149 fd_set set; 149 fd_set set;
150 struct timeval tv; 150 struct timeval tv;
151 struct sockaddr_in server_address; 151 struct sockaddr_in server_address;
152 152 struct hostent *hp;
153 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s:%d ...\n", host, port );
154 153
155 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0); 154 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
156 if( socket_server_fd==-1 ) { 155 if( socket_server_fd==-1 ) {
157 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket\n"); 156 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket\n");
158 return -2; 157 return -2;
159 } 158 }
160 159
161 if( isalpha(host[0]) ) { 160 if( isalpha(host[0]) ) {
162 struct hostent *hp; 161 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Resolving %s ...\n", host );
163 hp=(struct hostent*)gethostbyname( host ); 162 hp=(struct hostent*)gethostbyname( host );
164 if( hp==NULL ) { 163 if( hp==NULL ) {
165 mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", host); 164 mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", host);
166 return -2; 165 return -2;
167 } 166 }
171 } 170 }
172 server_address.sin_family=AF_INET; 171 server_address.sin_family=AF_INET;
173 server_address.sin_port=htons(port); 172 server_address.sin_port=htons(port);
174 173
175 // Turn the socket as non blocking so we can timeout on the connection 174 // Turn the socket as non blocking so we can timeout on the connection
175 if( isalpha(host[0]) ) {
176 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s[%d.%d.%d.%d]:%d ...\n", host, (hp->h_addr_list[0][0])&0xff, (hp->h_addr_list[0][1])&0xff, (hp->h_addr_list[0][2])&0xff, (hp->h_addr_list[0][3])&0xff, port );
177 } else {
178 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s:%d ...\n", host, port );
179 }
176 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK ); 180 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
177 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) { 181 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
178 if( errno!=EINPROGRESS ) { 182 if( errno!=EINPROGRESS ) {
179 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n"); 183 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n");
180 close(socket_server_fd); 184 close(socket_server_fd);