1 /* $Id: icmp.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
3 Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 pkt_icmp_header(struct packet *pkt, unsigned char type, unsigned char code, unsigned short int checksum)
28 icmp = (struct icmp *) pkt->pkt_ptr;
29 icmp->icmp_type = type;
30 icmp->icmp_code = code;
31 icmp->icmp_cksum = htons(checksum);
37 int pkt_icmp_addr_mask(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int mask, char *cmask)
40 struct in_addr inetaddr;
43 icmp = (struct icmp *)pkt->pkt_ptr;
46 icmp->icmp_id = htons(id);
47 icmp->icmp_seq = htons(seqno);
49 icmp->icmp_mask = htons(mask);
51 if (inet_aton(cmask, &inetaddr) != 0) {
52 icmp->icmp_mask = inetaddr.s_addr;
60 pkt_icmp_cksum(struct packet *pkt, unsigned int len)
67 icmp = (struct icmp *) pkt->pkt_ptr;
69 icmp->icmp_cksum = in_cksum((unsigned short *)icmp, len);
74 pkt_icmp_dest_unreach(struct packet *pkt, unsigned int unused)
79 icmp = (struct icmp *)pkt->pkt_ptr;
82 icmp->icmp_void = htons(unused);
87 pkt_icmp_source_quench(struct packet *pkt, unsigned int unused)
92 icmp = (struct icmp *)pkt->pkt_ptr;
95 icmp->icmp_void = htons(unused);
100 pkt_icmp_redirect(struct packet *pkt, unsigned int routerip, char *crouterip)
103 struct in_addr inetaddr;
106 icmp = (struct icmp *)pkt->pkt_ptr;
111 if (inet_aton(crouterip, &inetaddr) != 0) {
112 icmp->icmp_gwaddr = inetaddr;
116 inetaddr.s_addr = htons(routerip);
117 icmp->icmp_gwaddr = inetaddr;
123 pkt_icmp_echo(struct packet *pkt, unsigned short int id, unsigned short int seqno, void *data, size_t data_len)
128 icmp = (struct icmp *) pkt->pkt_ptr;
131 icmp->icmp_id = htons(id);
132 icmp->icmp_seq = htons(seqno);
134 memcpy(icmp->icmp_data, data, data_len);
140 pkt_icmp_timestamp(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int ts_otime, unsigned int ts_rtime, unsigned int ts_ttime)
145 icmp = (struct icmp *) pkt->pkt_ptr;
148 icmp->icmp_id = htons(id);
149 icmp->icmp_seq = htons(seqno);
150 icmp->icmp_otime = htons(ts_otime);
151 icmp->icmp_rtime = htons(ts_rtime);
152 icmp->icmp_ttime = htons(ts_ttime);