Home | History | Annotate | Download | only in libsa

Lines Matching defs:ip

1 /* $NetBSD: ip.c,v 1.5 2022/07/08 07:02:47 skrll Exp $ */
47 #include <netinet/ip.h>
62 * sends an IP packet, if it's already constructed
65 _sendip(struct iodesc *d, struct ip *ip, size_t len)
69 if (ip->ip_dst.s_addr == INADDR_BROADCAST || ip->ip_src.s_addr == 0 ||
70 netmask == 0 || SAMENET(ip->ip_src, ip->ip_dst, netmask)) {
71 ea = arpwhohas(d, ip->ip_dst);
76 return sendether(d, ip, len, ea, ETHERTYPE_IP);
80 * fills out the IP header
81 * Caller must leave room for ethernet, ip and udp headers in front!
87 struct ip *ip;
89 ip = (struct ip *)pkt - 1;
90 len += sizeof(*ip);
92 memset(ip, 0, sizeof(*ip));
94 ip->ip_v = IPVERSION;
95 ip->ip_hl = sizeof(*ip) >> 2;
96 ip->ip_len = htons(len);
97 ip->ip_p = proto;
98 ip->ip_ttl = IPDEFTTL;
99 ip->ip_src = d->myip;
100 ip->ip_dst = d->destip;
101 ip->ip_sum = ip_cksum(ip, sizeof(*ip));
103 cc = _sendip(d, ip, len);
109 return (cc - (sizeof(*ip)));
113 * reads an IP packet
114 * WARNING: the old version stripped the IP options, if there were
125 struct ip *ip;
128 ip = (struct ip *)pkt - 1;
130 n = readether(d, ip, len + sizeof(*ip), tleft, &etype);
131 if (n == -1 || (size_t)n < sizeof(*ip))
135 struct arphdr *ah = (void *)ip;
149 if (ip->ip_v != IPVERSION || ip->ip_p != proto) {
153 hlen = ip->ip_hl << 2;
154 if (hlen != sizeof(*ip) || ip_cksum(ip, hlen) != 0) {
157 if (ntohs(ip->ip_len) < hlen) {
160 if (n < ntohs(ip->ip_len)) {
163 if (d->myip.s_addr && ip->ip_dst.s_addr != d->myip.s_addr) {
167 return (ntohs(ip->ip_len) - hlen);