OSSP CVS Repository

ossp - Difference in ossp-pkg/sa/sa_test.c versions 1.2 and 1.3
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/sa/sa_test.c 1.2 -> 1.3

--- sa_test.c    2001/10/04 11:04:59     1.2
+++ sa_test.c    2001/10/05 11:40:22     1.3
@@ -8,8 +8,6 @@
 
 #include "sa.h"
 
-/* see RFC3164 */
-
 static void die(char *fmt, ...)
 {
     va_list ap;
@@ -38,21 +36,32 @@
     char *cpHost;
     int n;
 
-    if (sa_u2a(&ra, "udp://%s:514", argv[1]) != SA_OK)
-        die("sa_u2a ra");
-    if (sa_u2a(&la, "udp://0.0.0.0:0") != SA_OK)
-        die("sa_u2a la");
+    /* create remote address */
+    if (sa_addr_create(&ra) != SA_OK)
+        die("sa_addr_create (ra)");
+    if (sa_addr_u2a(ra, "inet://141.1.129.1:514") != SA_OK)
+        die("sa_addr_u2a (ra)");
+
+    /* create local address */
+    if (sa_addr_create(&la) != SA_OK)
+        die("sa_addr_create (la)");
+    if (sa_addr_u2a(la, "inet://0.0.0.0:0") != SA_OK)
+        die("sa_addr_u2a (la)");
+
+    /* create datagram socket */
     if (sa_create(&sa) != SA_OK)
         die("sa_create");
+    if (sa_type(sa, SA_TYPE_DATAGRAM) != SA_OK)
+        die("sa_type");
+
+    /* bind socket to local address */
     if (sa_bind(sa, la) != SA_OK)
         die("sa_bind");
 
     /* RFC3164: The BSD syslog Protocol; C. Lonvick; August 2001. */
-
     now = time(NULL);
     tm = localtime(&now);
     strftime(caTime, sizeof(caTime), "%b %e %H:%M:%S", tm);
-
     if (uname(&uts) == 0) {
         cpHost = strdup(uts.nodename);
         if ((cp = strchr(cpHost, '.')) != NULL)
@@ -60,20 +69,23 @@
     }
     else
         cpHost = strdup("0.0.0.0"); /* FIXME */
-
     strcpy(caTag, "progname[12]: ");
     if (strlen(caTag) > 32)
         caTag[32] = '\0';
-
-    sprintf(caBuf, "<%d>%s %s %s%s", LOG_MAIL|LOG_EMERG, caTime, cpHost, caTag, argv[2]);
+    sprintf(caBuf, "<%d>%s %s %s%s", LOG_MAIL|LOG_EMERG, caTime, cpHost, caTag, "test");
     fprintf(stderr, "%s\n", caBuf);
     nBuf = strlen(caBuf);
     if (sa_writeto(sa, caBuf, nBuf, (size_t *)&n, ra) != SA_OK)
         die("sa_writeto");
+
+    /* destroy socket and address objects */
     if (sa_destroy(sa) != SA_OK)
         die("sa_destroy");
-    free(ra);
-    free(la);
+    if (sa_addr_destroy(la) != SA_OK)
+        die("sa_addr_destroy (la)");
+    if (sa_addr_destroy(ra) != SA_OK)
+        die("sa_addr_destroy (ra)");
+
     return 0;
 }
 

CVSTrac 2.0.1