Referring to the SIGURG signal here is the sample server client application that I am presenting to see how SIGURG signal are being sent and received. For all this to see we need three files which are basically the simple client and server program and a code that I have presented earlier for the mkaddr subroutine. Please download all the files mentioned below and try to build them in the order I am suggesting otherwise there are chances you may get errors.
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]# gcc -c -D_GNU_SOURCE -Wall -Wreturn-type -g oobrecv.c
[root@rhel54x64
sigurg]# gcc -c -D_GNU_SOURCE -Wall -Wreturn-type -g mkaddr.c
[root@rhel54x64
sigurg]# gcc -c -D_GNU_SOURCE -Wall -Wreturn-type -g bindacpt.c
[root@rhel54x64
sigurg]# gcc oobrecv.o mkaddr.o bindacpt.o -o oobrecv
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]# gcc -c -D_GNU_SOURCE -Wall -Wreturn-type -g oobsend.c
[root@rhel54x64
sigurg]# gcc oobsend.o mkaddr.o bindacpt.o -o oobsend
[root@rhel54x64
sigurg]#
After the compile
is complete, you have two executable programs:
- oobrecv is the receiving program (a server).
- oobsend is the sending program (a client).
Now you are ready
to invoke these programs.
Testing the oobrecv
and oobsend Programs
It is best to run
these programs in two completely different terminal sessions. Use either two different
xterm windows, or two different console sessions. Start the receiving program
first in the first terminal
session:
Example
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]# ./oobrecv
[root@rhel54x64
sigurg]#
Both programs
accept an optional address and port number pair if you want to specify your
Ethernet address instead of the local loopback address ("127.0.0.1:9011"
is assumed by default). For example, the following would work on a system with
an NIC card addressed as 192.168.0.1:
Example
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]# ./oobrecv
192.168.0.1:9023
[root@rhel54x64
sigurg]#
This would start
the server listening on 192.168.0.1 port number 9023. For the purposes of this demonstration,
however, you can just run the program without arguments. Now start the sending
program on the second terminal session, as follows:
Output
[root@rhel54x64
sigurg]#
[root@rhel54x64
sigurg]# ./oobsend
ib:
'In the beginning' (16)
ib:
'Linus begat Linux,' (18)
ib:
'and the Penguins' (16)
OOB
'rejoiced' (8)
ib:
'exceedingly.' (12)
[root@rhel54x64
sigurg]#
The lines
starting with ib: indicate in-band data that was written. The line beginning
with OOB indicates that 'rejoiced' was written as out-of-band data to the
socket. If you were able to watch both sessions at the same time, you will
notice that the receiving program reports the data shortly after it is sent by
the sending program. Its session output should look like this:
Output
[root@rhel54x64
sigurg]# ./oobrecv
rcv
'In the beginning' (16)
rcv
'Linus begat Linux,' (18)
rcv
'and the Penguins' (16)
URG
'd' (1)
rcv
'rejoice' (7)
rcv
'exceedingly.' (12)
[root@rhel54x64
sigurg]#
The output lines
shown in this terminal session that begin with rcv indicate normal in-band data
that was received. The line starting with URG indicates that SIGURG was raised
and the signal handler was called. Within the signal handler, the urgent data
is read and reported. You should notice something peculiar— only the d byte was
received as out-of-band data! What gives? Read on to find out.
No comments:
Post a Comment