summaryrefslogtreecommitdiff
path: root/net/net-snmp/patches/patch-an
blob: 2715da4ce8131b59151c40294ba93a6d6b94adce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--- agent/mibgroup/mibII/route_write.c.orig	2005-07-30 22:18:06.000000000 +1000
+++ agent/mibgroup/mibII/route_write.c	2005-07-30 22:18:28.000000000 +1000
@@ -102,7 +102,7 @@
 int
 addRoute(u_long dstip, u_long gwip, u_long iff, u_short flags)
 {
-#ifndef dynix
+#if !(defined dynix || defined darwin)
     struct sockaddr_in dst;
     struct sockaddr_in gateway;
     int             s, rc;
@@ -141,6 +141,55 @@
     return rc;
 #endif
 
+#elif defined darwin
+    size_t sa_in_size = sizeof(struct sockaddr_in);
+    int	s, rc;
+    struct sockaddr_in dst;
+    struct sockaddr_in gateway;
+    struct {
+        struct	rt_msghdr hdr;
+        char	space[512];
+    } rtmsg;
+
+    s = socket(PF_ROUTE, SOCK_RAW, 0);
+    if (s < 0) {
+        snmp_log_perror("socket");
+        return -1;
+    }
+
+    shutdown(s, SHUT_RD);
+    /* possible panic otherwise */
+    flags |= (RTF_UP | RTF_GATEWAY);
+
+    bzero((char *)&dst, sa_in_size);
+    dst.sin_len = sa_in_size;
+    dst.sin_family = AF_INET;
+    dst.sin_addr.s_addr = htonl(dstip);
+
+    bzero((char *)&gateway, sa_in_size);
+    gateway.sin_len = sa_in_size;
+    gateway.sin_family = AF_INET;
+    gateway.sin_addr.s_addr = htonl(gwip);
+
+    bzero((char *)&rtmsg, sizeof(rtmsg));
+    rtmsg.hdr.rtm_type = RTM_ADD;
+    rtmsg.hdr.rtm_version = RTM_VERSION;
+    rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
+    rtmsg.hdr.rtm_flags = RTF_GATEWAY;
+	
+    bcopy((char *)&dst, rtmsg.space, sa_in_size);
+    bcopy((char *)&gateway, (rtmsg.space+sa_in_size), sa_in_size);
+	
+    rc = sizeof(struct rt_msghdr) + sa_in_size + sa_in_size;
+    rtmsg.hdr.rtm_msglen = rc;
+	
+    if ((rc = write(s, (char *)&rtmsg, rc)) < 0) {
+        snmp_log_perror("writing to routing socket");
+        return -1;
+    }
+
+    return (rc);
+
 #else                           /* dynix */
     /*
      *  Throws up the following errors:
@@ -166,7 +215,7 @@
 int
 delRoute(u_long dstip, u_long gwip, u_long iff, u_short flags)
 {
-#ifndef dynix
+#if !(defined dynix || defined darwin)
 
     struct sockaddr_in dst;
     struct sockaddr_in gateway;
@@ -205,6 +254,56 @@
     return rc;
 #endif
 
+#elif defined darwin
+    size_t sa_in_size = sizeof(struct sockaddr_in);
+    int	s, rc;
+    struct sockaddr_in dst;
+    struct sockaddr_in gateway;
+    struct {
+        struct	rt_msghdr hdr;
+        char	space[512];
+    } rtmsg;
+
+    s = socket(PF_ROUTE, SOCK_RAW, 0);
+
+    if (s < 0) {
+        snmp_log_perror("socket");
+        return -1;
+    }
+
+    shutdown(s, SHUT_RD);
+    /* possible panic otherwise */
+    flags |= (RTF_UP | RTF_GATEWAY);
+
+    bzero((char *)&dst, sa_in_size);
+    dst.sin_len = sa_in_size;
+    dst.sin_family = AF_INET;
+    dst.sin_addr.s_addr = htonl(dstip);
+
+    bzero((char *)&gateway, sa_in_size);
+    gateway.sin_len = sa_in_size;
+    gateway.sin_family = AF_INET;
+    gateway.sin_addr.s_addr = htonl(gwip);
+
+    bzero((char *)&rtmsg, sizeof(rtmsg));
+    rtmsg.hdr.rtm_type = RTM_DELETE;
+    rtmsg.hdr.rtm_version = RTM_VERSION;
+    rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
+    rtmsg.hdr.rtm_flags = RTF_GATEWAY;
+
+    bcopy((char *)&dst, rtmsg.space, sa_in_size);
+    bcopy((char *)&gateway, (rtmsg.space+sa_in_size), sa_in_size);
+
+    rc = sizeof(struct rt_msghdr) + sa_in_size + sa_in_size;
+    rtmsg.hdr.rtm_msglen = rc;
+
+    if ((rc = write(s, (char *)&rtmsg, rc)) < 0) {
+        snmp_log_perror("writing to routing socket");
+        return -1;
+    }
+
+    return rc;
+
 #else                           /* dynix */
     /*
      * See 'addRoute' for the list of errors.