raw socket

From: Nelson (tanginhw@comp.nus.edu.sg)
Date: Thu Jun 01 2000 - 05:19:54 EST


i created a raw socket using

sockid=socket(PF_PACKET,SOCK_RAW, htons(ETH_P_ALL)); and it returns fine.

however, if i want to send something out from the socket, it returns me an
error. i used the following code to send the data:

struct sockaddr_in test;
test.sin_addr.s_addr = htonl(INADDR_LOOKBACK);
/* is the above required since it is a raw socket? */

char *data;
data = malloc(20);
memcpy(data, <src addr>, 6) /* setting up the src mac addr */
memcpy(data+6, <dst addr>, 6) /* setting up the dst mac addr */
memcpy(data+12, <protocol>, 2) /* setting up the protocol */
memcpy(data+14, <some data>, <data len>); /* putting in the data to send*/
sendto(sockid, data, 20, 0, (struct sockaddr*)&test, sizeof(test);

the error is invalid argument.
any help will be greatly appreciated. thanx.

"You will never walk alone"

To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.rutgers.edu

This archive was generated by hypermail 2b29 : Wed Jun 07 2000 - 21:00:32 EST