sfmike for unix manual source IP:port setting

Thomas Shaddack <[email protected]>
Newsgroups gmane.comp.audio.speak-freely.general
Message-ID <Pine.LNX.4.33.0309050335400.16799-100000@Zeta>
Recalling an earlier debate about NAT and firewalls here, I decided to
play around a bit. Took the SpeakFreely mike.c source code I played with
earlier, and added the possibility to manually specify what IP address the
sending socket should bind to (useful in case of machine with several IPs)
and what port to use for packet sending. Together with some other
utilities (eg. a program that would send UDP packets with preset
source:destination from and to clients behind NAT, setting up NAT to allow
packet forwarding).

The code became part of my sfParanoidPatch,
<http://217.11.227.71/patches/speakfreely/>.

The majority of the users are doomed to do Windows, for which I don't
wrote code (at least not yet). I sorrow I can't help directly there, but
the code should be quite similar. Someone more skilled with that platform
may like to take a look and implement it there.



The relevant part of the code is nearby the very end of the source.
The parts that aren't shown just declare the unsigned int source_port and
char*source_addr and set their values (default 0 and NULL) from the
commandline parameter (I chose -SP[IP:]port). Refer to sfParanoidPatch or
ask me for details.
The code itself follows, my part marked by the comments.


		if (robust > 1) {
                    fprintf(stderr, "Robust (-ROBUSTn) transmission cannot be used with -RTP or -VAT protocols.\n");
		    return 2;
		}
		if (ring) {
                    fprintf(stderr, "Warning: ring not implemented in -RTP and -VAT protocols.\n");
		}
	    }

            /* Shad's mod begin */
            if(source_port)
            { static struct sockaddr_in name;       /* Address of destination host */
              name.sin_family = AF_INET;
	      if(source_addr)name.sin_addr.s_addr = inet_addr(source_addr);
                        else name.sin_addr.s_addr = INADDR_ANY;
              name.sin_port = htons(source_port);
              if(bind(sock, (struct sockaddr *) &name, sizeof name))
	       {if(!source_addr)fprintf(stderr, "ERROR: Can't bind to UDP port %u.\n",source_port);
	        else fprintf(stderr, "ERROR: Can't bind to UDP IP:port %s:%u.\n",source_addr,source_port);
	        return 1;
	       }
            }
            /* Shad's mod end */
	    if (dests == NULL) {
		if (!addest(op)) {
		    return 1;
		}
	    } else {
		int ok = sendfile(op);
		if (ok != 0)
		    return ok;
		sentfile++;
	    }


                      * * *

To unsubscribe from this mailing list, send E-mail containing
the word "unsubscribe" in the message body (*not* as the
Subject) to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.