bringing up an interface

Is there any sample code that shows how to set an interface address, netmask
on QNX 6.2?
I have used ioctl() calls SIOCSIFADDR, SIOCSIFFLAGS to bring up the
interface on QNX 6.1, now the same code would crash io-net.

Appreciate any help.

-Beth

Please post your code.

-seanb


Beth <id@net.com> wrote:

Is there any sample code that shows how to set an interface address, netmask
on QNX 6.2?
I have used ioctl() calls SIOCSIFADDR, SIOCSIFFLAGS to bring up the
interface on QNX 6.1, now the same code would crash io-net.

Appreciate any help.

-Beth

This is the code I used for bringing up an interface on QNX 6.1 tiny and
full tcp stack.
Now, it crashes when running on QNX 6.2.

Thanks for your help.
-Beth


#include <net/route.h>
#include <sys/sockio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char * argv[])
{
int rc = 0;
int fd;
struct ifreq req;
struct sockaddr_in *sin = (struct sockaddr_in *)&req.ifr_addr;
ip_addr p_addr, p_mask;


addr_set_long(&p_addr, inet_network(“10.10.10.4”), WG_IP_HOSTORDER);
addr_set_long(&p_mask, inet_network(“255.255.255.0”), WG_IP_HOSTORDER);

fd = socket(AF_INET, SOCK_DGRAM, 0);
if( fd > 0 )
{
memset (&req, 0x00, sizeof(req));
strcpy ( req.ifr_name, “mnc0”);
sin->sin_len = sizeof (struct sockaddr_in);
sin->sin_family = AF_INET;

sin->sin_addr.s_addr = p_addr.net_order.s_addr;

if ( ( rc=ioctl (fd, SIOCSIFADDR, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFADDR) error: %s , err = %d\n”,
strerror(errno), errno);
}
sin->sin_addr.s_addr = p_mask.net_order.s_addr;
if ( ( rc=ioctl (fd, SIOCSIFNETMASK, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFNETMASK) error: %s , err = %d\n”,
strerror(errno), errno);
}
req.ifr_flags = 0;
if ( (rc = ioctl (fd, SIOCGIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCGIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}

req.ifr_flags |= IFF_UP |IFF_RUNNING;
if (( rc = ioctl (fd, SIOCSIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCSIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}
close(fd);
} else {
printf(“Open socket failed: %s , err = %d\n”,
strerror(errno), errno);
rc=errno;
}
return rc;
}


“Sean Boudreau” <seanb@node25.ott.qnx.com> wrote in message
news:bdhrmn$su2$1@nntp.qnx.com

Please post your code.

-seanb


Beth <> id@net.com> > wrote:
Is there any sample code that shows how to set an interface address,
netmask
on QNX 6.2?
I have used ioctl() calls SIOCSIFADDR, SIOCSIFFLAGS to bring up the
interface on QNX 6.1, now the same code would crash io-net.

Appreciate any help.

-Beth

This doesn’t compile cleanly. My modified version seems
to work here with both stacks. Does it work without your
mnc0 driver (just a plain ethernet).

BTW a return of ‘0’ is a valid fd from socket().

-seanb


Beth <id@net.com> wrote:

This is the code I used for bringing up an interface on QNX 6.1 tiny and
full tcp stack.
Now, it crashes when running on QNX 6.2.

Thanks for your help.
-Beth



#include <net/route.h
#include <sys/sockio.h
#include <sys/types.h
#include <sys/socket.h
#include <sys/ioctl.h
#include <errno.h
#include <string.h
#include <netinet/in.h
#include <arpa/inet.h

int main(int argc, char * argv[])
{
int rc = 0;
int fd;
struct ifreq req;
struct sockaddr_in *sin = (struct sockaddr_in *)&req.ifr_addr;
ip_addr p_addr, p_mask;



addr_set_long(&p_addr, inet_network(“10.10.10.4”), WG_IP_HOSTORDER);
addr_set_long(&p_mask, inet_network(“255.255.255.0”), WG_IP_HOSTORDER);

fd = socket(AF_INET, SOCK_DGRAM, 0);
if( fd > 0 )
{
memset (&req, 0x00, sizeof(req));
strcpy ( req.ifr_name, “mnc0”);
sin->sin_len = sizeof (struct sockaddr_in);
sin->sin_family = AF_INET;

sin->sin_addr.s_addr = p_addr.net_order.s_addr;

if ( ( rc=ioctl (fd, SIOCSIFADDR, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFADDR) error: %s , err = %d\n”,
strerror(errno), errno);
}
sin->sin_addr.s_addr = p_mask.net_order.s_addr;
if ( ( rc=ioctl (fd, SIOCSIFNETMASK, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFNETMASK) error: %s , err = %d\n”,
strerror(errno), errno);
}
req.ifr_flags = 0;
if ( (rc = ioctl (fd, SIOCGIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCGIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}

req.ifr_flags |= IFF_UP |IFF_RUNNING;
if (( rc = ioctl (fd, SIOCSIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCSIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}
close(fd);
} else {
printf(“Open socket failed: %s , err = %d\n”,
strerror(errno), errno);
rc=errno;
}
return rc;
}



“Sean Boudreau” <> seanb@node25.ott.qnx.com> > wrote in message
news:bdhrmn$su2$> 1@nntp.qnx.com> …
Please post your code.

-seanb


Beth <> id@net.com> > wrote:
Is there any sample code that shows how to set an interface address,
netmask
on QNX 6.2?
I have used ioctl() calls SIOCSIFADDR, SIOCSIFFLAGS to bring up the
interface on QNX 6.1, now the same code would crash io-net.

Appreciate any help.

-Beth

Sean, thanks for help. Sorry, I should give you the source code that can
compile cleanly.
I did try this code on “en0”, it worked fine. So, it’s combination of the
private interface and the 6.2 full stack that caused io-net to crash. Any
suggestion on debugging this problem?

-Beth


“Sean Boudreau” <seanb@node25.ott.qnx.com> wrote in message
news:bdi7s7$n9a$1@nntp.qnx.com

This doesn’t compile cleanly. My modified version seems
to work here with both stacks. Does it work without your
mnc0 driver (just a plain ethernet).

BTW a return of ‘0’ is a valid fd from socket().

-seanb


Beth <> id@net.com> > wrote:
This is the code I used for bringing up an interface on QNX 6.1 tiny and
full tcp stack.
Now, it crashes when running on QNX 6.2.

Thanks for your help.
-Beth


#include <net/route.h
#include <sys/sockio.h
#include <sys/types.h
#include <sys/socket.h
#include <sys/ioctl.h
#include <errno.h
#include <string.h
#include <netinet/in.h
#include <arpa/inet.h

int main(int argc, char * argv[])
{
int rc = 0;
int fd;
struct ifreq req;
struct sockaddr_in *sin = (struct sockaddr_in *)&req.ifr_addr;
ip_addr p_addr, p_mask;


addr_set_long(&p_addr, inet_network(“10.10.10.4”), WG_IP_HOSTORDER);
addr_set_long(&p_mask, inet_network(“255.255.255.0”),
WG_IP_HOSTORDER);

fd = socket(AF_INET, SOCK_DGRAM, 0);
if( fd > 0 )
{
memset (&req, 0x00, sizeof(req));
strcpy ( req.ifr_name, “mnc0”);
sin->sin_len = sizeof (struct sockaddr_in);
sin->sin_family = AF_INET;

sin->sin_addr.s_addr = p_addr.net_order.s_addr;

if ( ( rc=ioctl (fd, SIOCSIFADDR, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFADDR) error: %s , err = %d\n”,
strerror(errno), errno);
}
sin->sin_addr.s_addr = p_mask.net_order.s_addr;
if ( ( rc=ioctl (fd, SIOCSIFNETMASK, &req) ) < 0 )
{
printf(“ioctl(SIOCSIFNETMASK) error: %s , err = %d\n”,
strerror(errno), errno);
}
req.ifr_flags = 0;
if ( (rc = ioctl (fd, SIOCGIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCGIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}

req.ifr_flags |= IFF_UP |IFF_RUNNING;
if (( rc = ioctl (fd, SIOCSIFFLAGS, &req) )< 0)
{
printf(“ioctl(SIOCSIFFLAGS) error: %s , err = %d\n”,
strerror(errno), errno);
}
close(fd);
} else {
printf(“Open socket failed: %s , err = %d\n”,
strerror(errno), errno);
rc=errno;
}
return rc;
}


“Sean Boudreau” <> seanb@node25.ott.qnx.com> > wrote in message
news:bdhrmn$su2$> 1@nntp.qnx.com> …
Please post your code.

-seanb


Beth <> id@net.com> > wrote:
Is there any sample code that shows how to set an interface address,
netmask
on QNX 6.2?
I have used ioctl() calls SIOCSIFADDR, SIOCSIFFLAGS to bring up the
interface on QNX 6.1, now the same code would crash io-net.

Appreciate any help.

-Beth
\

Beth <id@net.com> wrote:

Sean, thanks for help. Sorry, I should give you the source code that can
compile cleanly.
I did try this code on “en0”, it worked fine. So, it’s combination of the
private interface and the 6.2 full stack that caused io-net to crash. Any
suggestion on debugging this problem?

Nothing specific. If you’re lucky, it’s actually dying in your
code. If so, you should be able to use gdb to narrow it down.

-seanb