Skip to content
Browse files

Minor fixes. Print default port in usage.

  • Loading branch information...
1 parent d841527 commit 1de7791204cc688803486cf3b1d5c2f46fdc5d2c gammy committed Apr 10, 2012
Showing with 13 additions and 14 deletions.
  1. +6 −10 main.c
  2. +7 −4 net.c
View
16 main.c
@@ -24,27 +24,26 @@
void usage(char *me) {
printf("Cheaptalk v%s by gammy\n"
- "Usage: %s [options]\n"
+ "Usage: %s [options]\n\n"
"To wait for a friend : %s --listen\n"
- "To connect to a friend: %s --connect <friends hostname>\n\n"
+ "To connect to a friend: %s --connect <address>\n\n"
"-l --listen Wait for someone to connect to you\n"
"-c --connect <host> Connect to <host>\n"
- "-p --port <port> Listen or connect using port <port>\n"
+ "-p --port <port> Listen or connect using port <port> (default %s)\n"
"-h --help This help\n"
"-V --version Display version\n\n"
"This is free software; see the source for copying conditions. "
"There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS "
"FOR A PARTICULAR PURPOSE.\n\n",
VERSION,
- me, me, me);
+ me, me, me, DEFAULT_PORT);
}
void signal_handle(int sig) {
endwin();
fprintf(stderr, "Caught signal %d\n", sig);
- busy = 0;
- //net_finish();
- //exit(EXIT_SUCCESS);
+ net_finish();
+ exit(EXIT_SUCCESS);
}
void signal_install(void) {
@@ -188,8 +187,5 @@ int main(int argc, char *argv[]){
net_finish();
endwin();
- if(busy == 2)
- printf("Other side closed the connection\n");
-
return(EXIT_SUCCESS);
}
View
11 net.c
@@ -40,7 +40,7 @@ unsigned int net_listen(char *port) {
// Get addresses which we can bind to
if((rv = getaddrinfo(NULL, port, &hints, &servinfo)) != 0) {
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
+ fprintf(stderr, "Error: getaddrinfo: %s\n", gai_strerror(rv));
return(0);
}
@@ -134,13 +134,16 @@ unsigned int net_connect(char *host, char *port) {
while(1) {
+ net_sock_client = -1;
+
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if((net_sock_client = socket(p->ai_family,
- p->ai_socktype,
- p->ai_protocol)) == -1) {
+ p->ai_socktype,
+ p->ai_protocol)) == -1) {
fprintf(stderr, "Error: socket: %s\n", strerror(errno));
+ sleep(2);
continue;
}
@@ -153,6 +156,7 @@ unsigned int net_connect(char *host, char *port) {
close(net_sock_client);
fprintf(stderr, "%s\n", strerror(errno));
+ sleep(2);
continue;
}
@@ -162,7 +166,6 @@ unsigned int net_connect(char *host, char *port) {
if(p)
break;
- sleep(2);
}
inet_ntop(p->ai_family,

0 comments on commit 1de7791

Please sign in to comment.
Something went wrong with that request. Please try again.