Perhaps I should clarify: You are binding a PF_PACKET socket to an AF_INET address. Try me.sll_family = AF_PACKET instead. Amit Kucheria wrote: > On Sat, 15 Dec 2001, Casey Carter wrote: > > >>AF_INET? >> >>Amit Kucheria wrote: >> >> >>>Can anybody explain whats wrong with the following piece of code? >>> >>>Specifically, the bind() fails. I have a clue that its something to do >>>with packet sockets, but what ? I checked my kernel, packet sockets are >>>compiled in. >>> >>>------------------------------------------------- >>>struct sockaddr_ll me, he; >>> >>>int main(int argc, char *argv[]) >>>{ >>> struct sockaddr hwaddr; >>> >>> if (argc < 2) >>> { >>> usage(argv[0]); >>> exit(1); >>> } >>> strcpy(device, argv[1]); >>> >>> sockfd = socket(PF_PACKET, SOCK_DGRAM, 0); >>> if (sockfd < 0) >>> { >>> DBG("main(): unable to create socket\n"); >>> perror("main()"); >>> return -1; >>> } >>> >>> req_dest.s_addr = address_generate(); /* linklocal address we want to own */ >>> req_src.s_addr = 0; /* send with IP addr 0.0.0.0 */ >>> >>> ret = get_ether_addr(device, &hwaddr); >>> if (ret < 0) >>> { >>> ERR("main(): get_ether_addr failed\n"); >>> exit(-1); >>> } >>> me.sll_family = AF_INET; >>> me.sll_ifindex = ifindex; >>> me.sll_protocol = htons(ETH_P_ARP); >>> if (bind(sockfd, (struct sockaddr*)&me, sizeof(me)) == -1) >>> { >>> perror("main(): bind"); >>> exit(2); >>> } >>> > > But i need to use PF_PACKET type to create a socket to 'bypass' the > protocol layers and send the packet directly to the ethernet layer (link > layer). I dont think AF_INET with SOCK_RAW would support struct > sockaddr_ll. > > Regards, > Amit > > -- Casey Carter Casey@Carter.net ccarter@uiuc.edu AIM: cartec69 - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html