BOOL CEthernetLayer::Send(unsigned char *ppayload, int nlength , int type) { char broadCast[20]; CString broadCastMac; BOOL bSuccess = FALSE ; memcpy( m_sHeader.enet_data, ppayload, nlength ) ; if(type == 0x01) //ARP Request 일 때 { broadCastMac.Format("ff:ff:ff:ff:ff:ff"); memcpy(broadCast , (char*)(LPCTSTR)broadCastMac , 18); sscanf(broadCast , "%02X:%02X:%02X:%02X:%02X:%02X", &m_DstMac[0],&m_DstMac[1],&m_DstMac[2],&m_DstMac[3],&m_DstMac[4], &m_DstMac[5]); SetSourceAddress(macMyAddress); // source Address 를 자신의 주소로 저장합니다. SetDestinAddress(m_DstMac); // destination Address 를 BroadCast로 지정합니다. m_sHeader.enet_type = htons(0x0806); // ARP Packet임을 type 값을 통해 명시해줍니다. } else if( type == 0x02 ) { // ARP reply 전송 일 때 수행하는 코드입니다. SetSourceAddress(macMyAddress); // source Address 를 자신의 주소로 저장합니다. SetDestinAddress(((CARPLayer::Parp_Header)ppayload)->target_mac_address); // destination Address 를 ACK Packet을 전송받을 상대로 지정합니다. // memcpy( m_sHeader.enet_dstaddr , ((CARPLayer::Parp_Header)ppayload)->target_mac_address , 4); // ACK Packet을 전송해줄 상대를 지정합니다. // memcpy( m_sHeader.enet_srcaddr , macMyAddress , sizeof(macMyAddress)); m_sHeader.enet_type = htons(0x0806); // ARP Packet임을 type 값을 통해 명시해줍니다. } return mp_UnderLayer->Send( (unsigned char*)&m_sHeader , nlength+ETHER_HEADER_SIZE+18); // 하위 layer로 전송합니다. }
CProto::CProto( CAbstractAdapter& anAdapter ) : CApplicationLayer( anAdapter ) { SetAddressingType( atPhysical ); SetTargetAddress( 0x10 ); SetSourceAddress( 0xf0 ); }