OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp.c versions 1.37 and 1.38
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.37 -> 1.38

--- lmtp2nntp.c  2001/08/30 11:53:25     1.37
+++ lmtp2nntp.c  2001/09/03 15:06:29     1.38
@@ -97,6 +97,9 @@
     char           *option_deliverymodefakedsn;
     int             option_maxmessagesize;
     int             option_waittime;
+    char           *cpBindh;
+    char           *cpBindp;
+    sa_t           *saBind;
     int             nsc;
     struct ns       ns[MAXNEWSSERVICES];
     char           *azGroupargs;
@@ -176,6 +179,9 @@
     ctx->option_deliverymodefakedsn    = "5.7.1"; /* Delivery not authorized, message refused */
     ctx->option_maxmessagesize = 8 * 1024 * 1024;
     ctx->option_waittime = -1;
+    ctx->cpBindh = NULL;
+    ctx->cpBindp = NULL;
+    ctx->saBind = NULL;
     ctx->nsc = 0;
     for (i=0; i < MAXNEWSSERVICES; i++) {
         ctx->ns[i].h = NULL;
@@ -194,7 +200,7 @@
         exit(ERR_EXECUTION);
     }
 
-#if 1
+#if 0
     {
         char buf[1000];
         int bufused = 0;
@@ -217,12 +223,43 @@
      */
 
     /* read in the arguments */
-    while ((i = getopt(argc, argv, "Vd:g:h:m:n:t:vw:")) != -1) {
+    while ((i = getopt(argc, argv, "Vb:d:g:h:m:n:t:vw:")) != -1) {
         switch (i) {
             case 'V': /*POD [B<-V>] (version)*/
                 fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu);
                 exit(0);
                 break;
+            case 'b': /*POD [B<-b> I<bindaddr>[I<:port>] */
+                /* parse host[:port] string into host and port */
+                ctx->cpBindh = strdup(optarg);
+                if ((ctx->cpBindp = strrchr(ctx->cpBindh, ':')) != NULL) {
+                    *ctx->cpBindp++ = NUL;
+                    ctx->cpBindp = strdup(ctx->cpBindp);
+                }
+                else 
+                    ctx->cpBindp = strdup("0");
+
+                fprintf(stderr, "DEBUG: creating TCP socket address for \"%s:%s\"\n", ctx->cpBindh, ctx->cpBindp);
+                if ((ctx->saBind = sa_create(SA_IP, "tcp", ctx->cpBindh, ctx->cpBindp)) == NULL) {
+                    fprintf(stderr, "%s:Error: creating TCP socket address failed for \"%s:%s\": %s\n", 
+                            progname, 
+                            ctx->cpBindh, 
+                            ctx->cpBindp, 
+                            strerror(errno));
+                    exit(ERR_EXECUTION);
+                }
+                fprintf(stderr, "DEBUG: saBind->sa_len=%d\n",
+                ctx->saBind->sa_buf->sa_len);
+                fprintf(stderr, "DEBUG: saBind->sa_family=%d\n", (int)ctx->saBind->sa_buf->sa_family);
+                for (i=0; i<14; i++)
+                fprintf(stderr, "DEBUG: saBind->sa_data[%2d]=%2x %d\n", i,
+                (unsigned int)(unsigned char)ctx->saBind->sa_buf->sa_data[i],
+                (unsigned int)(unsigned char)ctx->saBind->sa_buf->sa_data[i]);
+                ctx->saBind->sa_buf->sa_data[ 7]='0'; //DEBUG
+                ctx->saBind->sa_buf->sa_data[ 8]='0'; //DEBUG
+                ctx->saBind->sa_buf->sa_data[ 9]='0'; //DEBUG
+                ctx->saBind->sa_buf->sa_data[10]='0'; //DEBUG
+                break;
             case 'd': /*POD [B<-d> I<deliverymode>] */
                 if      (strcasecmp(optarg, "post") == 0)
                     ctx->option_deliverymode = DELIVERYMODE_POST;
@@ -553,6 +590,11 @@
     i = 0;
     do {
         bOk = TRUE;
+        if (bOk && (ctx->saBind != NULL) &&
+                   bind(ctx->ns[i].s, ctx->saBind->sa_buf, ctx->saBind->sa_len) < 0) {
+            bOk = FALSE;
+            fprintf(stderr, "DEBUG: errno=%d\n", errno);
+        }
         if (ctx->option_waittime > 0) {
             if (connect_nonb(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len, 
                          ctx->option_waittime) < 0) {
@@ -631,6 +673,10 @@
         if (ctx->ns[i].h != NULL)
             free(ctx->ns[i].h);
     }
+    if (ctx->cpBindh != NULL)
+        free(ctx->cpBindh);
+    if (ctx->cpBindp != NULL)
+        free(ctx->cpBindp);
 }
 
 static int helo_rfc0821domain(char *msg, char **domain)

CVSTrac 2.0.1