void send_udp_transmit(uint8_t *buf,uint16_t datalen) { uint16_t tmp16; tmp16=IP_HEADER_LEN+UDP_HEADER_LEN+datalen; buf[IP_TOTLEN_L_P]=tmp16& 0xff; buf[IP_TOTLEN_H_P]=tmp16>>8; fill_ip_hdr_checksum(buf); tmp16=UDP_HEADER_LEN+datalen; buf[UDP_LEN_L_P]=tmp16& 0xff; buf[UDP_LEN_H_P]=tmp16>>8; // tmp16=checksum(&buf[IP_SRC_P], 16 + datalen,1); buf[UDP_CHECKSUM_L_P]=tmp16& 0xff; buf[UDP_CHECKSUM_H_P]=tmp16>>8; enc28j60PacketSend(UDP_HEADER_LEN+IP_HEADER_LEN+ETH_HEADER_LEN+datalen,buf); }
void client_ntp_request(uint8_t *buf,uint8_t *ntpip,uint8_t srcport,uint8_t *dstmac) { uint8_t i=0; uint16_t ck; // while(i<6){ buf[ETH_DST_MAC +i]=dstmac[i]; // gw mac in local lan or host mac buf[ETH_SRC_MAC +i]=macaddr[i]; i++; } buf[ETH_TYPE_H_P] = ETHTYPE_IP_H_V; buf[ETH_TYPE_L_P] = ETHTYPE_IP_L_V; fill_buf_p(&buf[IP_P],9,iphdr); buf[IP_ID_L_P]=ipid; ipid++; buf[IP_TOTLEN_L_P]=0x4c; buf[IP_PROTO_P]=IP_PROTO_UDP_V; i=0; while(i<4){ buf[IP_DST_P+i]=ntpip[i]; buf[IP_SRC_P+i]=ipaddr[i]; i++; } fill_ip_hdr_checksum(buf); buf[UDP_DST_PORT_H_P]=0; buf[UDP_DST_PORT_L_P]=0x7b; // ntp=123 buf[UDP_SRC_PORT_H_P]=10; buf[UDP_SRC_PORT_L_P]=srcport; // lower 8 bit of src port buf[UDP_LEN_H_P]=0; buf[UDP_LEN_L_P]=56; // fixed len // zero the checksum buf[UDP_CHECKSUM_H_P]=0; buf[UDP_CHECKSUM_L_P]=0; // copy the data: i=0; // most fields are zero, here we zero everything and fill later while(i<48){ buf[UDP_DATA_P+i]=0; i++; } fill_buf_p(&buf[UDP_DATA_P],10,ntpreqhdr); // ck=checksum(&buf[IP_SRC_P], 16 + 48,1); buf[UDP_CHECKSUM_H_P]=ck>>8; buf[UDP_CHECKSUM_L_P]=ck& 0xff; enc28j60PacketSend(90,buf); }
void EtherShield::ES_fill_ip_hdr_checksum(uint8_t *buf) { fill_ip_hdr_checksum(buf); }