summaryrefslogtreecommitdiffstats
path: root/isys/inet.c
diff options
context:
space:
mode:
authorMatt Wilson <msw@redhat.com>1999-06-25 02:14:00 +0000
committerMatt Wilson <msw@redhat.com>1999-06-25 02:14:00 +0000
commit7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1 (patch)
tree5529c0a93291af7f86423d3eec5c64425b977a0c /isys/inet.c
parent79babd8fb43cfd0f73633a42f175398fedf5f7a5 (diff)
downloadanaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.tar.gz
anaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.tar.xz
anaconda-7e82cc2de02a546a60d33ad20c7b11cd7c63b3f1.zip
new methods
Diffstat (limited to 'isys/inet.c')
-rw-r--r--isys/inet.c106
1 files changed, 106 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;
+}