kernels/linux-2.4.0/drivers/net/wan/sdla_chdlc.c
static int reply_udp( unsigned char *data, unsigned int mbox_len )
{

	unsigned short len, udp_length, temp, ip_length;
	unsigned long ip_temp;
	int even_bound = 0;
  	chdlc_udp_pkt_t *c_udp_pkt = (chdlc_udp_pkt_t *)data;
	 
	/* Set length of packet */
	len = sizeof(ip_pkt_t)+ 
	      sizeof(udp_pkt_t)+
	      sizeof(wp_mgmt_t)+
	      sizeof(cblock_t)+
	      sizeof(trace_info_t)+ 
	      mbox_len;

	/* fill in UDP reply */
	c_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
   
	/* fill in UDP length */
	udp_length = sizeof(udp_pkt_t)+ 
		     sizeof(wp_mgmt_t)+
		     sizeof(cblock_t)+
	             sizeof(trace_info_t)+
		     mbox_len; 

 	/* put it on an even boundary */
	if ( udp_length & 0x0001 ) {
		udp_length += 1;
		len += 1;
		even_bound = 1;
	}  

	temp = (udp_length<<8)|(udp_length>>8);
	c_udp_pkt->udp_pkt.udp_length = temp;
		 
	/* swap UDP ports */
	temp = c_udp_pkt->udp_pkt.udp_src_port;
	c_udp_pkt->udp_pkt.udp_src_port = 
			c_udp_pkt->udp_pkt.udp_dst_port; 
	c_udp_pkt->udp_pkt.udp_dst_port = temp;

	/* add UDP pseudo header */
	temp = 0x1100;
	*((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound)) = temp;	
	temp = (udp_length<<8)|(udp_length>>8);
	*((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound+2)) = temp;

		 
	/* calculate UDP checksum */
	c_udp_pkt->udp_pkt.udp_checksum = 0;
	c_udp_pkt->udp_pkt.udp_checksum = calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);

	/* fill in IP length */
	ip_length = len;
	temp = (ip_length<<8)|(ip_length>>8);
	c_udp_pkt->ip_pkt.total_length = temp;
  
	/* swap IP addresses */
	ip_temp = c_udp_pkt->ip_pkt.ip_src_address;
	c_udp_pkt->ip_pkt.ip_src_address = c_udp_pkt->ip_pkt.ip_dst_address;
	c_udp_pkt->ip_pkt.ip_dst_address = ip_temp;

	/* fill in IP checksum */
	c_udp_pkt->ip_pkt.hdr_checksum = 0;
	c_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));

	return len;

}
/*============================================================================
 * Reply to UDP Management system.
 * Return length of reply.
 */
