~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_gethwaddr.c

Renamed strings to mystrings, for include/lib naming consistency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/* if there are many available, any non-zero one can be used */
18
18
 
19
19
#include "mysys_priv.h"
20
 
#include <mystrings/m_string.h>
 
20
#include <m_string.h>
21
21
 
22
22
#ifndef MAIN
23
23
 
24
24
#if defined(__FreeBSD__) || defined(__linux__)
25
 
static bool memcpy_and_test(unsigned char *to, unsigned char *from, uint32_t len)
 
25
static bool memcpy_and_test(uchar *to, uchar *from, uint len)
26
26
{
27
 
  uint32_t i, res=1;
 
27
  uint i, res=1;
28
28
 
29
29
  for (i=0; i < len; i++)
30
30
    if ((*to++= *from++))
41
41
#include <net/if.h>
42
42
#include <net/if_dl.h>
43
43
 
44
 
bool my_gethwaddr(unsigned char *to)
 
44
bool my_gethwaddr(uchar *to)
45
45
{
46
46
  size_t len;
47
 
  unsigned char  *buf, *next, *end, *addr;
 
47
  uchar  *buf, *next, *end, *addr;
48
48
  struct if_msghdr *ifm;
49
49
  struct sockaddr_dl *sdl;
50
50
  int i, res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0};
79
79
#include <sys/ioctl.h>
80
80
#include <net/ethernet.h>
81
81
 
82
 
bool my_gethwaddr(unsigned char *to)
 
82
bool my_gethwaddr(uchar *to)
83
83
{
84
84
  int fd, res=1;
85
85
  struct ifreq ifr;
88
88
  if (fd < 0)
89
89
    goto err;
90
90
 
91
 
  memset(&ifr, 0, sizeof(ifr));
92
 
  my_stpncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
 
91
  bzero(&ifr, sizeof(ifr));
 
92
  strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
93
93
 
94
94
  do {
95
95
    if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
96
 
      res=memcpy_and_test(to, (unsigned char *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
 
96
      res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
97
97
  } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
98
98
 
99
99
  close(fd);
103
103
 
104
104
#else   /* FreeBSD elif linux */
105
105
/* just fail */
106
 
bool my_gethwaddr(unsigned char *to __attribute__((unused)))
 
106
bool my_gethwaddr(uchar *to __attribute__((unused)))
107
107
{
108
108
  return 1;
109
109
}
112
112
#else /* MAIN */
113
113
int main(int argc __attribute__((unused)),char **argv)
114
114
{
115
 
  unsigned char mac[6];
116
 
  uint32_t i;
 
115
  uchar mac[6];
 
116
  uint i;
117
117
  MY_INIT(argv[0]);
118
118
  if (my_gethwaddr(mac))
119
119
  {