recvfrom not receiving ethernet packets!
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:content-type:content-transfer-encoding :subject:date:references:to:message-id:mime-version:x-mailer; bh=Ujz1UF61e9Dy3DIkUjG0VWtW9wjyBnEAZEKRFft6A+8=; b=YBdVRX4v8z+PhyGiMKE6p6Lv/u6FZJo5BQaNZwxLytNmVv7FBdmfKy0RK6dNiYFCp/ /0yqC4XNGeLH32t9jeJycptQlnhyeJiIuKKSuEpHf03CzqVwYcbbZpCu0Z6aLULaUZkO Adk/P3KxiDZYSljccf7YYYoe+ul92A7P3ESec= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:content-type:content-transfer-encoding:subject:date:references :to:message-id:mime-version:x-mailer; b=R64CknhFXjoJpwl4a7PBlTNLZoaw05BBcl0pSF7SURpTXdVwRX9sxJLSHHf/2Dh4xp PPQ78XmMI32AR4ZyfiZ4QikqgCxaep55U5aW1O2ibcpJACPL+CJaUZGI+mqvJ4x8SLc3 SPJS1ZX6X/Y+3dre81xfWOBjPgc76vMRNrTAw= Hi all, I have been trying to build a simple program to write an Ethernet packet and other to read an Ethernet packet. The one that writes seems to be working fine (I can see the packet in Wireshark) but the reading does not work; it just keeps waiting. Can anyone help me to find out the problem? Here is the code. Thanks, Daniel Writing program (works fine): main() { int fd; int result, write; struct ndrv_protocol_desc prot_desc; struct ndrv_demux_desc demux_desc[1]; struct sockaddr_ndrv ndrv; u_int8_t packet[1000]; //Open socket fd = socket(PF_NDRV, SOCK_RAW, 0); //error handing //Bind to interface en1 strlcpy((char*)ndrv.snd_name, "en1", sizeof(ndrv.snd_name)); ndrv.snd_len = sizeof(ndrv); ndrv.snd_family = AF_NDRV; bind(fd, (struct sockaddr*)&ndrv, sizeof(ndrv)); //error handing //Build packet memset(&packet, 0, sizeof(packet)); //Destination MAC address - here goes my en1 MAC address packet[0] = 0x00; packet[1] = 0x21; packet[2] = 0x41; packet[3] = 0x21; packet[4] = 0x11; packet[5] = 0x31; //Source MAC address - fictitious MAC address packet[6] = 0x12; packet[7] = 0x23; packet[8] = 0x34; packet[9] = 0x45; packet[10] = 0x56; packet[11] = 0x67; //Set packet type - this is the type field in the frame; no specific reason for this number but I think must match the demux descriptor in the reading program. packet[12] = 0x0f; packet[13] = 0x0f; //Some Data strcpy((char*)&packet[14], "ABCDEFGHIJKLMNOPQRSTUVWXZ1234567890 This is a test \0"); //Send packet write = sendto(fd, &packet, 1014, 0, (struct sockaddr*)&ndrv, sizeof(ndrv)); //error handling close(fd); return; } Reading program (not working, it keeps waiting for packet): main() { int fd; int read; struct ndrv_protocol_desc prot_desc; struct ndrv_demux_desc demux_desc[1]; struct sockaddr_ndrv ndrv; u_int8_t buffer[1000]; //Open socket fd = socket(PF_NDRV, SOCK_RAW, 0); //error handing //Bind to interface en1 ndrv.snd_len = sizeof(ndrv); ndrv.snd_family = AF_NDRV; strlcpy((char*)ndrv.snd_name, "en1", sizeof(ndrv.snd_name)); bind(fd, (struct sockaddr*)&ndrv, sizeof(ndrv)); //error handing //Define protocol prot_desc.version = (u_int32_t)1; prot_desc.protocol_family = (u_int32_t)13458; //Just a number that do not match any other protocol defined in the interface prot_desc.demux_count = (u_int32_t)1; prot_desc.demux_list = (struct ndrv_demux_desc*)&demux_desc; //Define DEMUX demux_desc[0].type = NDRV_DEMUXTYPE_ETHERTYPE; demux_desc[0].length = 2; demux_desc[0].data.ether_type = htons(0x0f0f); //same as ethernet type in the writing program //Set protocol using socket options setsockopt(fd, SOL_NDRVPROTO, NDRV_SETDMXSPEC, (caddr_t)&prot_desc, sizeof(prot_desc)); //error handing //Receive packet read = recvfrom(fd, &buffer, sizeof(buffer), 0, NULL, NULL); //error handing close(fd); return; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Daniel Zuniga