Reply to UDP Management system.
Return length of reply.
Reply to UDP Management system . Return length of reply .
static int reply_udp( unsigned char *data, unsigned int mbox_len )
{
	unsigned short len, udp_length, temp, ip_length;
	unsigned long ip_temp;
	int even_bound = 0;
  	chdlc_udp_pkt_t *c_udp_pkt = (chdlc_udp_pkt_t *)data;
	len = sizeof(ip_pkt_t)+ 
	      sizeof(udp_pkt_t)+
	      sizeof(wp_mgmt_t)+
	      sizeof(cblock_t)+
	      sizeof(trace_info_t)+ 
	      mbox_len;
	c_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
	udp_length = sizeof(udp_pkt_t)+ 
		     sizeof(wp_mgmt_t)+
		     sizeof(cblock_t)+
	             sizeof(trace_info_t)+
		     mbox_len; 
	if ( udp_length & 0x0001 ) {
		udp_length += 1;
		len += 1;
		even_bound = 1;
	}  
	temp = (udp_length<<8)|(udp_length>>8);
	c_udp_pkt->udp_pkt.udp_length = temp;
	temp = c_udp_pkt->udp_pkt.udp_src_port;
	c_udp_pkt->udp_pkt.udp_src_port = 
			c_udp_pkt->udp_pkt.udp_dst_port; 
	c_udp_pkt->udp_pkt.udp_dst_port = temp;
	temp = 0x1100;
	*((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound)) = temp;	
	temp = (udp_length<<8)|(udp_length>>8);
	*((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound+2)) = temp;
	c_udp_pkt->udp_pkt.udp_checksum = 0;
	c_udp_pkt->udp_pkt.udp_checksum = calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
	ip_length = len;
	temp = (ip_length<<8)|(ip_length>>8);
	c_udp_pkt->ip_pkt.total_length = temp;
	ip_temp = c_udp_pkt->ip_pkt.ip_src_address;
	c_udp_pkt->ip_pkt.ip_src_address = c_udp_pkt->ip_pkt.ip_dst_address;
	c_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
	c_udp_pkt->ip_pkt.hdr_checksum = 0;
	c_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
	return len;
}
static int reply_udp ( unsigned char * data , unsigned int mbox_len ) { unsigned short len , udp_length , temp , ip_length ; unsigned long ip_temp ; int even_bound = 0 ; chdlc_udp_pkt_t * c_udp_pkt = ( chdlc_udp_pkt_t * ) data ; len = sizeof ( ip_pkt_t ) + sizeof ( udp_pkt_t ) + sizeof ( wp_mgmt_t ) + sizeof ( cblock_t ) + sizeof ( trace_info_t ) + mbox_len ; c_udp_pkt -> wp_mgmt . request_reply = UDPMGMT_REPLY ; udp_length = sizeof ( udp_pkt_t ) + sizeof ( wp_mgmt_t ) + sizeof ( cblock_t ) + sizeof ( trace_info_t ) + mbox_len ; if ( udp_length & 0x0001 ) { udp_length += 1 ; len += 1 ; even_bound = 1 ; } temp = ( udp_length << 8 ) | ( udp_length >> 8 ) ; c_udp_pkt -> udp_pkt . udp_length = temp ; temp = c_udp_pkt -> udp_pkt . udp_src_port ; c_udp_pkt -> udp_pkt . udp_src_port = c_udp_pkt -> udp_pkt . udp_dst_port ; c_udp_pkt -> udp_pkt . udp_dst_port = temp ; temp = 0x1100 ; * ( ( unsigned short * ) ( c_udp_pkt -> data + mbox_len + even_bound ) ) = temp ; temp = ( udp_length << 8 ) | ( udp_length >> 8 ) ; * ( ( unsigned short * ) ( c_udp_pkt -> data + mbox_len + even_bound + 2 ) ) = temp ; c_udp_pkt -> udp_pkt . udp_checksum = 0 ; c_udp_pkt -> udp_pkt . udp_checksum = calc_checksum ( & data [ UDP_OFFSET ] , udp_length + UDP_OFFSET ) ; ip_length = len ; temp = ( ip_length << 8 ) | ( ip_length >> 8 ) ; c_udp_pkt -> ip_pkt . total_length = temp ; ip_temp = c_udp_pkt -> ip_pkt . ip_src_address ; c_udp_pkt -> ip_pkt . ip_src_address = c_udp_pkt -> ip_pkt . ip_dst_address ; c_udp_pkt -> ip_pkt . ip_dst_address = ip_temp ; c_udp_pkt -> ip_pkt . hdr_checksum = 0 ; c_udp_pkt -> ip_pkt . hdr_checksum = calc_checksum ( data , sizeof ( ip_pkt_t ) ) ; return len ; }
Reply to UDP Management system.
Reply to UDP Management system .
/* Set length of packet */ /* fill in UDP reply */ /* fill in UDP length */ /* put it on an even boundary */ /* swap UDP ports */ /* add UDP pseudo header */ /* calculate UDP checksum */ /* fill in IP length */ /* swap IP addresses */ /* fill in IP checksum */