Monthly Archives: January 2015

IPv6 in FreeBSD/Linux

Linux Daemon Dienste

radvd

Router Advertisement Daemon (radvd) (wenn die Clients automatisch konfiguriert werden sollen)
Wikipedia: Router Advertisement Daemon (radvd), implements link-local advertisements of IPv6 router addresses and IPv6 routing prefixes using the Neighbor Discovery Protocol (NDP) => stateless autoconfiguration

NAT64

Wikipedia: NAT64
TAYGA
NAT64 Kernel Module
github.com/fln/nat64

link local fe80::
global unicase 2001:

/proc/sys/net/ipv6/conf
all   default   eth0   eth1   lo

/proc/sys/net/ipv6/conf/all/forwarding => 1

well-known prefix, z.B.
NAT64   64:ff9b::/96
ALG     Application Layer Gateway
RR      Resource Record

FreeBSD Subversion

Subversion Mirror Sites

FreeBSD VLAN

FreeBSD VLAN Configuration
FreeBSD – Adding VLAN Tagged subinterface using ifconfig

struct  vlanreq {
    char    vlr_parent[IFNAMSIZ];
    u_short vlr_tag;
};
Step 1: create the vlan subinterface
# ifconfig vlan122 create

Step 2: assign it a vlan ID and vlan device:
# ifconfig vlan122 vlan 122 vlandev em0

Step 3: check the vlan subinterface:
# ifconfig vlan122
vlan122: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:07:e9:a5:9b:fa
        media: Ethernet autoselect (1000baseTX <full-duplex>)
        status: active
        vlan: 122 parent interface: em0

Step 4: assign ip address:
# ifconfig vlan122 10.1.122.1/24
# ifconfig vlan122 up
# ifconfig vlan122
vlan122: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:07:e9:a5:9b:fa
        inet 10.1.122.1 netmask 0xffffff00 broadcast 10.1.122.255
        media: Ethernet autoselect (1000baseTX <full-duplex>)
        status: active
        vlan: 122 parent interface: em0

Or edit rc.conf:
cloned_interfaces="vlan0"
ifconfig_vlan0="inet x.x.x.x netmask y.y.y.y vlan 2 vlandev em0"

FreeBSD Manual Pages

getifaddrs — get interface addresses
ether_ntohost — Ethernet address conversion and lookup routines

FreeBSD Implementation

DEC Direct Data Link Interface (DLI)
How to know ip address for interfaces in c
Polling interface names via SIOCGIFCONF in Linux
Broadcasting and Determining Network Configuration
FreeBSD: network interface information
lo0 not in ioctl( SIOCGIFCONF )
SOLVED: lo0 not in ioctl( SIOCGIFCONF )
How to get IPv6 address using getifaddrs and which version of glibc supports
How can I enumerate the list of network devices or interfaces in C or C++ in FreeBSD? [duplicate]
Re: ioctl programming probs

getifaddrs.c

Linux:
struct ifreq {
    char ifr_name[IFNAMSIZ]; /* Interface name */
    union {
        struct sockaddr ifr_addr;
        struct sockaddr ifr_dstaddr;
        struct sockaddr ifr_broadaddr;
        struct sockaddr ifr_netmask;
        struct sockaddr ifr_hwaddr;
        short           ifr_flags;
        int             ifr_ifindex;
        int             ifr_metric;
        int             ifr_mtu;
        struct ifmap    ifr_map;
        char            ifr_slave[IFNAMSIZ];
        char            ifr_newname[IFNAMSIZ];
        char           *ifr_data;
    };
};

struct ifconf {
    int                 ifc_len; /* size of buffer */
    union {
        char           *ifc_buf; /* buffer address */
        struct ifreq   *ifc_req; /* array of structures */
    };
};

FreeBSD:

/*
 * Length of interface external name, including terminating '\0'.
 * Note: this is the same size as a generic device's external name.
 */
#define         IF_NAMESIZE     16
#if __BSD_VISIBLE
#define         IFNAMSIZ        IF_NAMESIZE
#define         IF_MAXUNIT      0x7fff  /* historical value */
#endif
#if __BSD_VISIBLE

/*
 * Interface request structure used for socket
 * ioctl's.  All interface ioctl's must have parameter
 * definitions which begin with ifr_name.  The
 * remainder may be interface specific.
 */
