| version 1.3, 2002/10/02 20:13:58 |
version 1.4, 2003/11/20 11:55:16 |
| Line 19 int net_connection_connect(const char*ho |
|
| Line 19 int net_connection_connect(const char*ho |
|
| struct hostent*he; |
struct hostent*he; |
| |
|
| he=gethostbyname(host); |
he=gethostbyname(host); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"net_connection_connect()\n"); |
fprintf(stderr,"net_connection_connect()\n"); |
| if(he==NULL) |
if(he==NULL) |
| fprintf(stderr," ERROR: Unknown host. [%s]\n",host); |
fprintf(stderr," ERROR: Unknown host. [%s]\n",host); |
| Line 29 int net_connection_connect(const char*ho |
|
| Line 29 int net_connection_connect(const char*ho |
|
| if(he==NULL)return(-1); |
if(he==NULL)return(-1); |
| |
|
| if(port<=0){ |
if(port<=0){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," WARNING: Bad port (%d) changed to default (%d).\n", |
fprintf(stderr," WARNING: Bad port (%d) changed to default (%d).\n", |
| port, NET_CONNECTION_PORT); |
port, NET_CONNECTION_PORT); |
| #endif |
#endif |
| Line 40 int net_connection_connect(const char*ho |
|
| Line 40 int net_connection_connect(const char*ho |
|
| sin.sin_addr.s_addr=*((unsigned int*)he->h_addr); |
sin.sin_addr.s_addr=*((unsigned int*)he->h_addr); |
| sin.sin_port=htons(port); |
sin.sin_port=htons(port); |
| sock=socket(PF_INET,SOCK_STREAM,0); |
sock=socket(PF_INET,SOCK_STREAM,0); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| if(sock==-1) |
if(sock==-1) |
| fprintf(stderr," ERROR: Can't create socket.\n"); |
fprintf(stderr," ERROR: Can't create socket.\n"); |
| else |
else |
| Line 48 int net_connection_connect(const char*ho |
|
| Line 48 int net_connection_connect(const char*ho |
|
| #endif |
#endif |
| if(sock==-1)return(-1); |
if(sock==-1)return(-1); |
| |
|
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," STATUS: Trying to connect...\n"); |
fprintf(stderr," STATUS: Trying to connect...\n"); |
| #endif |
#endif |
| if(connect(sock,(struct sockaddr*)&sin,sizeof(struct sockaddr_in))==-1){ |
if(connect(sock,(struct sockaddr*)&sin,sizeof(struct sockaddr_in))==-1){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," ERROR: Cannot connect.\n"); |
fprintf(stderr," ERROR: Cannot connect.\n"); |
| #endif |
#endif |
| return(-1); |
return(-1); |
| } |
} |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," OK: Connection estabilished.\n"); |
fprintf(stderr," OK: Connection estabilished.\n"); |
| #endif |
#endif |
| return(sock); |
return(sock); |