From: Giro on
Hi,

I've written an application using Raw sockets. And sending the
complete Layer2 frame.
sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))

A call like
ret = send(sock, buff, buff_size,0);
should returns the number of trasferred bytes. So far so good. Now, If
I call the same function when the NIC link is down
(cable not plugged) then I receive no error. Instead I receive the
number of bytes trasferred.

Is this is a special case for raw sockets? I guess sockets on higher
layers like IP or TCP should return an error in such a case.

Is there any possibility to register a callback routine for a link
state change event?
I guess I can check with an ioctl call to the driver whether the link
is up or not. But a callback would be better ofcourse.

Thanks for any help.
Giray
From: Rick Jones on
Giro <giray.curgunlu(a)gmail.com> wrote:
> I've written an application using Raw sockets. And sending the
> complete Layer2 frame.
> sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))

> A call like
> ret = send(sock, buff, buff_size,0);
> should returns the number of trasferred bytes. So far so good. Now,
> If I call the same function when the NIC link is down (cable not
> plugged) then I receive no error. Instead I receive the number of
> bytes trasferred.

> Is this is a special case for raw sockets? I guess sockets on higher
> layers like IP or TCP should return an error in such a case.

No - they have no clue about link state - at least the application
using TCP won't. If the link is down, successive sends into a socket
bound to a TCP endpoint will simply fill the socket buffer and block
(or return EWOULDBLOCK/EAGAIN/whatnot if the socket is non-blocking)
until TCP either gets told by the routing that there is no way to get
there from here, or its retransmission limits are reached. At that
point, the connection will be terminated and a suitable indication
will be made for the socket.

rick jones
--
The glass is neither half-empty nor half-full. The glass has a leak.
The real question is "Can it be patched?"
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
From: Giro on
On May 14, 2:35 am, Rick Jones <rick.jon...(a)hp.com> wrote:
> Giro <giray.curgu...(a)gmail.com> wrote:
> > I've written an application using Raw sockets. And sending the
> > complete Layer2 frame.
> > sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))
> > A call like
> > ret = send(sock, buff, buff_size,0);
> > should returns the number of trasferred bytes. So far so good. Now,
> > If I call the same function when the NIC link is down (cable not
> > plugged) then I receive no error. Instead I receive the number of
> > bytes trasferred.
> > Is this is a special case for raw sockets? I guess sockets on higher
> > layers like IP or TCP should return an error in such a case.
>
> No - they have no clue about link state - at least the application
> using TCP won't.  If the link is down, successive sends into a socket
> bound to a TCP endpoint will simply fill the socket buffer and block
> (or return EWOULDBLOCK/EAGAIN/whatnot if the socket is non-blocking)
> until TCP either gets told by the routing that there is no way to get
> there from here, or its retransmission limits are reached. At that
> point, the connection will be terminated and a suitable indication
> will be made for the socket.
>
> rick jones
> --
> The glass is neither half-empty nor half-full. The glass has a leak.
> The real question is "Can it be patched?"
> these opinions are mine, all mine; HP might not want them anyway... :)
> feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

Many thanks Rick

I digged through the details and came to the following results:
Send over UDP ->returns error when link is down. The reason is that an
ICMP message is sent each time a frame is put on wire.
Send over TCP ->does not return error after connection has been
established and then when you unplug the cable. Because the ICMP
message is sent only once when connection is established, then no more
afterwards.
Send Raw packet PF_PACKET -> does not return any error.

I guess I'll check the link status of the driver directly with an
ioctl call.

Cheers,
Giray
From: Rick Jones on
Giro <giray.curgunlu(a)gmail.com> wrote:
> I digged through the details and came to the following results:
> Send over UDP ->returns error when link is down. The reason is that an
> ICMP message is sent each time a frame is put on wire.

I suspect though the error indication is on the *next* send/socket
operation right? Or is it actually synchronous with the one send via
a UDP socket?

Also, while I suppose we might presume from the newsgroup the context
is purely linux, portable code probably cannot rely on such
indications at the socket layer.

rick jones
--
No need to believe in either side, or any side. There is no cause.
There's only yourself. The belief is in your own precision. - Joubert
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...