struct  ifreq {
        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
        union {
                struct  sockaddr ifru_addr;
                struct  sockaddr ifru_dstaddr;
                struct  sockaddr ifru_broadaddr;
                struct  ifreq_buffer ifru_buffer;
                short   ifru_flags[2];
                short   ifru_index;
                int     ifru_jid;
                int     ifru_metric;
                int     ifru_mtu;
                int     ifru_phys;
                int     ifru_media;
                caddr_t ifru_data;
                int     ifru_cap[2];
                u_int   ifru_fib;
        } ifr_ifru;
#define ifr_addr        ifr_ifru.ifru_addr      /* address */
#define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
#define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_buffer      ifr_ifru.ifru_buffer    /* user supplied buffer with its length */
#define ifr_flags       ifr_ifru.ifru_flags[0]  /* flags (low 16 bits) */
#define ifr_flagshigh   ifr_ifru.ifru_flags[1]  /* flags (high 16 bits) */
#define ifr_jid         ifr_ifru.ifru_jid       /* jail/vnet */
#define ifr_metric      ifr_ifru.ifru_metric    /* metric */
#define ifr_mtu         ifr_ifru.ifru_mtu       /* mtu */
#define ifr_phys        ifr_ifru.ifru_phys      /* physical wire */
#define ifr_media       ifr_ifru.ifru_media     /* physical media */
#define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
#define ifr_reqcap      ifr_ifru.ifru_cap[0]    /* requested capabilities */
#define ifr_curcap      ifr_ifru.ifru_cap[1]    /* current capabilities */
#define ifr_index       ifr_ifru.ifru_index     /* interface index */
#define ifr_fib         ifr_ifru.ifru_fib       /* interface fib */
};


/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct  ifconf {
        int     ifc_len;                /* size of associated buffer */
        union {
                caddr_t ifcu_buf;
                struct  ifreq *ifcu_req;
        } ifc_ifcu;
#define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
#define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
};

/*-
 * Interface flags are of two types: network stack owned flags, and driver
 * owned flags.  Historically, these values were stored in the same ifnet
 * flags field, but with the advent of fine-grained locking, they have been
 * broken out such that the network stack is responsible for synchronizing
 * the stack-owned fields, and the device driver the device-owned fields.
 * Both halves can perform lockless reads of the other half's field, subject
 * to accepting the involved races.
 *
 * Both sets of flags come from the same number space, and should not be
 * permitted to conflict, as they are exposed to user space via a single
 * field.
 *
 * The following symbols identify read and write requirements for fields:
 *
 * (i) if_flags field set by device driver before attach, read-only there
 *     after.
 * (n) if_flags field written only by the network stack, read by either the
 *     stack or driver.
 * (d) if_drv_flags field written only by the device driver, read by either
 *     the stack or driver.
 */
#define IFF_UP          0x1             /* (n) interface is up */
#define IFF_BROADCAST   0x2             /* (i) broadcast address valid */
#define IFF_DEBUG       0x4             /* (n) turn on debugging */
#define IFF_LOOPBACK    0x8             /* (i) is a loopback net */
#define IFF_POINTOPOINT 0x10            /* (i) is a point-to-point link */
#define IFF_SMART       0x20            /* (i) interface manages own routes */
#define IFF_DRV_RUNNING 0x40            /* (d) resources allocated */
#define IFF_NOARP       0x80            /* (n) no address resolution protocol */
#define IFF_PROMISC     0x100           /* (n) receive all packets */
#define IFF_ALLMULTI    0x200           /* (n) receive all multicast packets */
#define IFF_DRV_OACTIVE 0x400           /* (d) tx hardware queue is full */
#define IFF_SIMPLEX     0x800           /* (i) can't hear own transmissions */
#define IFF_LINK0       0x1000          /* per link layer defined bit */
#define IFF_LINK1       0x2000          /* per link layer defined bit */
#define IFF_LINK2       0x4000          /* per link layer defined bit */
#define IFF_ALTPHYS     IFF_LINK2       /* use alternate physical connection */
#define IFF_MULTICAST   0x8000          /* (i) supports multicast */
#define IFF_CANTCONFIG  0x10000         /* (i) unconfigurable using ioctl(2) */
#define IFF_PPROMISC    0x20000         /* (n) user-requested promisc mode */
#define IFF_MONITOR     0x40000         /* (n) user-requested monitor mode */
#define IFF_STATICARP   0x80000         /* (n) static ARP */
#define IFF_DYING       0x200000        /* (n) interface is winding down */
#define IFF_RENAMING    0x400000        /* (n) interface is being renamed */
/* Throughout this file, IP addresses are expected to be in
 * the same byte order as in IP_PCB. */

