on command wrong?

Hi,

I was trying to run the following:

on -n SOME-HOST-NAME [-d] ./mcast-sample

(the source of mcast-sample is below)

but it outputs:

From host:MY_HOST_IP port:3456, Message number: 1
From host:MY_HOST_IP port:3456, Message number: 2
From host:MY_HOST_IP port:3456, Message number: 3

but i expected that will be

From host:SOME-HOST-NAME_IP port:3456, Message number: 1

it seems – the results of that test the same as I run it on MY machine !!!
WHY?

Thanks a lot,
vasa


<><><><><><><><><><><>

// File mcast-sample.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>


#define BUFSIZE 1024
#define TTL_VALUE 2
#define TEST_ADDR “234.5.6.7”
#define TEST_PORT 3456
#define LOOPMAX 20

#define TRUE 1
#define FALSE 0

void xerr(char* s){
perror(s);
exit(-1);
}

int main(int argc,char** argv)
{
struct sockaddr_in stLocal, stTo, stFrom;
char achIn[BUFSIZE];
char achOut[] = "Message number: ";
int s, i;
struct ip_mreq stMreq;
int iTmp;
char ttl,loop;

/* get a datagram socket */
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0)
xerr (“socket() failed”);

/* avoid EADDRINUSE error on bind() */
iTmp = TRUE;
if (0>setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);
if(0 > setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);

/* name the socket /
stLocal.sin_family = AF_INET;
stLocal.sin_addr.s_addr = htonl(INADDR_ANY);
stLocal.sin_port = htons(TEST_PORT);
if(0 > bind(s, (struct sockaddr
) &stLocal, sizeof(stLocal)))
xerr (“bind() failed”);

/* join the multicast group. */
stMreq.imr_multiaddr.s_addr = inet_addr(TEST_ADDR);
stMreq.imr_interface.s_addr = INADDR_ANY;
if (0 > setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq,
sizeof(stMreq)))
xerr (“setsockopt() IP_ADD_MEMBERSHIP”);

/* set TTL to traverse up to multiple routers /
ttl = TTL_VALUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char
)&ttl,
sizeof(ttl)))
xerr (“setsockopt() IP_MULTICAST_TTL”);

/* disable loopback */
loop = FALSE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

loop = TRUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

/* assign our destination address */
stTo.sin_family = AF_INET;
stTo.sin_addr.s_addr = inet_addr(TEST_ADDR);
stTo.sin_port = htons(TEST_PORT);
printf (“Now sending to (and receiving from) multicast group: %s\n”,
TEST_ADDR);

// for (i=0;i<LOOPMAX;i++) {
for (i=0;;i++) {
static int iCounter = 1;
int addr_size = sizeof(struct sockaddr_in);

/* send to the multicast address /
itoa(iCounter++, &achOut[16], 10);
if(0 > sendto(s, achOut, sizeof(achOut), 0, (struct sockaddr
)&stTo,
addr_size))
xerr (“sendto() failed”);

if(0 > recvfrom(s, achIn, BUFSIZE, 0, (struct sockaddr*)&stFrom,
&addr_size))
xerr (“sendto()”);

printf(“From host:%s port:%d, %s\n”,
inet_ntoa(stFrom.sin_addr), ntohs(stFrom.sin_port), achIn);
sleep (2);
} /* end for(;:wink: */

return 0;
} /* end main() */

This is correct with the -n option. Your programs “root” path is still
to your machine so opens to things like /dev/socket are going to resolve
back to your local /dev/socket. The next release will have the -f option
so you can have “on” chroot() your program to the remote node before running.
Then you will have the behaviour you expect with -n.

chris

vasa <vv40in@rambler.ru> wrote:

Hi,

I was trying to run the following:

on -n SOME-HOST-NAME [-d] ./mcast-sample

(the source of mcast-sample is below)

but it outputs:

From host:MY_HOST_IP port:3456, Message number: 1
From host:MY_HOST_IP port:3456, Message number: 2
From host:MY_HOST_IP port:3456, Message number: 3

but i expected that will be

From host:SOME-HOST-NAME_IP port:3456, Message number: 1

it seems – the results of that test the same as I run it on MY machine !!!
WHY?

Thanks a lot,
vasa




// File mcast-sample.c

#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <sys/types.h
#include <sys/socket.h
#include <netinet/in.h
#include <arpa/inet.h
#include <errno.h


#define BUFSIZE 1024
#define TTL_VALUE 2
#define TEST_ADDR “234.5.6.7”
#define TEST_PORT 3456
#define LOOPMAX 20

#define TRUE 1
#define FALSE 0

void xerr(char* s){
perror(s);
exit(-1);
}

int main(int argc,char** argv)
{
struct sockaddr_in stLocal, stTo, stFrom;
char achIn[BUFSIZE];
char achOut[] = "Message number: ";
int s, i;
struct ip_mreq stMreq;
int iTmp;
char ttl,loop;

/* get a datagram socket */
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0)
xerr (“socket() failed”);

/* avoid EADDRINUSE error on bind() */
iTmp = TRUE;
if (0>setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);
if(0 > setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);

/* name the socket /
stLocal.sin_family = AF_INET;
stLocal.sin_addr.s_addr = htonl(INADDR_ANY);
stLocal.sin_port = htons(TEST_PORT);
if(0 > bind(s, (struct sockaddr
) &stLocal, sizeof(stLocal)))
xerr (“bind() failed”);

/* join the multicast group. */
stMreq.imr_multiaddr.s_addr = inet_addr(TEST_ADDR);
stMreq.imr_interface.s_addr = INADDR_ANY;
if (0 > setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq,
sizeof(stMreq)))
xerr (“setsockopt() IP_ADD_MEMBERSHIP”);

