3 * Copied and hacked from loattach.c which was:
5 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
6 * Copyright (C) 1999 Greg Ungerer <gerg@snapgear.com>
7 * Copyright (C) 1999 D. Jeff Dionne <jeff@lineo.ca>
8 * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
21 #include <sys/types.h>
30 #include <linux/sockios.h>
31 #include <linux/socket.h>
34 #include <linux/icmp.h>
35 #include <linux/route.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
43 usage(char *name, int rc)
45 fprintf(stderr, "usage: %s --addr x.x.x.x [--mask x.x.x.x] "
46 "[--net x.x.x.x] [--gw x.x.x.x] [--if x] [--verbose] [--help]\n"
47 "usage: %s --addr x.x.x.x [--mask x.x.x.x] "
48 "[--net x.x.x.x] [--gw x.x.x.x] iface\n",name,name);
52 int main(int argc, char *argv[])
60 struct sockaddr_in *in;
65 char* ipAddr = "127.0.0.1";
66 char* ipMask = "255.0.0.0";
67 char* ipNet = "127.0.0.0";
68 char* ipGateway = NULL;
71 for(i=1; i<argc; i++) {
72 if (!strcmp(argv[i], "--addr")) {
74 } else if (!strcmp(argv[i], "--net")) {
76 } else if (!strcmp(argv[i], "--mask")) {
78 } else if (!strcmp(argv[i], "--gw")) {
79 ipGateway = argv[++i];
80 } else if (!strcmp(argv[i], "--verbose")) {
82 } else if (!strcmp(argv[i], "--if")) {
84 } else if (argc == i+1) {
87 usage(argv[0], strcmp(argv[i], "--help"));
94 if ((ipAddr == NULL) && (ipGateway == NULL))
98 printf("%s: address: %s, mask: %s, net: %s, gateway: %s\n",
99 dev, ipAddr, ipMask, ipNet, ipGateway);
100 setifaddr(dev, ipAddr);
101 setifflags(dev, IFF_UP | IFF_RUNNING);
103 addroute(dev, RTF_UP/* | RTF_HOST*/,
104 ipNet /* dest net */,
105 ipMask /* netmask */,
109 addroute(dev, RTF_UP/* | RTF_HOST*/,
110 "0.0.0.0" /* dest net */,
111 "0.0.0.0" /* netmask */,
112 ipGateway /* gateway */);