udp socket同样的代码为什么Linux行,Vxworks就不行?(有码)
void usrAppInit (void){#ifdef USER_APPL_INIT USER_APPL_INIT; /* for backwards compatibility */#endif /* add application specific code here */ int count, loopi, j; BYTE node_id = sysProcNumGet(); END_OBJ * pEnd; char ipaddr[40]; END_TBL_ENTRY* pDevTbl; BYTE bMasterMacAddress[6]; BYTE byFpgaStatus; DWORD dwNodeType; int sockd; struct sockaddr_in my_addr, srv_addr; char buf[2048]; int addrlen;/*网口初始化*/if (mBlkInit() != OK){printf("intercom_init: mBlkInit fail!\n");}/*set mac address and IP address*/ bMacAddress[0][5] = node_id; bMacAddress[1][5] = node_id; for (loopi = 0; loopi < 2; loopi++) { pRouteCookie[loopi] = NULL; } muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, arpresolve); /* Add in mux ENDs. */ for (count = 0, pDevTbl = endDevTbl; pDevTbl->endLoadFunc != END_TBL_END; pDevTbl++, count++) { if (!pDevTbl->processed) { pEnd = (END_OBJ *) muxDevLoad(pDevTbl->unit, pDevTbl->endLoadFunc, pDevTbl->endLoadString, pDevTbl->endLoan, pDevTbl->pBSP); if (pEnd == NULL) { printf("muxDevLoad failed for device entry %d!\n", count); } } } for (loopi = 0; loopi < count; loopi++) { pEnd = endFindByName("lnPci", loopi); pRouteCookie[loopi] = muxBind("lnPci", loopi, (FUNCPTR)intercom_device_mux_receive_return, NULL, NULL, NULL, END_INTERNODE_COMM, "END_INTERNODE_COMM", 0); if (pRouteCookie[loopi] == NULL) { perror("pRouteCookie:"); printf("pChannelCookie error1\n"); } muxMCastAddrAdd(pEnd, bAllNodeMacAddress); muxMCastAddrAdd(pEnd, bAllSlaveMacAddress); muxDevStart(pEnd); /*Start ip protocol*/ ipAttach(loopi, "lnPci"); memset(ipaddr, 0, 40); sprintf(ipaddr, "192.168.%d.%d", 237+loopi, sysProcNumGet()); usrNetIfConfig("lnPci", loopi, ipaddr, "", 0); } /*网口初始化结束,下面开始socket初始化和发包程序*/ /* create a socket */ sockd = socket(AF_INET, SOCK_DGRAM, 0); if (sockd == -1) { perror("Socket creation error"); exit(1); } /* client address */ my_addr.sin_family = AF_INET; my_addr.sin_addr.s_addr = INADDR_ANY; my_addr.sin_port = 0; bind(sockd, (struct sockaddr*)&my_addr, sizeof(my_addr)); memset(buf, 0xab, 1465); printf("sent. buff length %d\n", strlen(buf)); /* server address */ srv_addr.sin_family = AF_INET; inet_aton("192.168.238.2", &srv_addr.sin_addr); srv_addr.sin_port = htons(atoi("5555")); taskDelay(3*100); for (loopi = 0; loopi < 2000; loopi++) { //printf("sent. buff length %d\n", strlen(buf));=============================1 sendto(sockd, buf, strlen(buf)+1, 0, (struct sockaddr*)&srv_addr, sizeof(srv_addr)); //taskDelay(1);==========================2 } printf("sent over\n"); close(sockd);}