/** must be the maximum of all used hardware address lengths
    across all types of interfaces in use */
#define NETIF_MAX_HWADDR_LEN 6U

/** Whether the network interface is 'up'. This is
 * a software flag used to control whether this network
 * interface is enabled and processes traffic.
 * It is set by the startup code (for static IP configuration) or
 * by dhcp/autoip when an address has been assigned.
 */
#define NETIF_FLAG_UP           0x01U
/** If set, the netif has broadcast capability.
 * Set by the netif driver in its init function. */
#define NETIF_FLAG_BROADCAST    0x02U
/** If set, the netif is one end of a point-to-point connection.
 * Set by the netif driver in its init function. */
#define NETIF_FLAG_POINTTOPOINT 0x04U
/** If set, the interface is configured using DHCP.
 * Set by the DHCP code when starting or stopping DHCP. */
#define NETIF_FLAG_DHCP         0x08U
/** If set, the interface has an active link
 *  (set by the network interface driver).
 * Either set by the netif driver in its init function (if the link
 * is up at that time) or at a later point once the link comes up
 * (if link detection is supported by the hardware). */
#define NETIF_FLAG_LINK_UP      0x10U
/** If set, the netif is an ethernet device using ARP.
 * Set by the netif driver in its init function.
 * Used to check input packet types and use of DHCP. */
#define NETIF_FLAG_ETHARP       0x20U
/** If set, the netif is an ethernet device. It might not use
 * ARP or TCP/IP if it is used for PPPoE only.
 */
#define NETIF_FLAG_ETHERNET     0x40U
/** If set, the netif has IGMP capability.
 * Set by the netif driver in its init function. */
#define NETIF_FLAG_IGMP         0x80U

