summaryrefslogtreecommitdiffstats
path: root/tcpip/rip98t.c
blob: 2441c4997262f4abc247c56348b0ed131b7dc69f (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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include "rip98d.h"

static int build_header(unsigned char *message)
{
	message[0] = RIPCMD_RESPONSE;
	message[1] = RIP_VERSION_98;

	message[2] = 0;
	message[3] = 0;

	return RIP98_HEADER;
}


void transmit_routes(int s)
{
	unsigned char message[500];
	struct route_struct *route;
	struct sockaddr_in rem_addr;
	int mess_len;
	int size;
	int i;

	size = sizeof(struct sockaddr_in);

	for (i = 0; i < dest_count; i++) {

		if (debug && logging)
			syslog(LOG_DEBUG, "transmit_routes: sending routing message to %s\n", inet_ntoa(dest_list[i].dest_addr));

		memset((char *)&rem_addr, 0, sizeof(rem_addr));
		rem_addr.sin_family = AF_INET;
		rem_addr.sin_addr   = dest_list[i].dest_addr;
		rem_addr.sin_port   = htons(RIP_PORT);		

		route = first_route;

		while (route != NULL) {

			mess_len = build_header(message);

			while (mess_len < 184 && route != NULL) {
				if (route->action != DEL_ROUTE) {
					memcpy(message + mess_len + 0, (char *)&route->addr, sizeof(struct in_addr));
					message[mess_len + 4] = route->bits;
					message[mess_len + 5] = route->metric;
				
					mess_len += RIP98_ENTRY;
				}

				route = route->next;
			}

			if (mess_len > RIP98_HEADER) {
				if (sendto(s, message, mess_len, 0, (struct sockaddr *)&rem_addr, size) < 0) {
					if (logging)
						syslog(LOG_ERR, "sendto: %m");
				}
			}
		}
	}
}