133 lines
3.5 KiB
Text
133 lines
3.5 KiB
Text
--- 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.
|