Comcast and mail header errors?
Ben Scott
dragonhawk at gmail.com
Thu Mar 23 11:06:01 EST 2006
On 3/23/06, Cole Tuininga <colet at code-energy.com> wrote:
>> "man bind(2)"
>
> Right - this is for *listening* sockets.
As Kevin says, it isn't limited to listening sockets. Read the man
page carefully.
> Sending an email out requires the server to make a connection to a remote
> server - it doesn't use that same socket.
Correct, the mailer will use a different socket. That socket can
optionally be bound to a specific address. If I remember correctly,
it goes something like this:
int fd;
struct sockaddr_in src;
struct sockaddr_in dst;
/* source address (local network interface) */
src.sin_family = AF_INET;
src.sin_addr.s_addr = inet_addr("192.0.2.42");
/* destination */
dst.sin_port = htons(0);
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = inet_addr("192.0.2.69");
dst.sin_port = htons(25);
/* create socket */
fd = socket (PF_INET, SOCK_STREAM, 0);
/* bind to source address */
bind(fd, &src, sizeof(addr));
/* connect to remote */
connect(fd, &dst, sizeof(addr));
(That's totally untested example code, based on some quick man page
checks, so check it before you trust it. It also lacks error
checking.)
>> rom man 2 bind (emphasis mine):
>
> bind gives the socket sockfd the LOCAL ADDRESS my_addr.
>
> Again though, this is for setting up *listening* sockets. Not to connect to *remote* socket.
Note that the man page you quote doesn't mention listening there.
This isn't about the remote socket; it's about binding the local
socket to a particular address (i.e., interface).
Additional points:
Binding a socket for connect(2) doesn't influence routing directly;
it merely specifies that you want a particular source address. The
kernel router still decides how the packet gets where it is going, and
it does that based solely on the destination address[1].
The question of how Sendmail (or some other MTA, for that matter)
would decide *which* source address to use is still rather murky.
Sendmail would need to know this to pass it to bind(2) in the first
place. For mail received from another system for relay, Sendmail
could record the inteface address the mail was received on. For mail
originated on the local system, though, I don't think there is any
easy way for Sendmail to derive the source address (network interface)
the connection will use.
Footnotes
---------
[1] Well, things like policy routing, firewalling, source routing,
etc., might care about the source address, but they're exceptions to
the stateless, forward-only design of IP.
More information about the gnhlug-discuss
mailing list