OSSP CVS Repository

ossp - Check-in [877]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 877
Date: 2001-Sep-06 18:28:38 (local)
2001-Sep-06 16:28:38 (UTC)
User:rse
Branch:
Comment: Add a copy of our SA library to L2 in order to simplify socket channel and socket monitor program.
Tickets:
Inspections:
Files:
ossp-pkg/l2/Makefile.in      1.16 -> 1.17     2 inserted, 1 deleted
ossp-pkg/l2/configure.ac      1.2 -> 1.3     1 inserted, 0 deleted
ossp-pkg/l2/l2_p.h      1.11 -> 1.12     1 inserted, 0 deleted
ossp-pkg/l2/l2_ut_sa.c      added-> 1.1
ossp-pkg/l2/l2_ut_sa.h      added-> 1.1

ossp-pkg/l2/Makefile.in 1.16 -> 1.17

--- Makefile.in  2001/09/06 11:56:15     1.16
+++ Makefile.in  2001/09/06 16:28:38     1.17
@@ -78,7 +78,8 @@
     l2_ut_param.lo \
     l2_ut_pcre.lo \
     l2_ut_level.lo \
-    l2_ut_fmtcb.lo
+    l2_ut_fmtcb.lo \
+    l2_ut_sa.lo
 
 #   file containing the official version information
 _VERSION_FILE = \


ossp-pkg/l2/configure.ac 1.2 -> 1.3

--- configure.ac 2001/08/15 10:36:03     1.2
+++ configure.ac 2001/09/06 16:28:38     1.3
@@ -75,6 +75,7 @@
 AC_PROG_CPP
 AC_CHECK_DEBUGGING
 AC_CONFIGURE_LIBTOOL
