Ejemplo n.º 1
0
void udp_send_packet(unsigned pkt, unsigned payload_len)
{
  unsigned udplen = payload_len + sizeof (struct udp_hdr_s);
  struct ip_hdr_s  *ih = mac_ref(pkt, 0);
  struct udp_hdr_s *uh = ip_ref(pkt, 0);
  if(ih == 0) return;
  uh->total_len = htons(udplen);
  checksum_reset(&uh->checksum);
  checksum_incremental_pseudo(ih->dst_ip, ih->src_ip, UDP_PROTO, udplen);
  checksum_incremental_calc(uh, udplen);
  checksum_place(&uh->checksum);
  ip_send_packet(pkt, udplen, 1);
}
Ejemplo n.º 2
0
void udp_send_packet(int *data, int len)
{
	int * packet = ethernet_tx_data + ETHERNET_HDR_LEN + IP_HDR_LEN;
	int2mem(packet + UDP_SRC_PORT, 2, udp_dst_port);
    int2mem(packet + UDP_DST_PORT, 2, udp_src_port);
	packet[UDP_LENGTH] = MSB(len + 8);
	packet[UDP_LENGTH + 1] = LSB(len + 8);
	packet[UDP_CHECKSUM] = 0;
	packet[UDP_CHECKSUM + 1] = 0;
	int i;
	for (i = 0; i < len; i++) 
		packet[UDP_DATA + i] = data[i];
	
	ip_send_packet(remote_mac, IP_PROTOCAL_UDP, len + 8);
    ethernet_tx_len = ETHERNET_HDR_LEN + IP_HDR_LEN + len + 8;
    ethernet_send();
}
Ejemplo n.º 3
0
void icmp_send_packet(unsigned packet_id, unsigned icmp_payload_len)
{
  unsigned buf[64];

  icmp_get_tx_header(packet_id);
  checksum_reset(icmp_tx_header.checksum);
  checksum_incremental_calc(&icmp_tx_header, sizeof icmp_tx_header);
  unsigned len, chunk;
  icmp_tx_body_pointer = 0;
  for(len=icmp_payload_len; len>0; len-=chunk)
  {
    chunk = sizeof buf;
    if(chunk > len) chunk = len;
    icmp_get_tx_body(packet_id, buf, chunk);
    checksum_incremental_calc(buf, chunk);
  }
  checksum_place(icmp_tx_header.checksum);
  icmp_put_tx_header(packet_id);
  ip_send_packet(packet_id, sizeof icmp_tx_header + icmp_payload_len, 1);
}