/** Generic data structure used for all lwIP network interfaces.
 *  The following fields should be filled in by the initialization
 *  function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
struct netif {
    /** pointer to next in linked list */
    struct netif *next;
    
    /** IP address configuration in network byte order */
    ip_addr_t ip_addr;
    ip_addr_t netmask;
    ip_addr_t gw;
    
    /*** LWIP_IPV6 ***********************************************************/
    /** Array of IPv6 addresses for this netif. */
    ip6_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
    /** The state of each IPv6 address (Tentative, Preferred, etc).
     * @see ip6_addr.h */
    u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];

    /** This function is called by the network device driver
     *  to pass a packet up the TCP/IP stack. */
    netif_input_fn input;
    /** This function is called by the IP module when it wants
     *  to send a packet on the interface. This function typically
     *  first resolves the hardware address, then sends the packet. */
    netif_output_fn output;
    /** This function is called by the ARP module when it wants
     *  to send a packet on the interface. This function outputs
     *  the pbuf as-is on the link medium. */
    netif_linkoutput_fn linkoutput;
    
    /*** LWIP_IPV6 ***********************************************************/
    /** This function is called by the IPv6 module when it wants
     *  to send a packet on the interface. This function typically
     *  first resolves the hardware address, then sends the packet. */
     netif_output_ip6_fn output_ip6;
    
    /*** LWIP_NETIF_STATUS_CALLBACK ******************************************/
    /** This function is called when the netif state is set to up or down */
    netif_status_callback_fn status_callback;
    
    /*** LWIP_NETIF_LINK_CALLBACK ********************************************/
    /** This function is called when the netif link is set to up or down */
    netif_status_callback_fn link_callback;
    
    /*** LWIP_NETIF_REMOVE_CALLBACK ******************************************/
    /** This function is called when the netif has been removed */
    netif_status_callback_fn remove_callback;
    
    /** This field can be set by the device driver and could point
     *  to state information for the device. */
    void *state;
    
    /*** LWIP_DHCP ***********************************************************/
    /** the DHCP client state information for this netif */
    struct dhcp *dhcp;
    
    /*** LWIP_AUTOIP *********************************************************/
    /** the AutoIP client state information for this netif */
    struct autoip *autoip;
    
    /*** LWIP_IPV6_AUTOCONFIG ************************************************/
    /** is this netif enabled for IPv6 autoconfiguration */
    u8_t ip6_autoconfig_enabled;
    
    /*** LWIP_IPV6_SEND_ROUTER_SOLICIT ***************************************/
    /** Number of Router Solicitation messages that remain to be sent. */
    u8_t rs_count;
    
    /*** LWIP_IPV6_DHCP6 *****************************************************/
    /** the DHCPv6 client state information for this netif */
    struct dhcp6 *dhcp6;
    
    /*** LWIP_NETIF_HOSTNAME *************************************************/
    /* the hostname for this netif, NULL is a valid value */
    char*  hostname;
    
    /** maximum transfer unit (in bytes) */
    u16_t mtu;
    /** number of bytes used in hwaddr */
    u8_t hwaddr_len;
    /** link level hardware address of this interface */
    u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
    /** flags (see NETIF_FLAG_ above) */
    u8_t flags;
    /** descriptive abbreviation */
    char name[2];
    /** number of this interface */
    u8_t num;
    
    /*** LWIP_SNMP ***********************************************************/
    /** link type (from "snmp_ifType" enum from snmp.h) */
    u8_t link_type;
    /** (estimate) link speed */
    u32_t link_speed;
    /** timestamp at last change made (up/down) */
    u32_t ts;
    /** counters */
    u32_t ifinoctets;
    u32_t ifinucastpkts;
    u32_t ifinnucastpkts;
    u32_t ifindiscards;
    u32_t ifoutoctets;
    u32_t ifoutucastpkts;
    u32_t ifoutnucastpkts;
    u32_t ifoutdiscards;
    
    /*** LWIP_IGMP ***********************************************************/
    /** This function could be called to add or delete a entry in the multicast
     *  filter table of the ethernet MAC.*/
    netif_igmp_mac_filter_fn igmp_mac_filter;
    
    /*** LWIP_IPV6 && LWIP_IPV6_MLD ******************************************/
    /** This function could be called to add or delete an entry in the IPv6 multicast
     *  filter table of the ethernet MAC. */
    netif_mld_mac_filter_fn mld_mac_filter;
    
    /*** LWIP_NETIF_HWADDRHINT ***********************************************/
    u8_t *addr_hint;
    
    /*** ENABLE_LOOPBACK *****************************************************/
    /* List of packets to be queued for ourselves. */
    struct pbuf *loop_first;
    struct pbuf *loop_last;
    
    u16_t loop_cnt_current;
};
#define SIOCSIFPHYADDR   _IOW('i', 70, struct ifaliasreq) /* set gif addres */
#define SIOCGIFPSRCADDR _IOWR('i', 71, struct ifreq)    /* get gif psrc addr */
#define SIOCGIFPDSTADDR _IOWR('i', 72, struct ifreq)    /* get gif pdst addr */
struct nd_ifinfo {
    u_int32_t linkmtu;              /* LinkMTU */
    u_int32_t maxmtu;               /* Upper bound of LinkMTU */
    u_int32_t basereachable;        /* BaseReachableTime */
    u_int32_t reachable;            /* Reachable Time */
    u_int32_t retrans;              /* Retrans Timer */
    u_int32_t flags;                /* Flags */
    int recalctm;                   /* BaseReacable re-calculation timer */
    u_int8_t chlim;                 /* CurHopLimit */
    u_int8_t initialized;           /* Flag to see the entry is initialized */
    
    /* the following 3 members are for privacy extension for addrconf */
    u_int8_t randomseed0[8];        /* upper 64 bits of MD5 digest */
    u_int8_t randomseed1[8];        /* lower 64 bits (usually the EUI64 IFID) */
    u_int8_t randomid[8];           /* current random ID */
};

struct  in6_ndireq {
    char ifname[IFNAMSIZ];
    struct nd_ifinfo ndi;
};

struct in6_ndireq nd;

memset(&nd, 0, sizeof(nd));
strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
error = ioctl(s, SIOCGIFINFO_IN6, &nd);
/*
 * Structure of a Link-Level sockaddr:
 */
