Subject: How do I set the linktype on a P2P interface under BSD/OS?
Date: 09/12/97

Point to Point interfaces, such as the N2 card, under BSD/OS may be assigned to a number of types. As of the date of this NSFAQ the IFT_NONE, IFT_PTPSERIAL, IFT_PPP, IFT_FRELAY, IFT_LAPB and IFT_X25 types are supported (the latter two only in internal versions of BSD/OS).

In BSD/OS 3.1 the IFT_NONE type will allow you to read and write raw packets to the interface. The IFT_PTPSERIAL is also known as Cisco HDLC.

The ifconfig command may be used, with the linktype option to specify an interfaces link type. A program can use the SIOCSIFADDR ioctl on a raw AF_LINK socket. The ifreq.ifr_name field should contain the interface name and the ifreq.ifr_ifr_addr field should be a sockaddr_dl with the sdl_family set to AF_LINK, the sdl_type set to what ever type you want and sdl_len set to span just the family and type.

/*-
 * Copyright (c) 1996 Berkeley Software Design, Inc.
 * All rights reserved.
 */
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

int
setlinktype(char *name, int type)
{
	int r, rs;
        struct sockaddr_dl *dl;
        struct ifreq ifr;

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

        dl = (struct sockaddr_dl *)&ifr.ifr_addr;

        if ((rs = socket(AF_LINK, SOCK_RAW, 0)) < 0)
                return (-1);

        strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));

        dl->sdl_family = AF_LINK;
        dl->sdl_type = type;
        dl->sdl_len = sizeof(*dl) - sizeof(dl->sdl_data);

        r = ioctl(rs, SIOCSIFADDR, &ifr);
        close(rs);
	return (r);
}