u-boot의 netconsole (보드는 자일링스의 zedboard)에서 udp 프로토콜을 수정하고 있습니다.char에 대한 포인터에 숫자 할당
번호가 매겨진 패킷이 있어야합니다. 나는 송신을 담당하는 함수를 찾고 각 패킷의 시작 부분에 숫자를 추가하기 만하면된다. 값을 큰 따옴표 ("@")로 전달하는 한 정상적으로 작동합니다.
숫자를 전달하려는 경우 (또는 단일 문자를 사용하는 경우에도 "@"대신 '@'를 사용) 패킷을 받으면 완전히 임의의 값을 얻습니다.
static void nc_send_packet(const char *buf, int len)
{
struct eth_device *eth;
int inited = 0;
uchar *pkt;
uchar *ether;
IPaddr_t ip;
uchar *new_buf=malloc((len+1)*(sizeof(uchar))); //TN
uchar *prefix="@"; //<-------------------------------this line TN
memcpy(new_buf, prefix, 1); //TN
memcpy((new_buf+1), buf, len); //TN
len+=1; //TN
debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf);
eth = eth_get_dev();
if (eth == NULL)
return;
if (!memcmp(nc_ether, NetEtherNullAddr, 6)) {
if (eth->state == ETH_STATE_ACTIVE)
return; /* inside net loop */
output_packet = new_buf; //TN was output_packet = buf;
output_packet_len = len;
NetLoop(NETCONS); /* wait for arp reply and send packet */
output_packet_len = 0;
free(new_buf); //TN
return;
}
if (eth->state != ETH_STATE_ACTIVE) {
if (eth_is_on_demand_init()) {
if (eth_init(gd->bd) < 0)
free(new_buf); //TN
return;
eth_set_last_protocol(NETCONS);
} else
eth_init_state_only(gd->bd);
inited = 1;
}
pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
memcpy(pkt, new_buf, len); //TN was memcpy(pkt, buf, len);
ether = nc_ether;
ip = nc_ip;
NetSendUDPPacket(ether, ip, nc_out_port, nc_in_port, len);
free(new_buf);//TN
if (inited) {
if (eth_is_on_demand_init())
eth_halt();
else
eth_halt_state_only();
}
}
// TN이있는 행이 추가되었습니다. (적어도 나를 위해) uchar * prefix = '@';
도 작동하지 않는 경우에도 낯선 무엇
uchar * prefix = 0x40;
또는 uchar * prefix = 64;
:이 같은이 필요합니다. 나는 캐스팅을 시도했으나 uchar * prefix = (uchar)0x40;
도 uchar * prefix = (uchar)'@';
도 작동하지 않습니다.
더 긴 필드를 사용할 수 있다면 궁금합니다. 예를 들어, 패킷 번호 대신 단지 2 바이트를 가질 수 있습니다.