diff options
author | Jeremy Katz <katzj@redhat.com> | 2003-09-20 03:31:26 +0000 |
---|---|---|
committer | Jeremy Katz <katzj@redhat.com> | 2003-09-20 03:31:26 +0000 |
commit | 31f1add4879da48efb7af21fc5c575692cc3709d (patch) | |
tree | 7a541b8f54f91ed8309da17752e205b40db2cf30 /isys/getipaddr.c | |
parent | 8307d33391423f13c1deed409b80d8e381582a93 (diff) | |
download | anaconda-31f1add4879da48efb7af21fc5c575692cc3709d.tar.gz anaconda-31f1add4879da48efb7af21fc5c575692cc3709d.tar.xz anaconda-31f1add4879da48efb7af21fc5c575692cc3709d.zip |
merge from taroon
fairly large merge, but all fairly obvious stuff. will test in a tree tomorrow
Diffstat (limited to 'isys/getipaddr.c')
-rw-r--r-- | isys/getipaddr.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/isys/getipaddr.c b/isys/getipaddr.c new file mode 100644 index 000000000..712374206 --- /dev/null +++ b/isys/getipaddr.c @@ -0,0 +1,52 @@ +/* + * getmacaddr.c - get mac address for ethernet interface + * + * Copyright 2003 Red Hat, Inc. + * + * Michael Fulbright <msf@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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <net/if.h> +#include <netinet/in.h> + + +/* returns NULL or allocated string */ +char *getIPAddr(char *ifname) { + 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, SIOCGIFADDR, &ifr) < 0) + return NULL; + + rcstr = strdup(inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr)); + return rcstr; +} + +#ifdef TESTING +int main() { + + printf("%s\n", getIPAddr("eth0")); +} +#endif |