+AC_CHECK_FUNCS(inet_aton inet_pton)
 
 AC_OUTPUT(dnl
 Makefile dnl


ossp-pkg/l2/l2_p.h 1.11 -> 1.12

--- l2_p.h       2001/09/04 14:52:28     1.11
+++ l2_p.h       2001/09/06 16:28:38     1.12
@@ -34,6 +34,7 @@
 #include <errno.h>
 
 #include "l2_ut_pcre.h"
+#include "l2_ut_sa.h"
 
 #define L2_MAX_MSGSIZE    4096
 #define L2_MAX_CHANNELS    128


ossp-pkg/l2/l2_ut_sa.c -> 1.1

*** /dev/null    Thu Oct 21 07:11:00 2021
--- -    Thu Oct 21 07:13:24 2021
***************
*** 0 ****
--- 1,212 ----
+ /*
+ **  L2 - OSSP Logging Library
+ **  Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  This file is part of OSSP L2, a flexible logging library which
+ **  can be found at http://www.ossp.org/pkg/l2/.
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ **  SUCH DAMAGE.
+ **
+ **  l2_ut_sa.c: utility library for socket address handling
+ */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <ctype.h>
+ #include <errno.h>
+ #include <netdb.h>
+ #include <sys/types.h>
+ #include <sys/un.h>
+ #include <netinet/in.h>
+ #include <sys/socket.h>
+ #include <arpa/inet.h>
+ 
+ #include "l2_config.h"
+ #include "l2_ut_sa.h"
+ 
+ #if !defined(AF_LOCAL) && defined(AF_UNIX)
+ #define AF_LOCAL AF_UNIX
+ #endif
+ 
+ #ifndef HAVE_INET_PTON
+ #ifdef HAVE_INET_ATON
+ static int inet_pton(int family, const char *strptr, void *addrptr)
+ {
+     struct in_addr in_val;
+ 
+     if (family == AF_INET) {
+         if (inet_aton(strptr, &in_val)) {
+             memcpy(addrptr, &in_val, sizeof(struct in_addr));
+             return 1;
+         }
+         return 0;
+     }
+     errno = EAFNOSUPPORT;
+     return -1;
+ }
+ #else
+ #error "neither inet_pton nor inet_aton available"
+ #endif
+ #endif
+ 
+ #ifndef NUL
+ #define NUL '\0'
+ #endif
+ 
+ l2_util_sa_t *l2_util_sa_create(int sa_type, ...)
+ {
+     va_list ap;
+     l2_util_sa_t *rc;
+     int nPort;
+     socklen_t sl;
+     struct sockaddr *sa;
+     struct sockaddr_in sa4;
+ #ifdef AF_INET6
+     struct sockaddr_in6 sa6;
+ #endif
+     struct sockaddr_un sau;
+     struct hostent *he;
+     struct servent *se;
+     struct protoent *pe;
+     int bNumeric;
+     int i;
+     char *cpPath;
+     int   nPath;
+     char *cpProto;
+     int   nProto;
+     char *cpHost;
+     char *cpPort;
+ 
+     va_start(ap, sa_type);
+     sa = NULL;
+     sl = 0;
+     if (sa_type == SA_UNIX) {
+ #if defined(AF_LOCAL)
+         if ((cpPath = va_arg(ap, char *)) == NULL)
+             return NULL;
+         if ((nPath = strlen(cpPath)) >= (sizeof(sau.sun_path)-1))
+             return NULL;
+         nProto = 0;
+         sau.sun_family = AF_LOCAL;
+         memcpy(sau.sun_path, cpPath, nPath + 1);
+         sa = (struct sockaddr *)&sau;
+         sl = sizeof(sau);
+ #else
+         return NULL;
+ #endif
+     }
+     else if (sa_type == SA_IP) {
+         if ((cpProto = va_arg(ap, char *)) == NULL)
+             return NULL;
+         if ((cpHost = va_arg(ap, char *)) == NULL)
+             return NULL;
+         if ((cpPort = va_arg(ap, char *)) == NULL)
+             return NULL;
+ 
+         /* resolve protocol */
+         if ((pe = getprotobyname(cpProto)) == NULL)
+             return NULL;
+         nProto = pe->p_proto;
+ 
+         /* resolve port */
+         bNumeric = 1;
+         for (i = 0; cpPort[i] != NUL; i++) {
+             if (!isdigit((int)cpPort[i])) {
+                 bNumeric = 0;
+                 break;
+             }
+         }
+         if (bNumeric)
+             nPort = atoi(cpPort);
+         else {
+             if ((se = getservbyname(cpPort, cpProto)) == NULL)
+                 return NULL;
+             nPort = ntohs(se->s_port);
+         }
+ 
+         /* resolve host */
+         if (inet_pton(AF_INET, cpHost, &sa4.sin_addr.s_addr) == 1) {
+             sa4.sin_family = AF_INET;
+             sa4.sin_port = htons(nPort);
+             sa = (struct sockaddr *)&sa4;
+             sl = sizeof(sa4);
+         }
+ #ifdef AF_INET6
+         else if (inet_pton(AF_INET6, cpHost, &sa6.sin6_addr.s6_addr) == 1) {
+             sa6.sin6_family = AF_INET6;
+             sa6.sin6_port = htons(nPort);
+             sa = (struct sockaddr *)&sa6;
+             sl = sizeof(sa6);
+         }
+ #endif
+         else if ((he = gethostbyname(cpHost)) != NULL) {
+             if (he->h_addrtype == AF_INET) {
+                 sa4.sin_family = AF_INET;
+                 sa4.sin_port = htons(nPort);
+                 memcpy(&sa4.sin_addr.s_addr, he->h_addr_list[0], sizeof(sa4.sin_addr.s_addr));
+                 sa = (struct sockaddr *)&sa4;
+                 sl = sizeof(sa4);
+             }
+ #ifdef AF_INET6
+             else if (he->h_addrtype == AF_INET6) {
+                 sa6.sin6_family = AF_INET6;
+                 sa6.sin6_port = htons(nPort);
+                 memcpy(&sa6.sin6_addr.s6_addr, he->h_addr_list[0], sizeof(sa6.sin6_addr.s6_addr));
+                 sa = (struct sockaddr *)&sa6;
+                 sl = sizeof(sa6);
+             }
+ #endif
+         }
+     }
+     else
+         return NULL;
+     va_end(ap);
+ 
+     if (sa == NULL)
+         return NULL;
+         
+     if ((rc = (l2_util_sa_t *)malloc(sizeof(l2_util_sa_t))) == NULL)
+         return NULL;
+     if ((rc->sa_buf = (struct sockaddr *)malloc(sl)) == NULL) {
+         free(rc);
+         return NULL;
+     }
+     memcpy(rc->sa_buf, sa, sl);
+     rc->sa_len = sl;
+     rc->sa_proto = nProto;
+ 
+     return rc;
+ }
+ 
+ void l2_ut_sa_destroy(l2_util_sa_t *sa)
+ {
+     if (sa == NULL)
+         return;
+ 
+     if (sa->sa_buf != NULL)
+         free(sa->sa_buf);
+     free(sa);
+ 
+     return;
+ }
+ 


ossp-pkg/l2/l2_ut_sa.h -> 1.1

*** /dev/null    Thu Oct 21 07:11:00 2021
--- -    Thu Oct 21 07:13:24 2021
***************
*** 0 ****
--- 1,54 ----
+ /*
+ **  L2 - OSSP Logging Library
+ **  Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  This file is part of OSSP L2, a flexible logging library which
+ **  can be found at http://www.ossp.org/pkg/l2/.
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ **  SUCH DAMAGE.
+ **
+ **  l2_ut_sa.h: utility library for socket address handling
+ */
+ 
+ #ifndef __L2_UT_SA_H__
+ #define __L2_UT_SA_H__
+ 
+ #include <netdb.h>
+ #include <sys/types.h>
+ #include <netinet/in.h>
+ #include <sys/socket.h>
+ #include <arpa/inet.h>
+ 
+ typedef struct {
+     struct sockaddr *sa_buf;
+     socklen_t        sa_len;
+     int              sa_proto;
+ } l2_util_sa_t;
+ 
+ enum {
+     SA_UNIX,
+     SA_IP
+ };
+ 
+ l2_util_sa_t *l2_util_sa_create(int, ...);
+ void          l2_util_sa_destroy(l2_util_sa_t *);
+ 
+ #endif /* __L2_UT_SA_H__ */
+ 

CVSTrac 2.0.1