Browse Source

Clean-up for code and Makefile : remove warnings in pedantic mode.

Frederic G. Marand 15 years ago
parent
commit
38c8227af9
2 changed files with 49 additions and 18 deletions
  1. 30 3
      Makefile
  2. 19 15
      netclient.c

+ 30 - 3
Makefile

@@ -1,6 +1,33 @@
+#
+# Makefile for OSInet TCP test client
+#
+# @version $Id: Makefile,v 1.2 2008-08-01 09:00:33 marand Exp $
+# @copyright (c) 2008 Ouest Systemes Informatiques (OSInet)
+#
+# All rights reserved
+#
 
-netclient: netclient.o
-	cc netclient.o -o netclient
+CC      = cc
+CFLAGS  = -W -Wall -Wstrict-prototypes -pedantic -ansi -D_GNU_SOURCE
+LDFLAGS =
+NAME    = netclient
+OBJ     = $(SRC:.c=.o)
+SRC     = netclient.c
+
+$(NAME) : $(OBJ)
+	@echo "Linking $(NAME) from $(OBJ)"
+	@$(CC) $(LDFLAGS) -o $(NAME) $(OBJ)
+
+all: $(NAME)
+
+.c.o :
+	@echo "Compiling $< $(CFLAGS)"
+	@$(CC) -c $(CFLAGS) $< -o $(<:.c=.o)
 
 clean:
-	rm -f *.o netclient
+	@echo "Cleaning $(OBJ)"
+	@rm -f $(OBJ)
+
+fclean: clean
+	@echo "Cleaning $(NAME)"
+	@rm -f $(NAME)

+ 19 - 15
netclient.c

@@ -1,27 +1,32 @@
 /**
- * Simple TCP connection check
- * (c) 1993-2008 OSI 
- *
- * Proprietary unpublished code
+ * Simple OSInet TCP test client
  *
  * WARNING: contains various assumptions regarding the use of IPv4
  * This is NOT production-quality code, just a quick debug test
+ *
+ * Sample values:
+ *	HOST	"profile.microscopy-analysis.com"
+ *	PORT	8080
+ * @version $Id: netclient.c,v 1.2 2008-08-01 09:00:33 marand Exp $
+ * @copyright (c) 2008 Ouest Systemes Informatiques (OSInet). All rights reserved
  */
+ 
+#include "features.h"
+#include "string.h"
+#include "stdlib.h"
+#include "unistd.h"
 #include "sys/socket.h"
 #include "netinet/in.h"
 #include "arpa/inet.h"
 #include "netdb.h"
 #include "stdio.h"
 
-//	HOST	"profile.microscopy-analysis.com"
-//	PORT	8080
-//
 #define MAX_BUF	100
 
 /**
  * Dump client socket info for IPv4
  */
-int showServ(struct sockaddr_in *sn)
+void showServ(struct sockaddr_in *sn)
   {
   printf("IP Dump\n");
   printf("  Family [%d]\n", sn->sin_family);
@@ -61,12 +66,11 @@ char *getServIp(char *name)
  */
 int main (int argc, char **argv)
   {
-  int					sockd;
-  int					count;
+  int			sockd;
   struct sockaddr_in	serv_name;
-  char					buf[MAX_BUF];
-  int					status;
-  char					*ip;
+  char			buf[MAX_BUF];
+  int			status;
+  char			*ip;
 
   if (argc != 3)
     {
@@ -74,7 +78,7 @@ int main (int argc, char **argv)
 	exit(1);
 	}
   strcpy(buf, argv[1]);
-  ip = getServIp(buf); // warning: static result, overwritten by each call
+  ip = getServIp(buf); /* warning: static result, overwritten by each call */
 
   sockd = socket(AF_INET, SOCK_STREAM, 0);
   if (sockd == -1)
@@ -84,7 +88,7 @@ int main (int argc, char **argv)
 	}
 
   serv_name.sin_family = AF_INET;
-  /* fprintf(stderr, "Inet_aton on %s returns %d\n", */ ip, inet_aton(ip, &serv_name.sin_addr); 
+  /* fprintf(stderr, "Inet_aton on %s returns %d\n", ip, */ inet_aton(ip, &serv_name.sin_addr); 
   serv_name.sin_port = htons(atoi(argv[2]));
 
   showServ(&serv_name);