src/api/protect/sysinfo-linux.c
long mac_addr_sys ( u_char *addr)
{
/* implementation for Linux */
#ifdef Linux
    struct ifreq ifr;
    struct ifreq *IFR;
    struct ifconf ifc;
    char buf[1024];
    int s, i;
    int ok = 0;

    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s==-1) {
        return -1;
    }

    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;
    ioctl(s, SIOCGIFCONF, &ifc);
 
    IFR = ifc.ifc_req;
    for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {

        strcpy(ifr.ifr_name, IFR->ifr_name);
        if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
            if (! (ifr.ifr_flags & IFF_LOOPBACK)) {
                if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
                    ok = 1;
                    break;
                }
            }
        }
    }

    close(s);
    if (ok) {
        bcopy( ifr.ifr_hwaddr.sa_data, addr, 6);
    }
    else {
        return -1;
    }
    return 0;
#endif

/* implementation for HP-UX */
#ifdef HPUX

#define LAN_DEV0 "/dev/lan0"

    int		fd;
    struct fis	iocnt_block;
    int		i;
    char	net_buf[sizeof(LAN_DEV0)+1];
    char	*p;

    (void)sprintf(net_buf, "%s", LAN_DEV0);
    p = net_buf + strlen(net_buf) - 1;

    /* 
     * Get 802.3 address from card by opening the driver and interrogating it.
     */
    for (i = 0; i < 10; i++, (*p)++) {
        if ((fd = open (net_buf, O_RDONLY)) != -1) {
			iocnt_block.reqtype = LOCAL_ADDRESS;
			ioctl (fd, NETSTAT, &iocnt_block);
			close (fd);

            if (iocnt_block.vtype == 6)
                break;
        }
    }

    if (fd == -1 || iocnt_block.vtype != 6) {
        return -1;
    }

	bcopy( &iocnt_block.value.s[0], addr, 6);
	return 0;

#endif /* HPUX */

/* implementation for AIX */
#ifdef AIX

    int size;
    struct kinfo_ndd *nddp;

    size = getkerninfo(KINFO_NDD, 0, 0, 0);
    if (size <= 0) {
        return -1;
    }
    nddp = (struct kinfo_ndd *)malloc(size);
          
    if (!nddp) {
        return -1;
    }
    if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) {
        free(nddp);
        return -1;
    }
    bcopy(nddp->ndd_addr, addr, 6);
    free(nddp);
    return 0;
#endif

/* Not implemented platforms */
	return -1;
}
/* Reads system Macaddress for a banch of systems : provisional
AIX and HPUX, main function fir Linux Kernels */
Reads system Macaddress for a banch of systems : provisional
AIX and HPUX, main function fir Linux Kernels
Reads system Macaddress for a banch of systems : provisional AIX and HPUX main function fir Linux Kernels
long mac_addr_sys ( u_char *addr)
{
#ifdef Linux
    struct ifreq ifr;
    struct ifreq *IFR;
    struct ifconf ifc;
    char buf[1024];
    int s, i;
    int ok = 0;
    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s==-1) {
        return -1;
    }
    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;
    ioctl(s, SIOCGIFCONF, &ifc);
    IFR = ifc.ifc_req;
    for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {
        strcpy(ifr.ifr_name, IFR->ifr_name);
        if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
            if (! (ifr.ifr_flags & IFF_LOOPBACK)) {
                if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
                    ok = 1;
                    break;
                }
            }
        }
    }
    close(s);
    if (ok) {
        bcopy( ifr.ifr_hwaddr.sa_data, addr, 6);
    }
    else {
        return -1;
    }
    return 0;
#endif
#ifdef HPUX
#define LAN_DEV0 "/dev/lan0"
    int		fd;
    struct fis	iocnt_block;
    int		i;
    char	net_buf[sizeof(LAN_DEV0)+1];
    char	*p;
    (void)sprintf(net_buf, "%s", LAN_DEV0);
    p = net_buf + strlen(net_buf) - 1;
    for (i = 0; i < 10; i++, (*p)++) {
        if ((fd = open (net_buf, O_RDONLY)) != -1) {
			iocnt_block.reqtype = LOCAL_ADDRESS;
			ioctl (fd, NETSTAT, &iocnt_block);
			close (fd);
            if (iocnt_block.vtype == 6)
                break;
        }
    }
    if (fd == -1 || iocnt_block.vtype != 6) {
        return -1;
    }
	bcopy( &iocnt_block.value.s[0], addr, 6);
	return 0;
