diff options
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | isys/Makefile | 4 | ||||
-rw-r--r-- | isys/getmacaddr.c | 81 | ||||
-rw-r--r-- | isys/getmacaddr.h | 6 | ||||
-rw-r--r-- | isys/isys.c | 5 | ||||
-rw-r--r-- | isys/nl.c | 14 | ||||
-rw-r--r-- | loader2/Makefile | 5 | ||||
-rw-r--r-- | loader2/net.c | 14 | ||||
-rw-r--r-- | loader2/urlinstall.c | 4 |
9 files changed, 48 insertions, 108 deletions
@@ -1,3 +1,26 @@ +2006-05-26 David Cantrell <dcantrell@redhat.com> + + * isys/Makefile: Remove getmacaddr references. Add glib CFLAGS and + LDFLAGS. + + * isys/getmacaddr.c: Removed. + * isys/getmacaddr.h: Removed. + + * isys/isys.c: Call netlink_interfaces_mac2str() in doGetMacAddress. + + * isys/nl.c (netlink_format_mac_addr): Malloc space for buf if it's + NULL when we enter the function. + * isys/nl.c (netlink_interfaces_mac2str): Return buffer malloc is + handled by netlink_format_mac_addr). + + * loader2/Makefile: Add glib CFLAGS and LDFLAGS. + + * loader2/net.c: Call netlink_format_mac_addr() and + netlink_interfaces_mac2str(). + + * loader2/urlinstall.c: Call netlink_interfaces_mac2str() instead of + getMacAddr(). + 2006-05-25 Chris Lumens <clumens@redhat.com> * anaconda.spec: Bump version. diff --git a/isys/Makefile b/isys/Makefile index 3ebb0e9b5..36c0b530b 100644 --- a/isys/Makefile +++ b/isys/Makefile @@ -2,7 +2,7 @@ include ../Makefile.inc CFLAGS += -I$(PYTHONINCLUDE) -I.. -DHAVE_NFS -OBJECTS = nfsmount.o nfsmount_clnt.o nfsmount_xdr.o imount.o getmacaddr.o \ +OBJECTS = nfsmount.o nfsmount_clnt.o nfsmount_xdr.o imount.o \ smp.o devnodes.o cpio.o uncpio.o dasd.o \ lang.o isofs.o dns.o linkdetect.o vio.o \ ethtool.o getipaddr.o wireless.o eddsupport.o \ @@ -15,7 +15,7 @@ PYMODULES = _isys.so SUBDIRS = gzlib DIET = diet -# using glib +# glib LOADLIBES += $(shell pkg-config --libs glib-2.0) CFLAGS += $(shell pkg-config --cflags glib-2.0) diff --git a/isys/getmacaddr.c b/isys/getmacaddr.c deleted file mode 100644 index de923819f..000000000 --- a/isys/getmacaddr.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * getmacaddr.c - get mac address for ethernet interface - * - * Copyright 2003-2004 Red Hat, Inc. - * - * Michael Fulbright <msf@redhat.com> - * Jeremy Katz <katzj@redhat.com> - * - * This software may be freely redistributed under the terms of the GNU - * general public license. - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <sys/ioctl.h> -#include <net/if.h> - -/* returns NULL or allocated string */ -char *getMacAddr(char *ifname) { - int i; - int sock; - char *rcstr; - struct ifreq ifr; - - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return NULL; - - /* Setup our control structures. */ - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, ifname); - - if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) - return NULL; - - rcstr = (char *) malloc(24); - *rcstr = '\0'; - for (i=0; i<6; i++) { - char tmp[4]; - sprintf(tmp, "%02X",(unsigned char)ifr.ifr_hwaddr.sa_data[i]); - strcat(rcstr,tmp); - if (i != 5) - strcat(rcstr, ":"); - } - - return rcstr; -} - -/* returns NULL or allocated string */ -char * sanitizeMacAddr(char * hwaddr) { - char * rcstr; - int i = 0, j = 0; - - if (!hwaddr) - return NULL; - rcstr = (char *) malloc(24); - for (i = 0; hwaddr[i] && (j < 24); i++) { - if (isdigit(hwaddr[i])) - rcstr[j++] = hwaddr[i]; - else if (('A' <= hwaddr[i]) && ('F' >= hwaddr[i])) - rcstr[j++] = hwaddr[i]; - else if (('a' <= hwaddr[i]) && ('f' >= hwaddr[i])) - rcstr[j++] = toupper(hwaddr[i]); - } - rcstr[j] = '\0'; - - return rcstr; -} - -#ifdef TESTING -int main() { - - printf("%s\n", getMacAddr("eth0")); -} -#endif diff --git a/isys/getmacaddr.h b/isys/getmacaddr.h deleted file mode 100644 index a4d374559..000000000 --- a/isys/getmacaddr.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __GET_MAC_ADDR_H__ -#define __GET_MAC_ADDR_H__ -char *getMacAddr(char *ifname); -char *sanitizeMacAddr(char * hwaddr); -#endif - diff --git a/isys/isys.c b/isys/isys.c index a25d39b05..5359987d9 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -49,13 +49,12 @@ #include <signal.h> #include <execinfo.h> - +#include "nl.h" #include "imount.h" #include "isys.h" #include "net.h" #include "smp.h" #include "lang.h" -#include "getmacaddr.h" #include "wireless.h" #include "eddsupport.h" @@ -1264,7 +1263,7 @@ static PyObject * doGetMacAddress(PyObject * s, PyObject * args) { if (!PyArg_ParseTuple(args, "s", &dev)) return NULL; - ret = getMacAddr(dev); + ret = netlink_interfaces_mac2str(dev); return Py_BuildValue("s", ret); } @@ -45,6 +45,13 @@ static GSList *interfaces = NULL; char *netlink_format_mac_addr(char *buf, unsigned char *mac) { int i; + if (buf == NULL) { + if ((buf = malloc(20)) == NULL) { + perror("malloc in netlink_format_mac_addr"); + return NULL; + } + } + sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -361,7 +368,7 @@ int netlink_init_interfaces_list(void) { * on error. */ char *netlink_interfaces_mac2str(char *ifname) { - char *ret; + char *ret = NULL; GSList *e; interface_info_t *intf; @@ -380,11 +387,6 @@ char *netlink_interfaces_mac2str(char *ifname) { if (e == NULL) { return NULL; } else { - if ((ret=malloc(20)) == NULL) { - perror("malloc in netlink_interfaces_mac2str"); - return NULL; - } - intf = (interface_info_t *) e->data; ret = netlink_format_mac_addr(ret, intf->mac); return ret; diff --git a/loader2/Makefile b/loader2/Makefile index 5528c4abe..efb951c15 100644 --- a/loader2/Makefile +++ b/loader2/Makefile @@ -7,6 +7,9 @@ else TARGET=depend $(PROGS) endif +GLIB = /lib/libglib-2.0.a +CFLAGS += $(shell pkg-config --cflags glib-2.0) + SLANGLIB = -lslang NEWTLIB = -lnewt ISYSLIB = ../isys/libisys.a @@ -118,7 +121,7 @@ loader-net.o: loader.c loader: loader.o $(OBJS) $(NETOBJS) $(CC) -g $(STATIC) -o $@ $^ -lpopt \ $(HWLIBS) $(ISYSLIB) $(GUNZIP) $(UNICODELIB) \ - -lpump -lresolv $(NEWTLIB) $(SLANGLIB) $(DMLIB) + -lpump -lresolv $(NEWTLIB) $(SLANGLIB) $(DMLIB) $(GLIB) clean: rm -f *.o *~ .depend init ctype.c mkctype \ diff --git a/loader2/net.c b/loader2/net.c index 9d668b908..fc0d0ba68 100644 --- a/loader2/net.c +++ b/loader2/net.c @@ -37,7 +37,7 @@ #include "../isys/isys.h" #include "../isys/net.h" #include "../isys/wireless.h" -#include "../isys/getmacaddr.h" +#include "../isys/nl.h" #include "lang.h" #include "loader.h" @@ -1017,11 +1017,11 @@ int chooseNetworkInterface(struct loaderData_s * loaderData, devices = alloca((i + 1) * sizeof(*devices)); deviceNames = alloca((i + 1) * sizeof(*devices)); if (loaderData->netDev && (loaderData->netDev_set) == 1) { - if ((loaderData->bootIf && (loaderData->bootIf_set) == 1) && - !strcasecmp(loaderData->netDev, "bootif")) - ksMacAddr = sanitizeMacAddr(loaderData->bootIf); - else - ksMacAddr = sanitizeMacAddr(loaderData->netDev); + if ((loaderData->bootIf && (loaderData->bootIf_set) == 1) && !strcasecmp(loaderData->netDev, "bootif")) { + ksMacAddr = netlink_format_mac_addr(ksMacAddr, (unsigned char *) loaderData->bootIf); + } else { + ksMacAddr = netlink_format_mac_addr(ksMacAddr, (unsigned char *) loaderData->netDev); + } } for (i = 0; devs[i]; i++) { @@ -1048,7 +1048,7 @@ int chooseNetworkInterface(struct loaderData_s * loaderData, } else if (ksMacAddr != NULL) { /* maybe it's a mac address */ char * devmacaddr; - devmacaddr = sanitizeMacAddr(getMacAddr(devs[i]->device)); + devmacaddr = netlink_interfaces_mac2str(devs[i]->device); if ((devmacaddr != NULL) && !strcmp(ksMacAddr, devmacaddr)) { foundDev = 1; free(loaderData->netDev); diff --git a/loader2/urlinstall.c b/loader2/urlinstall.c index 77be23941..d35460391 100644 --- a/loader2/urlinstall.c +++ b/loader2/urlinstall.c @@ -23,7 +23,7 @@ #include <sys/mount.h> #include <unistd.h> -#include "../isys/getmacaddr.h" +#include "../isys/nl.h" #include "kickstart.h" #include "loader.h" @@ -388,7 +388,7 @@ int getFileFromUrl(char * url, char * dest, devices = probeDevices(CLASS_NETWORK, BUS_UNSPEC, PROBE_LOADED); for (i = 0; devices && devices[i]; i++) { dev = devices[i]->device; - mac = getMacAddr(dev); + mac = netlink_interfaces_mac2str(dev); if (mac) { snprintf(tmpstr, sizeof(tmpstr), "X-RHN-Provisioning-MAC-%d: %s %s\r\n", i, dev, mac); |