|
Home > Archive > Unix Programming > September 2006 > Understanding ping program
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Understanding ping program
|
|
| Tiken Heirangkhongjam 2006-09-18, 7:34 am |
| hi all,
I m very new to the Socket programming and I m trying to understand the
ping program (the first draft) written by Mike Muuss.
I m unable to understand the line
int fdmask = 1 << s;
where s is the socket descriptor used.
for the source code plz refer:
http://ws.edu.isoc.org/materials/src/ping.c
I would like to know the function of "fdmask" .Pliz suggest me in this
regard.
thanks and regards,
tiken
| |
| Hubble 2006-09-18, 7:34 am |
| Tiken Heirangkhongjam schrieb:
> I m unable to understand the line
> int fdmask = 1 << s;
> where s is the socket descriptor used.
<< is the left shift operator in C. 1<<s means basically 2^s (^=power)
(constant 1 shifted by s bits to the left). fdmask is used in the
select system call, so 1<<s contains a 1 for the bit of the file
descriptor s, 0 for all other file descriptors.
Hubble
| |
| Robert Harris 2006-09-18, 7:34 am |
| Tiken Heirangkhongjam wrote:
> hi all,
>
> I m very new to the Socket programming and I m trying to understand the
> ping program (the first draft) written by Mike Muuss.
>
> I m unable to understand the line
> int fdmask = 1 << s;
> where s is the socket descriptor used.
>
> for the source code plz refer:
> http://ws.edu.isoc.org/materials/src/ping.c
"man select" explains it.
Robert
>
>
> [snip]
| |
| Nils O. Selåsdal 2006-09-18, 7:34 am |
| Tiken Heirangkhongjam wrote:
> hi all,
>
> I m very new to the Socket programming and I m trying to understand the
> ping program (the first draft) written by Mike Muuss.
>
> I m unable to understand the line
> int fdmask = 1 << s;
> where s is the socket descriptor used.
>
> for the source code plz refer:
> http://ws.edu.isoc.org/materials/src/ping.c
>
>
> I would like to know the function of "fdmask" .Pliz suggest me in this
> regard.
It uses some internal knowledge of the select call on a particular (old)
system, it should not be done this way anymore, rather the code should
be:
fd_set fdmask;
FD_ZERO(&fdmask);
FD_SET(s,&fdmask);
....
select(s+1, &fdmask, 0, 0, &timeout)
See the select manpage for further info.
| |
| Tiken Heirangkhongjam 2006-09-18, 1:28 pm |
|
Thanks a lot for ur valuable suggestions.It really helped me in
understanding the program.
|
|
|
|
|