LCOV - code coverage report
Current view: top level - src/tds - getmac.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 14 14 100.0 %
Date: 2025-01-18 12:13:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998-2002  Brian Bruns
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : 
      22             : #include <stdarg.h>
      23             : #include <stdio.h>
      24             : 
      25             : #if HAVE_STDLIB_H
      26             : #include <stdlib.h>
      27             : #endif /* HAVE_STDLIB_H */
      28             : 
      29             : #if HAVE_STRING_H
      30             : #include <string.h>
      31             : #endif /* HAVE_STRING_H */
      32             : 
      33             : #include <freetds/tds.h>
      34             : 
      35             : #ifdef __linux__
      36             : #include <sys/ioctl.h>
      37             : #include <sys/types.h>
      38             : #include <sys/socket.h>
      39             : #include <netinet/in.h>
      40             : #include <linux/if.h>
      41             : #endif
      42             : 
      43             : /* TODO get real MAC */
      44             : void
      45        2172 : tds_getmac(TDS_SYS_SOCKET s, unsigned char mac[6])
      46             : {
      47             : /* implementation for Linux */
      48             : #ifdef __linux__
      49             :         struct ifreq ifr;
      50             :         struct ifreq *IFR;
      51             :         struct ifconf ifc;
      52             :         char buf[1024];
      53             :         int i;
      54             : 
      55        2172 :         memset(mac, 0, 6);
      56             : 
      57        2172 :         ifc.ifc_len = sizeof(buf);
      58        2172 :         ifc.ifc_buf = buf;
      59        2172 :         ioctl(s, SIOCGIFCONF, &ifc);
      60             : 
      61        2172 :         IFR = ifc.ifc_req;
      62        4344 :         for (i = ifc.ifc_len / (int)sizeof(struct ifreq); --i >= 0; ++IFR) {
      63             : 
      64        4344 :                 strcpy(ifr.ifr_name, IFR->ifr_name);
      65        4344 :                 if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
      66        4344 :                         if (!(ifr.ifr_flags & IFF_LOOPBACK)) {
      67        2172 :                                 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
      68        2172 :                                         memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
      69        2172 :                                         break;
      70             :                                 }
      71             :                         }
      72             :                 }
      73             :         }
      74             : #else /* !defined(__linux__) */
      75             :         memset(mac, 0, 6);
      76             : #endif
      77        2172 : }

Generated by: LCOV version 1.13