Reg:socket programming in QNX

Hi,
I am using QNX Nutrino 6.4.0.I need to port one application from Linux to QNX which requires socket programming.Can you please suggest me what modification should I make in the following part of the Linux code so that it will be compatible for QNX.

#include <linux/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if.h>
#include <linux/if_arp.h>

int save_ifindex;
ST_RET clnp_snet_init (CLNP_PARAM *param)
{                    
struct  ifreq ifr;
ST_INT  ret;
ST_LONG arg = 0;
ST_CHAR *device;	/* name of ethernet device	*/

  /* Use ethernet device name stored in "param->network_device".	*/
  if (param->network_device == NULL ||
      strlen (param->network_device) == 0)
    {
    CLNP_LOG_ERR0 ("Subnetwork initialization: 'network_device' not set. Using default 'eth0'.");
    device = "eth0";
    }
  else
    device = param->network_device;

  memset(&ifr, 0, sizeof(ifr));

  if ((hPktSock = socket (PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: init packet socket error");
    return (SD_FAILURE);
    }

  arg |= O_NONBLOCK;
  if((ret  = fcntl (hPktSock, F_SETFL, arg)) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: error setting non-blocking flag");
    return (SD_FAILURE);
    }
  
  strcpy ( ifr.ifr_name, device);

  if (ioctl (hPktSock, SIOCGIFFLAGS, &ifr) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: error getting interface flags");
    return (SD_FAILURE);
    }

  strcpy ( ifr.ifr_name, device);
  ifr.ifr_flags |= IFF_PROMISC;

  if (ioctl (hPktSock, SIOCSIFFLAGS, &ifr) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: error setting promiscuous mode");
    return (SD_FAILURE);
    }

  ifr.ifr_ifindex = 0;
  strcpy ( ifr.ifr_name, device);

  if (ioctl (hPktSock, SIOGIFINDEX, &ifr) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: error get index");
    return (SD_FAILURE);
    }

  save_ifindex = ifr.ifr_ifindex;	/* save in global to use in clnp_snet_write_raw*/

  /* Get local MAC addr from the OS. Save it in "clnp_param.loc_mac".	*/
  strcpy (ifr.ifr_name, device);

  if (ioctl (hPktSock, SIOCGIFHWADDR, &ifr) < 0)
    {
    CLNP_LOG_ERR0 ("clnp_snet_init: error getting Hardware address");
    return (SD_FAILURE);
    }
  else
    memcpy (clnp_param.loc_mac, ifr.ifr_hwaddr.sa_data, CLNP_MAX_LEN_MAC);

  return (SD_SUCCESS);
}

Thanks,
Atanu

Well for starters, the “linux” includes will have to change.

The ioctl() calls will also have to be converted. I believe there might be a routine, something like socket_ioctl() that replaces them.

Some of the network require promiscuous mode to be enabled as a command line switch to the driver. Check the documentation for the network driver you are using.