Linux Netfilter discussions
 help / color / mirror / Atom feed
From: "David Busby" <busby@pnts.com>
To: System Administrator <sysadmin_lists@iwa-solutions.com>,
	netfilter@lists.netfilter.org
Subject: Re: Understanding Source ports
Date: Tue, 15 Jul 2003 14:57:17 -0700	[thread overview]
Message-ID: <004f01c34b1c$16d71df0$1100000a@busbydev> (raw)
In-Reply-To: 200307151256.56125.sysadmin_lists@iwa-solutions.com

Leon,
    How the source port on a machine is generated is dependent on the IP
stack.  Some boxes (Win32) I know use incremental (or almost incremental
(x+=2) source ports.  These are allocated by the IP stack when you call
connect().  However on almost every system that supports Berkley Sockets you
can call bind() to have the client socket use a specific IP and PORT
combination on the machine that is originating the connection.  So source
port comes from stack or program.  Source ports are (on *NIX) limited so
that only root can bind to ports <= 1024 (IIRC).

// PERL/Cish psudeocode
// Typical client connection
int sd = socket(PF_INET,SOCK_STREAM,getprotobyname("tcp"));
// Pretend *sin is a packed socket address
// This will make the OS determine my outbound IP and port
connect(sd,*sin,sizeof(*sin));
close(sd);
// Now Pick my port
sd = socket(PF_INET,SOCK_STREAM,getprotobyname("tcp"));
// Assume *lin is a packed local socket address (IP/PORT)
lin.addr = '10.0.0.1';
lin.port = '68';
bind(sd,*lin,sizeof(lin));

Also see
man 2 socket
man 5 protocols
man 3 getprotoent
man 2 connect
man 2 bind
If you have perl try `man 3 Socket`

/B


----- Original Message ----- 
From: "System Administrator" <sysadmin_lists@iwa-solutions.com>
To: <netfilter@lists.netfilter.org>
Sent: Tuesday, July 15, 2003 09:56
Subject: Understanding Source ports


I love my source of information -- Iptables logging feature.  I'm still
learning about but sure beats saying "I donno" to the boss.

It has brought a question i can't answer.  I guess I don't really understand
how packets orginate, in relation to the source port, on a system.  They
seem
to be somewhat random and very definately incremental.

Is there a good FAQ somewhere that I missed?

THNX
-- 
Leon Sonntag
Systems Administrator



      reply	other threads:[~2003-07-15 21:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-15 16:56 Understanding Source ports System Administrator
2003-07-15 21:57 ` David Busby [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='004f01c34b1c$16d71df0$1100000a@busbydev' \
    --to=busby@pnts.com \
    --cc=netfilter@lists.netfilter.org \
    --cc=sysadmin_lists@iwa-solutions.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox