From owner-p4-projects@FreeBSD.ORG Tue Jun 22 06:34:43 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2B23F1065675; Tue, 22 Jun 2010 06:34:42 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9499A106564A for ; Tue, 22 Jun 2010 06:34:42 +0000 (UTC) (envelope-from ligregni@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 78D258FC18 for ; Tue, 22 Jun 2010 06:34:42 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o5M6Ygk0060369 for ; Tue, 22 Jun 2010 06:34:42 GMT (envelope-from ligregni@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o5M6Ygts060367 for perforce@freebsd.org; Tue, 22 Jun 2010 06:34:42 GMT (envelope-from ligregni@FreeBSD.org) Date: Tue, 22 Jun 2010 06:34:42 GMT Message-Id: <201006220634.o5M6Ygts060367@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ligregni@FreeBSD.org using -f From: Sergio Ligregni To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 180091 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jun 2010 06:34:43 -0000 http://p4web.freebsd.org/@@180091?ac=10 Change 180091 by ligregni@ligPhenom on 2010/06/22 06:34:14 Client socket connection done, ready to start master daemon (mainly to test the shipd daemon). Affected files ... .. //depot/projects/soc2010/disaudit/damasterd.c#1 add .. //depot/projects/soc2010/disaudit/damasterd.h#1 add .. //depot/projects/soc2010/disaudit/msocket_work.c#1 add .. //depot/projects/soc2010/disaudit/msocket_work.h#1 add .. //depot/projects/soc2010/disaudit/ssocket_work.c#2 edit .. //depot/projects/soc2010/disaudit/ssocket_work.h#2 edit Differences ... ==== //depot/projects/soc2010/disaudit/ssocket_work.c#2 (text+ko) ==== @@ -25,8 +25,102 @@ * */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + int do_socket_check_file(char *host, int port, char *path, char *fullpath, char *md5) { + int sockfd; + + if (init_socket(host, port, &sockfd) == -1) + return -1; + return -1; } + +int +is_ipv4(char *address) +{ + int points=0, last_point=0, i, len=strlen(address); + + /* Here we will check if the string is a valid IPv4 address */ + + for(i=0; i last_point+1) /* Counting the points and making sure there are no two consecutive points */ + { + last_point = i; + ++points; + } + else if (!isdigit(address[i])) + break; + + if (points == 3 && i == len) + return 1; + return 0; +} + +int +init_socket(char *host, int port, int *sfd) +{ + struct sockaddr_in sockaddr; + struct in_addr inaddr; + struct hostent *hostentry = NULL; + char message[256]; + int sockfd, res; + char ipv4[16]; + + if (!is_ipv4(host)) + { + hostentry = gethostbyname(host); + if (!hostentry) + { + to_log("Error gettig the host"); + return -1; + } + + sprintf(message, "Got for the host: %s the IPv4 address: %s", host, inet_ntoa(*((struct in_addr *)hostentry->h_addr))); + to_log(message); + } + + sockfd = socket(PF_INET, SOCK_STREAM, 0); + + if (sockfd == -1) + { + to_log("Cannot create socket!"); + return -1; + } + + bzero(&sockaddr, sizeof(sockaddr)); + + sockaddr.sin_family = AF_INET; + sockaddr.sin_addr.s_addr = hostentry != NULL ? ((struct in_addr *) hostentry->h_addr)->s_addr : inet_addr(host); + sockaddr.sin_port = htons(port); + + res = connect(sockfd, (struct sockaddr *) &sockaddr, sizeof(sockaddr)); + + if (res < 0) + { + to_log("Can't connect to server!"); + return -1; + } + + sprintf(message, "Successfully connected to: %s", hostentry != NULL ? inet_ntoa(*((struct in_addr *) hostentry->h_addr)) : host); + to_log(message); + + *sfd = sockfd; + return 0; +} + ==== //depot/projects/soc2010/disaudit/ssocket_work.h#2 (text+ko) ==== @@ -29,5 +29,6 @@ #define _SSOCKET_WORK_H_ int do_socket_check_file(char *, int, char *, char *, char *); +int init_socket(char *, int, int *); #endif