Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/ip.c File Reference


Detailed Description

Author:
Version:
1.0
Date:
11.6.2002
Bug:
Warning:
Todo:
OpenTCP IP protocol implementation functions. For declaration, constants and data structures refer to inet/ip.h.

Definition in file ip.c.

Go to the source code of this file.

Functions

INT16 process_ip_in (struct ethernet_frame *frame)
 Process received IP frame.

INT16 process_ip_out (UINT32 ipadr, UINT8 pcol, UINT8 tos, UINT8 ttl, UINT8 *dat, UINT16 len)
 Try to send out IP frame.

UINT32 ip_construct_cs (struct ip_frame *frame)
 Construct checksum of the IP header.

UINT8 ip_check_cs (struct ip_frame *frame)
 Check IP frame's checksum.

UINT16 ip_checksum (UINT16 cs, UINT8 dat, UINT8 count)
 Used for constructuing IP checksum.

UINT32 ip_checksum_buf (UINT16 cs, UINT8 *buf, UINT16 len)
 Used for constructuing IP checksum of a data buffer.


Variables

ip_frame received_ip_packet
 Used for storing various information about the incoming IP packet.

ip_frame send_ip_packet
 Used for storing various information about the outgoing IP packet.

UINT16 ip_id


Function Documentation

INT16 process_ip_in struct ethernet_frame   frame
 

Author:
  • Jari Lahti
Date:
11.06.2002
Parameters:
frame  pointer to ethernet_frame structure holding information about the received frame that carries IP datagram.
Returns:
  • -1 - IP packet not OK
  • >0 - Length of next layer data (IP packet OK)
Process received IP packet by checking necessary header information and storing it accordingly to received_ip_packet variable. If everything checks out, return length of the data carried in the IP datagram (for higher-level protocols), otherwise return -1.

Definition at line 115 of file ip.c.

References arp_add(), ARP_TEMP_IP, ip_frame::buf_index, ethernet_frame::buf_index, ip_frame::checksum, ethernet_frame::destination, ip_frame::dip, ip_frame::frags, ethernet_frame::frame_size, ip_frame::id, ip_check_cs(), IP_ICMP, NETWORK_RECEIVE_INITIALIZE, ip_frame::opt, PHY_ADR_LEN, ip_frame::protocol, ethernet_frame::protocol, PROTOCOL_IP, RECEIVE_NETWORK_B, ip_frame::sip, ethernet_frame::source, ip_frame::tlen, ip_frame::tos, TRUE, ip_frame::ttl, and ip_frame::vihl.

INT16 process_ip_out UINT32    ipadr,
UINT8    pcol,
UINT8    tos,
UINT8    ttl,
UINT8 *    dat,
UINT16    len
 

Author:
  • Jari Lahti
Date:
11.06.2002
Parameters:
ipadr  remote IP address
pcol  protocol over IP used. Can be one of the following:
tos  type of service required
ttl  time to live header field of IP packet
dat  pointer to data buffer
len  length of data to be sent in IP datagram
Returns:
  • -1 - general error
  • -2 - ARP cache not ready
  • >0 - number of data bytes sent (packet OK)
Invoke this function to perform all of the necessary preparation in order to send out an IP packet. These include:
  • Consulting ARP cache for HW address to send the packet to
  • Filling send_ip_packet variable with correct values
  • Calculating checksum for the IP packet
  • Adding datalink header information
  • Sending IP header and data
  • Instructing NIC to send the data

Definition at line 300 of file ip.c.

References arp_find(), ARP_TEMP_IP, ip_frame::checksum, ip_frame::dip, ip_frame::frags, arp_entry::hwadr, ICMP_BUF, ip_frame::id, ip_construct_cs(), IP_ICMP, ip_id, IP_TCP, IP_UDP, MAXHWALEN, NETWORK_ADD_DATALINK, NETWORK_COMPLETE_SEND, NETWORK_SEND_INITIALIZE, ip_frame::protocol, PROTOCOL_IP, SEND_NETWORK_B, SEND_NETWORK_BUF, ip_frame::sip, TCP_BUF, ip_frame::tlen, ip_frame::tos, ip_frame::ttl, UDP_BUF, and ip_frame::vihl.

Referenced by process_icmp_in(), process_tcp_out(), and udp_send().

UINT32 ip_construct_cs struct ip_frame   frame
 

Author:
  • Jari Lahti
Date:
08.07.2002
Parameters:
frame  pointer to ip_frame structure holding header information based on which checksum is calculated
Returns:
Calculated checksum
Checksum of the supplied IP datagram is calculated.

Definition at line 417 of file ip.c.

References ip_frame::dip, ip_frame::frags, ip_frame::id, ip_checksum(), ip_frame::opt, ip_frame::protocol, ip_frame::sip, ip_frame::tlen, ip_frame::tos, ip_frame::ttl, and ip_frame::vihl.

Referenced by process_ip_out().

UINT8 ip_check_cs struct ip_frame   frame
 

Author:
  • Jari Lahti
Date:
11.06.2002
Parameters:
frame  pointer to IP frame to be checked
Returns:
  • 0 - checksum corrupted
  • 1 - checksum OK
Checksum of an IP packet is calculated and compared with the received checksum. Error is signaled if there is discrepancy between them.

Definition at line 474 of file ip.c.

References ip_frame::checksum, ip_frame::dip, ip_frame::frags, ip_frame::id, ip_checksum(), ip_frame::opt, ip_frame::protocol, ip_frame::sip, ip_frame::tlen, ip_frame::tos, ip_frame::ttl, and ip_frame::vihl.

Referenced by process_ip_in().

UINT16 ip_checksum UINT16    cs,
UINT8    dat,
UINT8    count
 

Author:
  • Jari Lahti
Date:
24.02.2002
Parameters:
cs  last checksum value
dat  byte to be added to checksum
count  byte indicating whether dat is MSB or LSB byte
Returns:
new checksum value
Based on count value, dat byte is added to checksum either as a MSB or a LSB byte and the new checksum value is then returned.

Definition at line 539 of file ip.c.

Referenced by ip_check_cs(), ip_checksum_buf(), ip_construct_cs(), process_icmp_in(), process_tcp_out(), process_udp_in(), tcp_check_cs(), and udp_send().

UINT32 ip_checksum_buf UINT16    cs,
UINT8 *    buf,
UINT16    len
 

Author:
  • Jari Lahti
Date:
03.08.2003
Parameters:
cs  last checksum value
buf  buffer who's checksum we're calculating
len  length of data in buffer
Returns:
new checksum value
Calculates checksum of the data in buffer and returns new checksum value.

Definition at line 582 of file ip.c.

References ip_checksum().

Referenced by process_icmp_in(), process_tcp_out(), tcp_check_cs(), and udp_send().


Variable Documentation

struct ip_frame received_ip_packet
 

Various fields from the IP packet are stored in this structure. These values are later used from other upper layer protocols (ICMP, UDP, TCP and possibly others) to extract needed information about the received packet. See ip_frame definition for struct information.

Definition at line 85 of file ip.c.

struct ip_frame send_ip_packet
 

Various fields from the IP packet are stored in this structure. These values are filled based on the information supplied by the upper layer protocols (ICMP, UDP, TCP and possibly others) and used to form a correct IP packet (correct filed values, checksum,..). See ip_frame definition for struct information.

Definition at line 95 of file ip.c.

UINT16 ip_id
 

ID field in the next IP packet that will be sent

Definition at line 97 of file ip.c.

Referenced by process_ip_out().


Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by doxygen1.2.18