struct sockaddr_dl {
        u_char  sdl_len;        /* Total length of sockaddr */
        u_char  sdl_family;     /* AF_LINK */
        u_short sdl_index;      /* if != 0, system given index for interface */
        u_char  sdl_type;       /* interface type */
        u_char  sdl_nlen;       /* interface name length, no trailing 0 reqd. */
        u_char  sdl_alen;       /* link level address length */
        u_char  sdl_slen;       /* link layer selector length */
        char    sdl_data[46];   /* minimum work area, can be larger;
                                   contains both if name and ll address */
};
$2  = {sdl_len = 56 '8', sdl_family = 18 (AF_LINK), sdl_index = 1, sdl_type = 0x06 (IFT_ETHER), sdl_nlen = 3, sdl_alen = 6, sdl_slen = 0, sdl_data = "vr0", ...}
$13 = {sdl_len = 56 '8', sdl_family = 18 (AF_LINK), sdl_index = 2, sdl_type = 0x06 (IFT_ETHER), sdl_nlen = 3, sdl_alen = 6, sdl_slen = 0, sdl_data = "vr1", ...}
$14 = {sdl_len = 56 '8', sdl_family = 18 (AF_LINK), sdl_index = 3, sdl_type = 0x06 (IFT_ETHER), sdl_nlen = 3, sdl_alen = 6, sdl_slen = 0, sdl_data = "vr2", ...}
$15 = {sdl_len = 56 '8', sdl_family = 18 (AF_LINK), sdl_index = 4, sdl_type = 0x18 (IFT_LOOP),  sdl_nlen = 3, sdl_alen = 0, sdl_slen = 0, sdl_data = "lo0", ...}
$16 = {sdl_len = 56 '8', sdl_family = 18 (AF_LINK), sdl_index = 5, sdl_type = 0xf6 (IFT_PFLOG), sdl_nlen = 6, sdl_alen = 0, sdl_slen = 0, sdl_data = "pflog0", ...}

sdl->sdl_nlen   /* interface name length, no trailing 0 reqd. */
sdl->sdl_alen   /* link level address length */

sdl->sdl_type:
/usr/include/net/if_types.h
#define	IFT_ETHER	0x6		/* Ethernet CSMA/CD */
#define	IFT_LOOP	0x18		/* loopback */
#define	IFT_PFLOG	0xf6            /* PF firewall */
#define ETH_ALEN	6		/* Octets in one ethernet addr	 */
Linux:

#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */

/* This is a name for the 48 bit ethernet address available on many
   systems.  */
struct ether_addr
{
  u_int8_t ether_addr_octet[ETH_ALEN];
} __attribute__ ((__packed__));


FreeBSD:
/*
* The number of bytes in an	ethernet (MAC) address.
*/
#define ETHER_ADDR_LEN	   6

/*
* Structure	of a 48-bit Ethernet address.
*/
struct  ether_addr {
   u_char octet[ETHER_ADDR_LEN];
};

Do SIOCGIFNUM ioctl to find the number of interfaces

/*
 * Do SIOCGIFNUM ioctl to find the number of interfaces
 *
 * Allocate space for number of interfaces found
 *
 * Do SIOCGIFCONF with allocated buffer
 *
 */
if (ioctl(s, SIOCGIFNUM, (char *)&numifs) == -1) {
    numifs = MAXIFS;
}
bufsize = numifs * sizeof(struct ifreq);
reqbuf = (struct ifreq *) malloc(bufsize);
if (reqbuf == NULL) {
    fprintf(stderr, "out of memory\n");
    exit(1);
}
ifc.ifc_buf = (caddr_t)&reqbuf[0];
ifc.ifc_len = bufsize;
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) == -1) {
    perror("ioctl(SIOCGIFCONF)");
    exit(1);
}

ioctl(sockfd, SIOCGIFCONF, &ifc)



					

Remote Desktop Protocol (RDP) with Ubuntu and XRDP

xrdp – an open-source Remote Desktop Protocol server
github.com/neutrinolabs/xrdp
Xrdp

Tutorials

Using Windows RDP to Access your Ubuntu Instance
How to use xRDP for remote access to Ubuntu 14.04
Ubuntu 14.04 – How to install xrdp in Ubuntu 14.04

XRDP – Quick fix – Custom XRDP install on Ubuntu 15.04 using systemd

$ sudo apt-get install ubuntu-desktop 
$ sudo apt-get install xrdp
$ sudo /etc/init.d/xrdp start
$ sudo adduser USERNAME
$ service xrdp restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Multiple identities can be used for authentication:
 1.  Andreas Bachmann,,, (andreas)
 2.  rdpuser
Choose identity to authenticate as (1-2): Failed to restart xrdp.service: Connection timed out

$ sudo service xrdp restart
A dependency job for xrdp.service failed. See 'journalctl -xe' for details.

