Hi all,

I'm currently trying to build some code using the packet socket
interface, but have run into a couple quandries that I'm hoping someone
might be able to lead me out of...

The code I'm working with right now goes something like this:  (this is
exploratory code, and isn't terribly pretty...or useful, for that
matter.)

struct Ether
{
  signed char     eth_device_name[ IFNAMSIZ + 1 ];
  signed int      eth_sock_fd;
  struct sockaddr_ll eth_addr;
};

<snip>

struct Ether  eth;
unsigned char buf[DEFAULT_MTU];
int           s;
int           result;
int           len
int           i;

s = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_IPX ) );
if (s < 0) {
  perror("IPX: socket: ");
  exit(-1);
}

strncpy( eth.eth_device_name, "eth0", IFNAMSIZ );
eth.eth_addr.sll_family = AF_PACKET;
eth.eth_addr.sll_hatype = PACKET_OTHERHOST;
eth.eth_addr.sll_halen = IFHWADDRLEN;

len = sizeof(eth.eth_addr);
result = getsockname(s, (struct sockaddr *)&eth.eth_addr, &len);

/* Attempt to bind the socket to the interface */
if( bind( s, (struct sockaddr *)&eth.eth_addr, sizeof( struct
sockaddr_ll ) ) != 0 ) {
  perror("IPX: open");
  close( s );
  return;
}

eth.eth_sock_fd = s;

set_if_promisc_mode( &eth );
while(1) {      
  result = read(eth.eth_sock_fd, buf, DEFAULT_MTU);
  if( result < 0 ) {
    fprintf( stderr, " [RECV-IPX-PACKET: Read error : %s]\n", strerror(
errno ) );
    exit(1);
  }

  print_packet_data(buf, result);
  printf("\nSize: %d bytes\n\n", result);

  /* Test the re-send */
  result = sendto(eth.eth_sock_fd, buf, sizeof(buf), 0, (struct sockaddr
*)&(eth.eth_addr),
                    sizeof( struct sockaddr_ll ));
  if (result < 0) {
    perror("ECHO: send");
    exit(-1);
  }
}

The basic jist of this code is that I want to read in all the raw IPX
packets on my local network and echo them back out.

Ultimately, I'm having a couple problems.  The first (which will
probably be solved by the second), is that whenever I make the call to
sendto(2), it errs with: Device not initialized. I can recieve packets
fine, but sending them is a problem. (Personally, I suspect that the
only reason I am receiving packets is because I have the driver in
promiscuous mode.)

My second problem is initiallizing the sockaddr_ll structure.  The
getsockbyname call certainly is doing something productive, but not what
I need.  (Without the call, the bind fails...however, even with it, the
hll_haddr field has the wrong address for my NIC). What would be the
SMART way of getting all the pertinent information I need about an
ethernet device from it's device name? (eg. eth0) 

My final goal is an IPX-over-IP tunnel.  I've looked at the code for
tipxd, but they are using the apparently deprecated SOCK_PACKET
interface, with sockaddr_in structures...

Any help would be greatly appreciated,

Jonathan Kovacs
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to