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 2213 : tds_getmac(TDS_SYS_SOCKET s TDS_UNUSED, 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 2213 : memset(mac, 0, 6);
56 :
57 2213 : ifc.ifc_len = sizeof(buf);
58 2213 : ifc.ifc_buf = buf;
59 2213 : ioctl(s, SIOCGIFCONF, &ifc);
60 :
61 2213 : IFR = ifc.ifc_req;
62 4426 : for (i = ifc.ifc_len / (int)sizeof(struct ifreq); --i >= 0; ++IFR) {
63 :
64 4426 : strcpy(ifr.ifr_name, IFR->ifr_name);
65 4426 : if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
66 4426 : if (!(ifr.ifr_flags & IFF_LOOPBACK)) {
67 2213 : if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
68 2213 : memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
69 2213 : break;
70 : }
71 : }
72 : }
73 : }
74 : #else /* !defined(__linux__) */
75 : memset(mac, 0, 6);
76 : #endif
77 2213 : }
|