/* set TTL to traverse up to multiple routers /
ttl = TTL_VALUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char
)&ttl,
sizeof(ttl)))
xerr (“setsockopt() IP_MULTICAST_TTL”);

/* disable loopback */
loop = FALSE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

loop = TRUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

/* assign our destination address */
stTo.sin_family = AF_INET;
stTo.sin_addr.s_addr = inet_addr(TEST_ADDR);
stTo.sin_port = htons(TEST_PORT);
printf (“Now sending to (and receiving from) multicast group: %s\n”,
TEST_ADDR);

// for (i=0;i<LOOPMAX;i++) {
for (i=0;;i++) {
static int iCounter = 1;
int addr_size = sizeof(struct sockaddr_in);

/* send to the multicast address /
itoa(iCounter++, &achOut[16], 10);
if(0 > sendto(s, achOut, sizeof(achOut), 0, (struct sockaddr
)&stTo,
addr_size))
xerr (“sendto() failed”);

if(0 > recvfrom(s, achIn, BUFSIZE, 0, (struct sockaddr*)&stFrom,
&addr_size))
xerr (“sendto()”);

printf(“From host:%s port:%d, %s\n”,
inet_ntoa(stFrom.sin_addr), ntohs(stFrom.sin_port), achIn);
sleep (2);
} /* end for(;:wink: */

return 0;
} /* end main() */
\

cdm@qnx.com > “The faster I go, the behinder I get.”

Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

vasa <vv40in@rambler.ru> wrote:

Hi,

I was trying to run the following:

on -n SOME-HOST-NAME [-d] ./mcast-sample

(the source of mcast-sample is below)

but it outputs:

From host:MY_HOST_IP port:3456, Message number: 1
From host:MY_HOST_IP port:3456, Message number: 2
From host:MY_HOST_IP port:3456, Message number: 3

but i expected that will be

From host:SOME-HOST-NAME_IP port:3456, Message number: 1

it seems – the results of that test the same as I run it on MY machine !!!
WHY?

What you see is correct behaver. “on -n cmd” inherit all current env.
(It use SOME-HOST-NAME_IP’s memory/cpu, but using all services on
MY_HOST_IP).

What you actually want is “on -f cmd”, but unfortunatly, “-f” is not
supported in your release.

Since you are trying socket program, you can, however, use this:

SOCK=/net/SOME-HOST-NAME_IP cmd

The “cmd” will run local (use MY_HOST_IP’s memory, cpu), but
contact to remote tcpip.

-xtang


// File mcast-sample.c

#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <sys/types.h
#include <sys/socket.h
#include <netinet/in.h
#include <arpa/inet.h
#include <errno.h



#define BUFSIZE 1024
#define TTL_VALUE 2
#define TEST_ADDR “234.5.6.7”
#define TEST_PORT 3456
#define LOOPMAX 20

#define TRUE 1
#define FALSE 0

void xerr(char* s){
perror(s);
exit(-1);
}

int main(int argc,char** argv)
{
struct sockaddr_in stLocal, stTo, stFrom;
char achIn[BUFSIZE];
char achOut[] = "Message number: ";
int s, i;
struct ip_mreq stMreq;
int iTmp;
char ttl,loop;

/* get a datagram socket */
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0)
xerr (“socket() failed”);

/* avoid EADDRINUSE error on bind() */
iTmp = TRUE;
if (0>setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);
if(0 > setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&iTmp,
sizeof(iTmp)))
xerr (“setsockopt() SO_REUSEADDR failed”);

/* name the socket /
stLocal.sin_family = AF_INET;
stLocal.sin_addr.s_addr = htonl(INADDR_ANY);
stLocal.sin_port = htons(TEST_PORT);
if(0 > bind(s, (struct sockaddr
) &stLocal, sizeof(stLocal)))
xerr (“bind() failed”);

/* join the multicast group. */
stMreq.imr_multiaddr.s_addr = inet_addr(TEST_ADDR);
stMreq.imr_interface.s_addr = INADDR_ANY;
if (0 > setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq,
sizeof(stMreq)))
xerr (“setsockopt() IP_ADD_MEMBERSHIP”);

/* set TTL to traverse up to multiple routers /
ttl = TTL_VALUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char
)&ttl,
sizeof(ttl)))
xerr (“setsockopt() IP_MULTICAST_TTL”);

/* disable loopback */
loop = FALSE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

loop = TRUE;
if (0 > setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loop,
sizeof(loop)))
xerr (“setsockopt() IP_MULTICAST_LOOP”);

/* assign our destination address */
stTo.sin_family = AF_INET;
stTo.sin_addr.s_addr = inet_addr(TEST_ADDR);
stTo.sin_port = htons(TEST_PORT);
printf (“Now sending to (and receiving from) multicast group: %s\n”,
TEST_ADDR);

// for (i=0;i<LOOPMAX;i++) {
for (i=0;;i++) {
static int iCounter = 1;
int addr_size = sizeof(struct sockaddr_in);

/* send to the multicast address /
itoa(iCounter++, &achOut[16], 10);
if(0 > sendto(s, achOut, sizeof(achOut), 0, (struct sockaddr
)&stTo,
addr_size))
xerr (“sendto() failed”);

if(0 > recvfrom(s, achIn, BUFSIZE, 0, (struct sockaddr*)&stFrom,
&addr_size))
xerr (“sendto()”);

printf(“From host:%s port:%d, %s\n”,
inet_ntoa(stFrom.sin_addr), ntohs(stFrom.sin_port), achIn);
sleep (2);
} /* end for(;:wink: */

return 0;
} /* end main() */