mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
4736d0fe99
Simple optimzations and cleanups Removed compiler warnings and fixed portability issues Added client functions 'mysql_embedded()' to allow client to check if we are using embedded server Fixes for purify client/mysqlimport.c: Remove not used variable client/mysqltest.c: Remove usage of MAXPATHLEN (all MySQL code uses FN_REFLEN) Simplified code Remove usage of sprintf("%llu") as this is not portable include/mysql.h: Added mysql_embedded() to be able to easily check if we are using the embedded server innobase/srv/srv0start.c: Don't use memcmp() when using purify (to avoid false warnings) libmysql/libmysql.c: Added mysql_embedded() to be able to easily check if we are using the embedded server libmysql/libmysql.def: Added mysql_embedded() to be able to easily check if we are using the embedded server myisam/myisam_ftdump.c: Remove compiler warning myisam/myisamchk.c: Remove compiler warning myisam/rt_test.c: #ifdef not used code mysys/hash.c: Remove compiler warning (from last push) mysys/my_gethwaddr.c: Remove compiler warning ndb/src/ndbapi/ndberror.c: #ifdef not used code regex/regcomp.c: Remove not used code regex/regcomp.ih: Remove not used code (to remove compiler warnings) sql-common/client.c: Remove compiler warnings sql/field.cc: Simple optimization sql/ha_innodb.cc: Rename mysql_embedded -> mysqld_embedded sql/item.cc: Fix comments Move variables first on block Remove else after return Simple optimizations (no logic changes) sql/item_cmpfunc.cc: Added comment sql/mysql_priv.h: Rename mysql_embedded -> mysqld_embedded sql/mysqld.cc: Rename mysql_embedded -> mysqld_embedded sql/sql_acl.cc: Added comments simple optimization Fixed 'very unlikely' bug when doing REVOKE ALL PRIVILEGES sql/sql_select.cc: More comments Simple optimization sql/sql_show.cc: Simple changes to make similar code similar More comments sql/sql_string.cc: Trivial optimization and better code layout strings/Makefile.am: Change xml.c to use bcmp to avoid warnings from purify strings/xml.c: Change xml.c to use bcmp to avoid warnings from purify tests/client_test.c: Remove usage of MAXPATHLEN (all MySQL code uses FN_REFLEN)
130 lines
2.9 KiB
C
130 lines
2.9 KiB
C
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/* get hardware address for an interface */
|
|
/* if there are many available, any non-zero one can be used */
|
|
|
|
#include "mysys_priv.h"
|
|
#include <m_string.h>
|
|
|
|
#ifndef MAIN
|
|
static my_bool memcpy_and_test(uchar *to, uchar *from, uint len)
|
|
{
|
|
uint i, res=1;
|
|
|
|
for (i=0; i < len; i++)
|
|
if ((*to++= *from++))
|
|
res=0;
|
|
return res;
|
|
}
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <net/ethernet.h>
|
|
#include <sys/sysctl.h>
|
|
#include <net/route.h>
|
|
#include <net/if.h>
|
|
#include <net/if_dl.h>
|
|
|
|
my_bool my_gethwaddr(uchar *to)
|
|
{
|
|
size_t len;
|
|
uchar *buf, *next, *end, *addr;
|
|
struct if_msghdr *ifm;
|
|
struct sockaddr_dl *sdl;
|
|
int i, res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0};
|
|
|
|
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
|
|
goto err;
|
|
if (!(buf = alloca(len)))
|
|
goto err;
|
|
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
|
|
goto err;
|
|
|
|
end = buf + len;
|
|
|
|
for (next = buf ; res && next < end ; next += ifm->ifm_msglen)
|
|
{
|
|
ifm = (struct if_msghdr *)next;
|
|
if (ifm->ifm_type == RTM_IFINFO)
|
|
{
|
|
sdl = (struct sockaddr_dl *)(ifm + 1);
|
|
addr=LLADDR(sdl);
|
|
res=memcpy_and_test(to, addr, ETHER_ADDR_LEN);
|
|
}
|
|
}
|
|
|
|
err:
|
|
return res;
|
|
}
|
|
|
|
#elif __linux__
|
|
|
|
#include <net/if.h>
|
|
#include <sys/ioctl.h>
|
|
#include <net/ethernet.h>
|
|
|
|
my_bool my_gethwaddr(uchar *to)
|
|
{
|
|
int fd, res=1;
|
|
struct ifreq ifr;
|
|
|
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
if (fd < 0)
|
|
goto err;
|
|
|
|
bzero(&ifr, sizeof(ifr));
|
|
strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
|
|
|
|
do {
|
|
if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
|
|
res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
|
|
} while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
|
|
|
|
close(fd);
|
|
err:
|
|
return res;
|
|
}
|
|
|
|
#else
|
|
/* just fail */
|
|
my_bool my_gethwaddr(uchar *to __attribute__((unused)))
|
|
{
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
#else /* MAIN */
|
|
int main(int argc __attribute__((unused)),char **argv)
|
|
{
|
|
uchar mac[6];
|
|
uint i;
|
|
MY_INIT(argv[0]);
|
|
if (my_gethwaddr(mac))
|
|
{
|
|
printf("my_gethwaddr failed with errno %d\n", errno);
|
|
exit(1);
|
|
}
|
|
for (i=0; i < sizeof(mac); i++)
|
|
{
|
|
if (i) printf(":");
|
|
printf("%02x", mac[i]);
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
}
|
|
#endif
|
|
|