icmp.c (22c624779b5330d6a42ec4b7e3215de77a76c4ec) icmp.c (24084f9bfc80f32d7390568d742988293cc6547b)
1/*
2 * natd - Network Address Translation Daemon for FreeBSD.
3 *
4 * This software is provided free of charge, with no
5 * warranty of any kind, either expressed or implied.
6 * Use at your own risk.
7 *
8 * You may copy, modify and distribute this software (icmp.c) freely.
9 *
10 * Ari Suutari <suutari@iki.fi>
11 *
12 * $FreeBSD$
13 */
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <unistd.h>
18#include <string.h>
19#include <ctype.h>
20
21#include <sys/types.h>
22#include <sys/socket.h>

--- 58 unchanged lines hidden (view full) ---

81
82 failBytes += failHdrLen;
83 icmpLen = ICMP_MINLEN + failBytes;
84
85 memcpy (&icmp->icmp_ip, failedDgram, failBytes);
86/*
87 * Calculate checksum.
88 */
1#include <stdlib.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <string.h>
5#include <ctype.h>
6
7#include <sys/types.h>
8#include <sys/socket.h>

--- 58 unchanged lines hidden (view full) ---

67
68 failBytes += failHdrLen;
69 icmpLen = ICMP_MINLEN + failBytes;
70
71 memcpy (&icmp->icmp_ip, failedDgram, failBytes);
72/*
73 * Calculate checksum.
74 */
89 icmp->icmp_cksum = LibAliasInternetChecksum (mla, (u_short*) icmp,
90 icmpLen);
75 icmp->icmp_cksum = InternetChecksum ((u_short*) icmp, icmpLen);
91/*
92 * Add IP header using old IP header as template.
93 */
94 memcpy (ip, failedDgram, sizeof (struct ip));
95
96 ip->ip_v = 4;
97 ip->ip_hl = 5;
98 ip->ip_len = htons (sizeof (struct ip) + icmpLen);
99 ip->ip_p = IPPROTO_ICMP;
100 ip->ip_tos = 0;
101
102 swap = ip->ip_dst;
103 ip->ip_dst = ip->ip_src;
104 ip->ip_src = swap;
105
76/*
77 * Add IP header using old IP header as template.
78 */
79 memcpy (ip, failedDgram, sizeof (struct ip));
80
81 ip->ip_v = 4;
82 ip->ip_hl = 5;
83 ip->ip_len = htons (sizeof (struct ip) + icmpLen);
84 ip->ip_p = IPPROTO_ICMP;
85 ip->ip_tos = 0;
86
87 swap = ip->ip_dst;
88 ip->ip_dst = ip->ip_src;
89 ip->ip_src = swap;
90
106 LibAliasIn (mla, (char*) ip, IP_MAXPACKET);
91 PacketAliasIn ((char*) ip, IP_MAXPACKET);
107
108 addr.sin_family = AF_INET;
109 addr.sin_addr = ip->ip_dst;
110 addr.sin_port = 0;
111/*
112 * Put packet into processing queue.
113 */
114 wrote = sendto (sock,

--- 13 unchanged lines hidden ---
92
93 addr.sin_family = AF_INET;
94 addr.sin_addr = ip->ip_dst;
95 addr.sin_port = 0;
96/*
97 * Put packet into processing queue.
98 */
99 wrote = sendto (sock,

--- 13 unchanged lines hidden ---