Lines Matching full:ip
3 * ip.c (C) 1995-1998 Darren Reed
13 #include <netinet/ip.h>
77 send_ip(int nfd, int mtu, ip_t *ip, struct in_addr gwip, int frag)
112 bcopy((char *)ip, (char *)&ipsv, sizeof(*ip));
114 iplen = ip->ip_len;
115 ip->ip_len = htons(iplen);
117 if (!IP_V(ip))
118 IP_V_A(ip, IPVERSION);
119 if (!ip->ip_id)
120 ip->ip_id = htons(id++);
121 if (!ip->ip_ttl)
122 ip->ip_ttl = 60;
125 if (ip->ip_src.s_addr != local_ip.s_addr) {
126 (void) arp((char *)&ip->ip_src, (char *) &local_arp);
128 local_ip = ip->ip_src;
134 ip->ip_sum = 0;
135 ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2);
137 bcopy((char *)ip, ipbuf + sizeof(*eh), iplen);
143 * Actually, this is bogus because we're putting all IP
152 hlen = IP_HL(ip) << 2;
154 fprintf(stderr, "mtu (%d) < ip header size (%d) + 8\n",
159 ol = (IP_HL(ip) << 2) - sizeof(*ip);
160 for (i = 0, s = (char*)(ip + 1); ol > 0; )
190 s = (char *)ip + hlen;
191 iplen = ntohs(ip->ip_len) - hlen;
192 ip->ip_off |= htons(IP_MF);
198 ip->ip_off ^= htons(IP_MF);
203 ip->ip_off &= htons(0xe000);
204 ip->ip_off |= htons(sent >> 3);
206 ip->ip_len = htons(ts);
207 ip->ip_sum = 0;
208 ip->ip_sum = chksum((u_short *)ip, hlen);
209 bcopy((char *)ip, ipbuf + sizeof(*eh), hlen);
215 if (!(ntohs(ip->ip_off) & IP_MF))
217 else if (!(ip->ip_off & htons(0x1fff)))
219 hlen = i + sizeof(*ip);
220 IP_HL_A(ip, (sizeof(*ip) + i) >> 2);
221 bcopy(optcpy, (char *)(ip + 1), i);
226 bcopy((char *)&ipsv, (char *)ip, sizeof(*ip));
235 send_tcp(int nfd, int mtu, ip_t *ip, struct in_addr gwip)
243 iplen = ip->ip_len;
244 hlen = IP_HL(ip) << 2;
245 t = (tcphdr_t *)((char *)ip + hlen);
246 ip2 = (struct ip *)lbuf;
252 ip->ip_p = IPPROTO_TCP;
253 ip2->ip_p = ip->ip_p;
254 ip2->ip_src = ip->ip_src;
255 ip2->ip_dst = ip->ip_dst;
256 bcopy((char *)ip + hlen, (char *)t2, thlen);
264 if ((__tcp_get_flags(t2) == TH_SYN) && !ntohs(ip->ip_off) &&
267 bcopy((char *)ip + hlen + thlen, (char *)ip + hlen + thlen + 4,
273 ip->ip_len = hlen + thlen;
277 bcopy((char *)t2, (char *)ip + hlen, thlen);
278 return (send_ip(nfd, mtu, ip, gwip, 1));
286 send_udp(int nfd, int mtu, ip_t *ip, struct in_addr gwip)
295 ti->ti_pr = ip->ip_p;
296 ti->ti_src = ip->ip_src;
297 ti->ti_dst = ip->ip_dst;
298 bcopy((char *)ip + (IP_HL(ip) << 2),
302 ip->ip_len = (IP_HL(ip) << 2) + thlen;
307 (char *)ip + (IP_HL(ip) << 2), sizeof(udphdr_t));
308 return (send_ip(nfd, mtu, ip, gwip, 1));
316 send_icmp(int nfd, int mtu, ip_t *ip, in_addr gwip)
320 ic = (struct icmp *)((char *)ip + (IP_HL(ip) << 2));
325 return (send_ip(nfd, mtu, ip, gwip, 1));
330 send_packet(int nfd, int mtu, ip_t *ip, struct in_addr gwip)
332 ip_t *ip;
335 switch (ip->ip_p)
338 ( return send_tcp(nfd, mtu, ip, gwip));
340 ( return send_udp(nfd, mtu, ip, gwip));
342 ( return send_icmp(nfd, mtu, ip, gwip));
344 ( return send_ip(nfd, mtu, ip, gwip, 1));