diff options
author | Matt Wilson <msw@redhat.com> | 1999-06-25 02:14:00 +0000 |
---|---|---|
committer | Matt Wilson <msw@redhat.com> | 1999-06-25 02:14:00 +0000 |
commit | 7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1 (patch) | |
tree | 5529c0a93291af7f86423d3eec5c64425b977a0c /isys | |
parent | 79babd8fb43cfd0f73633a42f175398fedf5f7a5 (diff) | |
download | anaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.tar.gz anaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.tar.xz anaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.zip |
new methods
Diffstat (limited to 'isys')
-rw-r--r-- | isys/inet.c | 106 | ||||
-rw-r--r-- | isys/inet.h | 21 |
2 files changed, 127 insertions, 0 deletions
diff --git a/isys/inet.c b/isys/inet.c new file mode 100644 index 000000000..b31dbc3cb --- /dev/null +++ b/isys/inet.c @@ -0,0 +1,106 @@ +#include <sys/socket.h> +#include <arpa/inet.h> +#include <net/if.h> +#include <net/route.h> +#include <sys/ioctl.h> + +#include "inet.h" + +int configureNetDevice(struct intfInfo * intf) { + struct ifreq req; + int s; + struct sockaddr_in addr; + struct in_addr ia; + char ip[20], nm[20], nw[20], bc[20]; +#if 0 /* 2.0 kernels only */ + struct rtentry route; +#endif + + addr.sin_family = AF_INET; + addr.sin_port = 0; + + memcpy(&ia, &intf->ip, sizeof(intf->ip)); + strcpy(ip, inet_ntoa(ia)); + + memcpy(&ia, &intf->netmask, sizeof(intf->netmask)); + strcpy(nm, inet_ntoa(ia)); + + memcpy(&ia, &intf->broadcast, sizeof(intf->broadcast)); + strcpy(bc, inet_ntoa(ia)); + + memcpy(&ia, &intf->network, sizeof(intf->network)); + strcpy(nw, inet_ntoa(ia)); + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + return 1; + } + + strcpy(req.ifr_name, intf->device); + req.ifr_flags &= ~(IFF_UP | IFF_RUNNING); /* Take down iface */ + if (ioctl(s, SIOCSIFFLAGS, &req)) { + perror("SIOCSIFFLAGS"); + close(s); + return 1; + } + + addr.sin_port = 0; + memcpy(&addr.sin_addr, &intf->ip, sizeof(intf->ip)); + memcpy(&req.ifr_addr, &addr, sizeof(addr)); + if (ioctl(s, SIOCSIFADDR, &req)) { + perror("SIOCSIFADDR"); + close(s); + return 1; + } + + memcpy(&addr.sin_addr, &intf->broadcast, sizeof(intf->broadcast)); + memcpy(&req.ifr_broadaddr, &addr, sizeof(addr)); + if (ioctl(s, SIOCSIFBRDADDR, &req)) { + perror("SIOCSIFNETMASK"); + close(s); + return 1; + } + + memcpy(&addr.sin_addr, &intf->netmask, sizeof(intf->netmask)); + memcpy(&req.ifr_netmask, &addr, sizeof(addr)); + if (ioctl(s, SIOCSIFNETMASK, &req)) { + perror("SIOCSIFNETMASK\n"); + close(s); + return 1; + } + + if (intf->isPtp) + req.ifr_flags = IFF_UP | IFF_RUNNING | IFF_POINTOPOINT | IFF_NOARP; + else + req.ifr_flags = IFF_UP | IFF_RUNNING | IFF_BROADCAST; + + if (ioctl(s, SIOCSIFFLAGS, &req)) { + perror("SIOCSIFFLAGS"); + close(s); + return 1; + } + +#if 0 /* kernel 2.0 only */ + memset(&route, 0, sizeof(route)); + route.rt_dev = intf->device; + route.rt_flags = RTF_UP; + + memcpy(&addr.sin_addr, &intf->network, sizeof(intf->netmask)); + memcpy(&route.rt_dst, &addr, sizeof(addr)); + + memcpy(&addr.sin_addr, &intf->netmask, sizeof(intf->netmask)); + memcpy(&route.rt_genmask, &addr, sizeof(addr)); + + if (ioctl(s, SIOCADDRT, &route)) { + perror("SIOCADDRT"); + close(s); + return 1; + + } +#endif + + intf->isUp = 1; + + return 0; +} diff --git a/isys/inet.h b/isys/inet.h new file mode 100644 index 000000000..2f467f4cc --- /dev/null +++ b/isys/inet.h @@ -0,0 +1,21 @@ +#ifndef _INET_H_ +#define _INET_H_ + +#include <netinet/in.h> + +#define INET_ERR_ERRNO 1 +#define INET_ERR_OTHER 2 + +struct intfInfo { + char device[10]; + int isPtp, isUp; + int set, manuallySet; + struct in_addr ip, netmask, broadcast, network; + struct in_addr bootServer; + char * bootFile; + int bootProto; +}; + +int configureNetDevice(struct intfInfo * intf); + +#endif /* _INET_H_ */ |