we are doing a project based on the communication protocols for which PPP is being used to make a link between the serial interfaces. To use the kernel PPP services, PPPD is used to establish the link between two ports. The following prodcedure is used for PPP connection establishment.

On Server Side:

linux-7tmr:~ # pppd nodetach crtscts 192.168.0.1: /dev/ttyS0 9600 &
[1] 4834
linux-7tmr:~ # Using interface ppp1
Connect: ppp1 <--> /dev/ttyS0
Deflate (15) compression enabled
local IP address 192.168.0.1
remote IP address 192.168.2.1

On Client Side:

linux-7tmr:~ # pppd nodetach crtscts 192.168.2.1: /dev/ttyS1 9600 &
[1] 4813
linux-7tmr:~ # Using interface ppp0
Connect: ppp0 <--> /dev/ttyS1
Deflate (15) compression enabled
local IP address 192.168.2.1
remote IP address 192.168.0.1

After establish the ppp connection between two ports i am able send/receive test data from client to server using my UDP client /server programs ( Firtst two files in attachment).

But actually my requirement is to send data using PF_PACKET packet sockets to write/read data to/from directly from data link layer by by-passing higher layers. while using this packet socket type i am getting proper status from sento call from client
program, but i am not to receive at serverside. the following files are my client server programs using PF_PACKET socket family.



pfpacket.c


int sockid, nread, index;
char *name = "ppp0";
struct ifreq req;
struct sockaddr_ll sll;
char msg[50];

memset ( &req, 0, sizeof ( req ));
strcpy ( req.ifr_name, name );

printf("Server: creating socket\n");
if ( (sockid = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL))) < 0)
{
printf("Server: Problem creating the socket");
exit(0);
}

printf("Server: binding my local socket\n");
if ( ioctl ( sockid, SIOCGIFINDEX, &req ) < 0 )
{
printf ("Error getting interface %s index\n", name);
}
index = req.ifr_ifindex;
printf ("Index %d\n", index);
bzero ( &sll, sizeof ( sll ));
sll.sll_family = AF_PACKET;
sll.sll_hatype = ARPHRD_PPP;
sll.sll_ifindex = index;

if ( bind ( sockid, (struct sockaddr *)&sll, sizeof ( sll )) < 0 )
{
printf ("Problem binding to interface %s\n", name);
}

printf("Server: starting blocking message read\n");

while(1)
{
nread = recvfrom(sockid, msg, 15, 0, NULL,0);

if (nread > -1)
printf("Server: message is: %.11s\n",msg);
}
close(sockid);
}




pfclient.c


int sockid, retcode, index;
char *name = "ppp0";
struct ifreq req;
struct sockaddr_ll sll, sll1;
char msg[12];

memset ( &req, 0, sizeof ( req ));
strcpy ( req.ifr_name, name );


if ( ioctl ( sockid, SIOCGIFFLAGS, &req ) < 0 )
{
printf ("Error getting interface %s flags.\n%s\n", name);
}

if ( ! ( req.ifr_flags & IFF_UP ))

printf ("Bringing interface %s up\n", name );
req.ifr_flags |= IFF_UP;
if ( ioctl ( sockid, SIOCSIFFLAGS, &req ) < 0 )
{
printf ("Failed to bring interface %s up.\n%s\n", name);
}

printf("Client: creating socket\n");
if ( (sockid = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL))) < 0)
{
printf("Client: socket failed");
exit(0);
}
printf("Client: binding my local socket\n");
if ( ioctl ( sockid, SIOCGIFINDEX, &req ) < 0 )
{
printf ("Error getting interface %s index\n", name);
}
index = req.ifr_ifindex;
printf ("Index %d\n", index);
bzero ( &sll, sizeof ( sll ));
sll.sll_family = AF_PACKET;
sll.sll_hatype = ARPHRD_PPP;
sll.sll_ifindex = index;

if ( bind ( sockid, (struct sockaddr *)&sll, sizeof ( sll )) < 0 )
{
printf ("Problem binding to interface %s\n", name);
exit(0);
}

printf("Client: initializing message and sending\n");
sprintf(msg, "Hello world");

while (1)
{

retcode = sendto(sockid, msg, 12,0, NULL, 0);

printf ("Client: sent %d bytes\n", retcode);

}
if (retcode < 0)
{
printf("client: sendto failed");
exit(0);
}

close(sockid);

}

kindly help me this regard.