# /etc/init.d/xrdp start
[....] Starting xrdp (via systemctl): xrdp.serviceA dependency job for xrdp.service failed. See 'journalctl -xe' for details.
 failed!

# systemctl enable xrdp-sesman.service
Created symlink from /etc/systemd/system/multi-user.target.wants/xrdp-sesman.service to /lib/systemd/system/xrdp-sesman.service.

# systemctl enable xrdp.service
Synchronizing state for xrdp.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d xrdp defaults
Executing /usr/sbin/update-rc.d xrdp enable
# cat /lib/systemd/system/xrdp.service
[Unit]
Description=xrdp daemon
Requires=xrdp-sesman.service
After=syslog.target network.target xrdp-sesman.service

[Service]
Type=forking
PIDFile=/var/run/xrdp.pid
EnvironmentFile=/etc/sysconfig/xrdp
ExecStart=/usr/sbin/xrdp $XRDP_OPTIONS
ExecStop=/usr/sbin/xrdp $XRDP_OPTIONS --kill

[Install]
WantedBy=multi-user.target
# cat /lib/systemd/system/xrdp-sesman.service
[Unit]
Description=xrdp session manager
After=syslog.target network.target
StopWhenUnneeded=true

[Service]
Type=forking
PIDFile=/var/run/xrdp-sesman.pid
EnvironmentFile=/etc/sysconfig/xrdp
ExecStart=/usr/sbin/xrdp-sesman $SESMAN_OPTIONS
ExecStop=/usr/sbin/xrdp-sesman $SESMAN_OPTIONS --kill

[Install]
WantedBy=multi-user.target
### Change in /lib/systemd/system/xrdp.service and /lib/systemd/system/xrdp-sesman.service:
### /etc/sysconfig/xrdp -> /etc/default/xrdp

# service xrdp start
Warning: xrdp.service changed on disk. Run 'systemctl daemon-reload' to reload units.
A dependency job for xrdp.service failed. See 'journalctl -xe' for details.

# systemctl daemon-reload

# service xrdp start
--> Hangs?!

# /usr/sbin/xrdp
# /usr/sbin/xrdp-sesman
--> Works!

# /usr/sbin/xrdp
running in daemon mode with no access to pid files, quitting

# sudo mkdir /var/run/xrdp
# sudo chown xrdp:xrdp /var/run/xrdp

VNC (Virtual Network Computing) with TightVNC and vino-server

TightVNC
TigerVNC
What do I need for remotely accessing my Ubuntu 14.04 machine?
Remote desktop Sharing in Ubuntu 14.04
Cannot connect to vino-server from Windows anymore

Ubuntu Users: VNC
Ubuntu: VNC Server

$ sudo apt-get install vino
$ /usr/lib/vino/vino-server
22/01/2015 11:35:19 [IPv4] Got connection from client andreas.XXX.com
22/01/2015 11:35:19   other clients:
22/01/2015 11:35:19 Client Protocol Version 3.7
22/01/2015 11:35:19 Advertising security type 18
22/01/2015 11:35:20 Client andreas.XXX.com gone
$ gsettings set org.gnome.Vino require-encryption false
22/01/2015 11:43:38 [IPv4] Got connection from client andreas.XXX.com
22/01/2015 11:43:38   other clients:
22/01/2015 11:43:38 Client Protocol Version 3.7
22/01/2015 11:43:38 Advertising security type 18
22/01/2015 11:43:38 Advertising security type 2
22/01/2015 11:43:38 Client returned security type 2

Bitlocker

Encrypt

manage-bde status, Provides information about all drives on the computer; whether or not they are BitLocker-protected.
manage-bde protectors, Manages the protection methods used for the BitLocker encryption key.
Kommandozeilenbefehle für Bitlocker
BitLocker-Wiederherstellungsschlüssel aus ActiveDirectory auslesen

Boot

How to use Windows Vista’s Boot Manager to boot Linux
OpenHiddenSystemDrive
How to Open Windows 7 Hidden System Reserved Partition
BCDEdit (Befehlszeilenoptionen)
Mit bcdedit das Boot-Menü von Windows 7 konfigurieren

1. Create /boot Partition with EXT4, ex. /dev/sda9
2. Extract boot sector
   $ dd if=/dev/sda9 of=/tmp/linux_boot.bin bs=512 count=1
