Hi all,
I’ve gotten fairly far porting our control app to QNX RTP. This one here
has me stumped. It’s a little program which basically translates
messages coming in / going out through Send() / Receive() / Reply() into
TCP/IP traffic for use by a UI application. This works on QNX4.25, but
not on RTP…
It seems that for some reason udp traffic doesn’t raise SIGIO (I’m using
the full tcp/ip stack btw. , same thing with the tiny stack minus the
“ioctl(sckt, SIOCSPGRP, &gid)” stuff)
Here is some of the programs code (I tried to trim it down, not too
successfull it seems )
int InitSockets(void)
{
// if already initialized, just get out
if (scktInit == 1)
return SCKT_OK;
//— Assign signal handlers
signal(SIGIO, SocketSignalHandler); // called when a packet
is received
signal(SIGPIPE, BrokenPipeH); // called when pipe lost
if ((rcvProxy = qnx_proxy_attach(0, 0, 0, -1)) == -1)
return SCKT_NO_PROXY;
// Trigger() call back routine
RegisterCallback(rcvProxy, (intFunc)SocketEventHandler);
// clear out set of socket descriptors used by select
FD_ZERO(&fdset);
// socket library is now initialized
scktInit = 1;
return SCKT_OK;
}
static void SocketSignalHandler(int sigNo)
{
printf("#### socket signal ####\n");
Trigger(rcvProxy);
return;
}
[snip : some declarations / implementation details ommited]
int CreateSocket(char* service, int protocol, int *scktID, int type, int
port, int blocking)
{
int sckt; // socket file descriptor
int len, on, i;
gid_t gid; // this task’s group ID
struct sockaddr_in sin; // socket info entry
SOCKET_TYPE *sockNode; // new socket entry
// check passed parameters
if (scktID == NULL || service == NULL || protocol == NULL)
return SCKT_INVALID_PARMS;
*scktID = -1; // filled in at the end if all is well
//— Create the socket
sckt = socket(AF_INET, protocol, 0);
if (sckt < 0)
return SCKT_CANNOT_CREATE;
//— Set up this task group as the one receiving sigio signals
gid = getgid();
if ((i = ioctl(sckt, SIOCSPGRP, &gid)) < 0)
return SCKT_SIGNAL_ERROR;
// Allow receipt of asynchnonous I/O signals
on = 1;
if (ioctl(sckt, FIOASYNC, &on) < 0)
return SCKT_SIGNAL_ERROR;
// mark blocking (1==nonblocking, 0==blocking)
on = blocking;
if (ioctl(sckt, FIONBIO, &on) < 0)
return SCKT_SIGNAL_ERROR;
// if a server socket, set it up to accept connections
if (type == SERVER_SOCKET) {
bzero ((char*) &sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(port);
//— Bind the socket
if (bind(sckt, (struct sockaddr*) &sin, sizeof(sin)) <
0)
return SCKT_CANNOT_BIND;
//— Listen for connection requests (stream type
sockets only)
if (protocol == SOCK_STREAM) {
if (listen(sckt, QLEN) < 0) {
return SCKT_CANNOT_LISTEN;
}
}
len = sizeof(sin);
if (getsockname(sckt, (struct sockaddr *)&sin, &len))
return SCKT_ERROR;
}
FD_SET(sckt, &fdset);
return SCKT_OK;
}
int main(int argc, char *argv[])
{
int sckt, ret;
const char *service = “server”;
InitSockets();
if ((ret = CreateSocket(service, SOCK_DGRAM, &sckt,
SERVER_SOCKET, 2000, 0)) != SCKT_OK) {
return ret;
}
// call app layer function which winds up blocking in Receive()
WaitAndListen(-1);
return -1;
}
My setup is a Winderz box on 192.168.1.5 which generates a udp broadcast
for port 2000(callbook), QNX RTP on 192.168.1.16 and FreeBSD on
192.168.1.2 for dumping the network traffic.
On QNX RTP :
$ ifconfig -a
lo0: flags=8009<UP,LOOPBACK,MULTICAST> mtu 32976
inet 127.0.0.1 netmask 0xff000000
en0: flags=843<UP,BROADCAST,RUNNING,SIMPLEX> mtu 1500
address: 00:50:da:0f:e5:a8
inet 192.168.1.16 netmask 0xffffff00 broadcast 192.168.1.255
Checking the port from FreeBSD :
falcon# nmap -sU -p 2000 192.168.1.16
Starting nmap V. 2.53 by fyodor@insecure.org ( www.insecure.org/nmap/ )
Interesting ports on (192.168.1.16):
Port State Service
2000/udp open callbook
Nmap run completed – 1 IP address (1 host up) scanned in 1 second
Invoking the broadcast from Winderz(192.168.1.5) shows :
falcon# tcpdump -s 1518 -lenx host 192.168.1.5 | tcpshow -cooked
tcpdump: listening on rl0
Packet 1
TIME: 23:44:16.741878
LINK: 00:A0:24:BA:66:0A → FF:FF:FF:FF:FF:FF type=IP
IP: 192.168.1.5 → 255.255.255.255 hlen=20 TOS=00 dgramlen=40
id=BFED
MF/DF=0/0 frag=0 TTL=128 proto=UDP cksum=B92A
UDP: port 1821 → callbook hdr=8 data=12
DATA: …
… but no joy over on the RTP box where gdb waiting to fall into
“SocketSignalHandler()”. It gets called though if I get it with “kill
-SIGIO …”
-Th ( ← hoping there is someone with an idea out there)