Lines Matching refs:buf

67 static int ip_rx_callback(ebuf_t *buf,void *ref);
83 ebuf_t *buf;
85 buf = eth_alloc(ipi->eth_info,ipi->ip_port);
87 if (buf == NULL) return buf;
89 ebuf_seek(buf,IPHDR_LENGTH);
90 ebuf_setlength(buf,0);
92 return buf;
144 * _ip_send(ipi,buf,destaddr,proto)
151 * buf - an ebuf
160 int _ip_send(ip_info_t *ipi,ebuf_t *buf,uint8_t *destaddr,uint8_t proto)
170 ebuf_seek(buf,-IPHDR_LENGTH);
172 pktlen = ebuf_length(buf) + IPHDR_LENGTH;
178 ebuf_put_u8(buf,IPHDR_VER_4 | IPHDR_LEN_20);
179 ebuf_put_u8(buf,IPHDR_TOS_DEFAULT);
180 ebuf_put_u16_be(buf,pktlen);
181 ebuf_put_u16_be(buf,ipi->ip_id);
182 ebuf_put_u16_be(buf,0);
183 ebuf_put_u8(buf,IPHDR_TTL_DEFAULT);
184 ebuf_put_u8(buf,proto);
185 ebuf_put_u16_be(buf,0); /* checksum */
186 ebuf_put_bytes(buf,ipi->net_info.ip_addr,IP_ADDR_LEN);
187 ebuf_put_bytes(buf,destaddr,IP_ADDR_LEN);
191 ebuf_prepend(buf,IPHDR_LENGTH);
195 ptr = ebuf_ptr(buf);
207 eth_send(buf,(uint8_t *) enet_broadcast);
208 eth_free(buf);
218 return _arp_lookup_and_send(ipi,buf,destaddr);
235 return _arp_lookup_and_send(ipi,buf,destaddr);
240 eth_free(buf); /* silently drop */
244 return _arp_lookup_and_send(ipi,buf,ipi->net_info.ip_gateway);
252 * ip_rx_callback(buf,ref)
259 * buf - ebuf we received
267 static int ip_rx_callback(ebuf_t *buf,void *ref)
284 hdr = ebuf_ptr(buf); /* save current posn */
286 ebuf_get_u8(buf,tmp); /* version and header length */
319 ebuf_skip(buf,1); /* skip TOS field */
321 ebuf_get_u16_be(buf,length);
322 ebuf_skip(buf,2); /* skip ID field */
324 ebuf_get_u16_be(buf,tmp16); /* get Fragment Offset field */
336 ebuf_skip(buf,1); /* skip TTL */
337 ebuf_get_u8(buf,proto); /* get protocol */
338 ebuf_skip(buf,2); /* skip checksum */
340 ebuf_get_bytes(buf,srcip,IP_ADDR_LEN);
341 ebuf_get_bytes(buf,dstip,IP_ADDR_LEN);
343 ebuf_skip(buf,hdrlen-IPHDR_LENGTH); /* skip rest of header */
345 ebuf_setlength(buf,length-hdrlen); /* set length to just data portion */
372 res = (*(pdisp->cb))(pdisp->ref,buf,dstip,srcip);
508 * _ip_free(ipi,buf)
514 * buf - ebuf to free
520 void _ip_free(ip_info_t *ipi,ebuf_t *buf)
522 eth_free(buf);
526 * _ip_getaddr(ipi,buf)
532 * buf - pointer to 4-byte buffer to receive IP address
538 void _ip_getaddr(ip_info_t *ipi,uint8_t *buf)
540 memcpy(buf,ipi->net_info.ip_addr,IP_ADDR_LEN);
682 int (*cb)(void *ref,ebuf_t *buf,uint8_t *dst,uint8_t *src),void *ref)