3. Copy 'linux_boot.bin' to USB-Stick
4. Boot Windows with F8-Key pressed
5. Go to the command-line
   bootrec.exe /fixboot
   bootrec.exe /fixmbr
6. Boot Windows normally
7. Find file 'bootmgr' in root directory of 'System Reserved' partition (OpenHiddenSystemDrive64.exe)
8. Copy 'linux_boot.bin' from USB-Stick to root directory beside 'bootmgr'
9. Start BCDEdit (An example of {LinuxID} is {81ed7925-47ee-11db-bd26-cbb4e160eb27})
   bcdedit /create /d “GRUB” /application BOOTSECTOR
   bcdedit /set {LinuxID} device boot
   bcdedit /set {LinuxID}  PATH \linux_boot.bin
   bcdedit /displayorder {LinuxID} /addlast
   bcdedit /timeout 10

Finish!

Building a dual boot system with Windows Vista BitLocker protection with TPM support
How to Multiboot with Bitlocker, TPM, and a Non-Windows OS
BitLocker dual boot – Windows 7 and Fedora
Windows 7 Dual Boot Revisited with Bitlocker

GRUB 2 – Installation
GRUB – Sonderformen der Installation
Boot-Partition
Create Boot-Partition after Install

Die UUID der neuen Partition ermittelt man mittels folgendem Kommando:

$ ls -l /dev/disk/by-uuid

“warning: File system `ext2′ doesn’t support embedding.” but my system isn’t embedded either, why is grub trying?
I need step by step guidence to recover grub [duplicate]

$ mount /dev/sda5 /mnt 
$ mount /dev/sda9 /mnt/boot 
$ mount -o bind /dev /mnt/dev 
$ mount -o bind /sys /mnt/sys 
$ mount -t proc /proc /mnt/proc 
$ chroot /mnt /bin/bash

# grub-install --force /dev/sda9
Installing for i386-pc platform.
grub-install: warning: File system `ext2' doesn't support embedding.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
Installation finished. No error reported.

$ dd if=/dev/sda9 of=/tmp/linux_boot.bin bs=512 count=1

You are getting the warning because you are installing grub to a partition instead of the MBR. This means grub can not be embedded in the unused space between the MBR and the first partition.

BoehmGC: Garbage Collector for C and C++

  • Boehm-Demers-Weiser Conservative GC
  • BoehmGC
  • BDWGC

A garbage collector for C and C++
github: Boehm-Demers-Weiser Garbage Collector v7.5
gitub: Ivan Maidanski
IvMaiSoft by Ivan Maidanski

Garbage collection tuning
Investigation of Boehm’s GC as GCC GC
User: Laurynas Biveinis

Questions on boehm-gc, fragmentation, and low memory resources
Boehm gc in embedded scheme application
Denkwürdige Merkmale der Sprache C: dynamische Speicherreservierung einmal anders
TinyGC
Writing a Simple Garbage Collector in C
Garbage Collection in C Programs, LISP and Java programmers take garbage collection for granted. With the Boehm-Demers-Weiser library, you easily can use it in C and C++ projects, too.

Is there any embeddable lisp or scheme?
ECL – Common Lisp language (look at the GC part!)

Stack-based:
alloca(): Automatic Storage with Variable Size

No, that would not be possible. The fundamental design choice for the BDW
GC is that it is "conservative": it does not know exactly which registers
and local variables contain pointers, so if it were to decide to move heap
objects around, it would have no way to safely patch up all pointers to the
moved objects. (Some of the words that look like pointers to a moved object
might actually be non-pointer data).

In general a collector that moves objects demands either deep integration
with the compiler's code generator (such that every stack frame is marked
up with exact where-are-the-pointers information), or very tight discipline
in the source code of the client program such that moveable pointers are never
stored in local variables across points calls the collector might run. The
latter is probably compatible with programmer sanity only for generated code
and/or when implementing a virtual machine.

FreeBSD as a Bridge

FreeBSD Handbuch: LAN-Kopplung mit einer Bridge

# ifconfig bridge create
bridge0

# ifconfig bridge0
bridge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 96:3d:4b:f1:79:7a
        id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
        maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
        root id 00:00:00:00:00:00 priority 0 ifcost 0 port 0

# ifconfig bridge0 addm fxp0 addm fxp1 up
# ifconfig fxp0 up
# ifconfig fxp1 up