#endif 
#ifdef AIX
    int size;
    struct kinfo_ndd *nddp;
    size = getkerninfo(KINFO_NDD, 0, 0, 0);
    if (size <= 0) {
        return -1;
    }
    nddp = (struct kinfo_ndd *)malloc(size);
    if (!nddp) {
        return -1;
    }
    if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) {
        free(nddp);
        return -1;
    }
    bcopy(nddp->ndd_addr, addr, 6);
    free(nddp);
    return 0;
#endif
	return -1;
}
long mac_addr_sys ( u_char * addr ) { #ifdef Linux struct ifreq ifr ; struct ifreq * IFR ; struct ifconf ifc ; char buf [ 1024 ] ; int s , i ; int ok = 0 ; s = socket ( AF_INET , SOCK_DGRAM , 0 ) ; if ( s == -1 ) { return -1 ; } ifc . ifc_len = sizeof ( buf ) ; ifc . ifc_buf = buf ; ioctl ( s , SIOCGIFCONF , & ifc ) ; IFR = ifc . ifc_req ; for ( i = ifc . ifc_len / sizeof ( struct ifreq ) ; -- i >= 0 ; IFR ++ ) { strcpy ( ifr . ifr_name , IFR -> ifr_name ) ; if ( ioctl ( s , SIOCGIFFLAGS , & ifr ) == 0 ) { if ( ! ( ifr . ifr_flags & IFF_LOOPBACK ) ) { if ( ioctl ( s , SIOCGIFHWADDR , & ifr ) == 0 ) { ok = 1 ; break ; } } } } close ( s ) ; if ( ok ) { bcopy ( ifr . ifr_hwaddr . sa_data , addr , 6 ) ; } else { return -1 ; } return 0 ; #endif #ifdef HPUX #define LAN_DEV0  "/dev/lan0" int fd ; struct fis iocnt_block ; int i ; char net_buf [ sizeof ( LAN_DEV0 ) + 1 ] ; char * p ; ( void ) sprintf ( net_buf , " " , LAN_DEV0 ) ; p = net_buf + strlen ( net_buf ) - 1 ; for ( i = 0 ; i < 10 ; i ++ , ( * p ) ++ ) { if ( ( fd = open ( net_buf , O_RDONLY ) ) != -1 ) { iocnt_block . reqtype = LOCAL_ADDRESS ; ioctl ( fd , NETSTAT , & iocnt_block ) ; close ( fd ) ; if ( iocnt_block . vtype == 6 ) break ; } } if ( fd == -1 || iocnt_block . vtype != 6 ) { return -1 ; } bcopy ( & iocnt_block . value . s [ 0 ] , addr , 6 ) ; return 0 ; #endif #ifdef AIX int size ; struct kinfo_ndd * nddp ; size = getkerninfo ( KINFO_NDD , 0 , 0 , 0 ) ; if ( size <= 0 ) { return -1 ; } nddp = ( struct kinfo_ndd * ) malloc ( size ) ; if ( ! nddp ) { return -1 ; } if ( getkerninfo ( KINFO_NDD , nddp , & size , 0 ) < 0 ) { free ( nddp ) ; return -1 ; } bcopy ( nddp -> ndd_addr , addr , 6 ) ; free ( nddp ) ; return 0 ; #endif return -1 ; }
Reads system Macaddress for a banch of systems : provisional
AIX and HPUX, main function fir Linux Kernels
Reads system Macaddress for a banch of systems : provisional AIX and HPUX main function fir Linux Kernels
/* implementation for Linux */ /* implementation for HP-UX */ /* 
     * Get 802.3 address from card by opening the driver and interrogating it.
     */ /* HPUX */ /* implementation for AIX */ /* Not implemented platforms */