# ifconfig bridge0 deletem fxp0
# ifconfig bridge0 destroy

Remove IPv4 10.16.4.200 from Interface re2
# ifconfig re2 inet 10.16.4.200 -alias
cloned_interfaces="bridge0"
ifconfig_bridge0="addm fxp0 addm fxp1 up"
ifconfig_fxp0="up"
ifconfig_fxp1="up"

Port Mirroring / Span Ports

FreeBSD Network Tap
What is port mirroring?
OpenBSD Network Tap

           ------------------
       re1 |     FreeBSD    | re2
     ------|  (Network Tap) |------
           ------------------
                   | vr0
                   |
                --------  
                |      |
                |  PC  |
                |      |
                --------
           (Traffic Collector)

# ifconfig bridge0 create
# ifconfig bridge0 addm rl0 addm rl1 up
# ifconfig bridge0 span vr0 

nmap – Network exploration tool and security / port scanner

How to find live hosts on my network?

# nmap --iflist

Starting Nmap 6.47 ( http://nmap.org ) at 2015-01-07 11:12 CET
************************INTERFACES************************
DEV     (SHORT)   IP/MASK                       TYPE     UP   MTU   MAC
re0     (re0)     172.21.5.109/21               ethernet up   1500  00:0D:B9:35:88:B4
re1     (re1)     192.168.1.1/24                ethernet up   1500  00:0D:B9:35:88:B5
re1     (re1)     fe80:2::20d:b9ff:fe35:88b5/64 ethernet up   1500  00:0D:B9:35:88:B5
re2     (re2)     10.0.0.1/16                   ethernet up   1500  00:0D:B9:35:88:B6
re2     (re2)     fe80:3::20d:b9ff:fe35:88b6/64 ethernet up   1500  00:0D:B9:35:88:B6
ath0    (ath0)    (none)/0                      ethernet down 2290  04:F0:21:0C:2B:A6
pflog0  (pflog0)  (none)/0                      other    up   33160
pfsync0 (pfsync0) (none)/0                      other    down 1500
lo0     (lo0)     127.0.0.1/8                   loopback up   16384
lo0     (lo0)     ::1/128                       loopback up   16384
lo0     (lo0)     fe80:7::1/64                  loopback up   16384
bridge0 (bridge0) (none)/0                      ethernet up   1500  02:A6:4D:75:47:00

**************************ROUTES**************************
DST/MASK                     DEV METRIC GATEWAY
10.0.0.1/32                  lo0 0
127.0.0.1/32                 lo0 0
172.21.5.109/32              lo0 0
192.168.1.1/32               lo0 0
192.168.1.0/24               re1 0
172.21.0.0/21                re0 0
10.0.0.0/16                  re2 0
0.0.0.0/0                    re0 0      172.21.0.1
fe80::1/128                  lo0 0
::1/128                      lo0 0
fe80::20d:b9ff:fe35:88b6/128 lo0 0
fe80::20d:b9ff:fe35:88b5/128 lo0 0
fe80::/32                    re1 0
ff01::/32                    re2 0      fe80::20d:b9ff:fe35:88b6
fe80::/32                    re2 0
::ffff:0.0.0.0/32            lo0 0      ::1
fe80::/32                    lo0 0
::/32                        lo0 0      ::1
ff01::/32                    re1 0      fe80::20d:b9ff:fe35:88b5
fe80::/32                    lo0 0      ::1
ff01::/32                    lo0 0      ::1
ff02::/32                    lo0 0      ::1
ff02::/32                    re1 0      fe80::20d:b9ff:fe35:88b5
ff02::/32                    re2 0      fe80::20d:b9ff:fe35:88b6
ff02::/32                    lo0 0      ::1
  • -e re2: Only use interface re2
  • -sn: No port scan. Only host discovery.
  • -PS161: TCP SYN Ping to port 161 (SNMP)
# nmap -e re2 -sP -PS161 172.21.6.0/24
Starting Nmap 6.47 ( http://nmap.org ) at 2015-01-07 11:05 CET
Nmap scan report for 172.21.6.29
Host is up (-0.21s latency).
MAC Address: 00:03:F4:04:C7:C7 (NetBurner)
Nmap scan report for 172.21.6.32
Host is up (-0.21s latency).
MAC Address: 00:14:2D:22:F2:74 (Toradex AG)
Nmap scan report for 172.21.6.33
Host is up (-0.21s latency).