linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfgang <wutz@unterderbruecke.de>
To: linux-can@vger.kernel.org
Subject: Re: recv list
Date: Thu, 5 Jan 2012 21:24:25 +0000 (UTC)	[thread overview]
Message-ID: <loom.20120105T215714-788@post.gmane.org> (raw)
In-Reply-To: 20120105120930.GA372@e-circ.dyndns.org

> Note that this bridge puts the originating source address as bridged
destination address.
> This does not matter for PDU2 type of PGN's (== PDU-specific is not the 
> destination address), it may not be completely right.
> 
> I'd expect to 'empty' (== put J1939_NO_ADDR) the src_addr.can_addr.j1939.addr 
> member before sendto(), resulting in a broadcasted PGN.

OK I hope I fixed that, I want to keep the originating source address and it 
should stay PDU2 type.

> In a later iteration, You could (if necessary, since I have no clue what kind
> of traffic you will bridge):
> * make the receiving socket (s) 'promiscuous', i.e. receiving all traffic.
> * fetch the original destination by using recvmsg() as illustrated in jspy.

At the moment I am also not aware what particular traffic I will bridge, I am
still 'playing' around. But the target is to place that bridge between an 
existing engine bus and an existing ECU. So different source address' the 
existing ECU is 'interested' in (but I think not in all in the network) and one 
source address from the ECU.

In the example below, I wanted, if the pgn is 0xFEF5 (this is a pgn I will 
definitely need) to print the first byte otherwise just bridge it. 
But it is not working! Could you see an error? Sorry!

int main (void)
{
	int s;
	s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
	    
	struct sockaddr_can addr;

    memset(&addr, 0, sizeof(addr));
    addr.can_ifindex = if_nametoindex("can0");
    addr.can_addr.j1939.name = J1939_NO_NAME;    
    addr.can_addr.j1939.addr = 0x00;
    addr.can_addr.j1939.pgn = J1939_NO_PGN;
    addr.can_family = AF_CAN;  
   
   
    if (bind(s, (void *)&addr, sizeof(addr))<0)
    	{
    		perror ("bind failed");
        	}
        	
     
    int s2;
	s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
	
	struct sockaddr_can addr2;	
	   
    memset(&addr2, 0, sizeof(addr2));
    addr2.can_ifindex = if_nametoindex("can1");
    addr2.can_addr.j1939.name = J1939_NO_NAME;    
    addr2.can_addr.j1939.addr = 0x3D;
    addr2.can_addr.j1939.pgn = J1939_NO_PGN;
    addr2.can_family = AF_CAN;     
   
    if (bind(s2, (void *)&addr2, sizeof(addr2))<0)
    	{
    		perror ("bind2 failed");
        	}
    int ret;
	socklen_t len; 
	struct sockaddr_can src_addr;
	char buf[128];


	while (1) {
		len = sizeof(src_addr);
		ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
		
		if (ret < 0)
		perror ("recvfrom failed");
		
		src_addr.can_addr.j1939.addr = J1939_NO_ADDR;

		/*if the frame is sent by 0x30 do this*/
		if (src_addr.can_addr.j1939.pgn == 0xFEF5)
		{
			if (ret < 0)
			perror ("no data");
			
			printf("%x\n", buf[0]);
/*I didn't get it what you wanted to tell me with the remainder*/
			
			if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
				perror("sendto failed");
						
		}
		
		/*else just bridge it*/
		else
		{ 
			if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
				perror("sendto failed");
		}

	}

  		 
  return 0;
}



--Wolfgang







  reply	other threads:[~2012-01-05 21:24 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 10:44 using j1939 wutz
2011-12-06 12:14 ` Kurt Van Dijck
2011-12-06 12:28   ` Kurt Van Dijck
2011-12-06 12:37   ` Wolfgang
2011-12-06 13:18     ` Kurt Van Dijck
2011-12-07  8:55       ` Wolfgang
2011-12-07 14:33         ` using j1939: j1939.h Kurt Van Dijck
2011-12-07 14:50           ` Kurt Van Dijck
2011-12-08 12:23             ` Wolfgang
2011-12-08 12:30               ` using j1939: userspace binaries Kurt Van Dijck
2011-12-08 12:48                 ` Wolfgang
2011-12-08 13:32                   ` Kurt Van Dijck
2011-12-08 14:27                     ` Wolfgang
2011-12-08 15:17                       ` using j1939: AF_CAN missing Kurt Van Dijck
2011-12-08 15:34                         ` Oliver Hartkopp
2011-12-08 15:19                       ` iproute2-j1939 Kurt Van Dijck
2011-12-08 15:56                         ` iproute2-j1939 Wolfgang
2011-12-08 16:44                         ` iproute2-j1939 Wolfgang
2011-12-09  6:55                           ` iproute2-j1939 Oliver Hartkopp
2011-12-09  7:28                             ` iproute2-j1939 Wolfgang
2011-12-09  7:58                               ` iproute2-j1939 Oliver Hartkopp
2011-12-09  8:07                           ` iproute2-j1939 Kurt Van Dijck
2011-12-09  8:12                             ` iproute2-j1939 Oliver Hartkopp
2011-12-09  9:02                             ` iproute2-j1939 Wolfgang
2011-12-09  9:48                               ` iproute2-j1939 Kurt Van Dijck
2011-12-09 10:56                                 ` iproute2-j1939 Wolfgang
2011-12-09 11:03                                   ` iproute2-j1939 Kurt Van Dijck
2011-12-09 11:12                                     ` iproute2-j1939 Wolfgang
2011-12-09 11:47                                       ` iproute2-j1939 Kurt Van Dijck
2011-12-09 12:14                                         ` iproute2-j1939 Wolfgang
2011-12-06 13:24     ` using j1939 Oliver Hartkopp
2011-12-09 13:47       ` Kurt Van Dijck
2011-12-09 13:58         ` Wolfgang
     [not found]           ` <20111209143224.GB309@e-circ.dyndns.org>
     [not found]             ` <20111209144911.144460@gmx.net>
2011-12-09 15:01               ` Kurt Van Dijck
2011-12-09 17:23                 ` Wolfgang Wagner
2011-12-12  8:12                   ` Kurt Van Dijck
2011-12-12 11:27                     ` Wolfgang
2011-12-12 12:40                       ` Kurt Van Dijck
2011-12-12 15:10                         ` Wolfgang
2011-12-13  9:53                           ` backporting can & can-j1939 Kurt Van Dijck
2011-12-13 15:20                             ` Wolfgang
2011-12-13 15:51                               ` Kurt Van Dijck
2011-12-13 18:49                                 ` Wolfgang
2011-12-14 13:29                                 ` Wolfgang
2011-12-14 15:43                                   ` Kurt Van Dijck
2011-12-14 18:19                                     ` Wolfgang
2011-12-14 20:42                                       ` Using " Kurt Van Dijck
2011-12-15  8:35                                         ` Wolfgang
2011-12-15  9:20                                           ` Cross-compiling iproute2-j1939 Kurt Van Dijck
2011-12-15 11:24                                             ` Wolfgang
2011-12-15 12:04                                               ` replacing iproute2 & can-utils with j1939 variants Kurt Van Dijck
2011-12-15 13:43                                                 ` Wolfgang
2011-12-15 14:00                                                   ` using can-j1939 Kurt Van Dijck
2011-12-15 14:49                                                     ` Wolfgang
2011-12-15 15:06                                                       ` Kurt Van Dijck
2011-12-15 15:16                                                         ` Wolfgang
2011-12-15 15:50                                                           ` Kurt Van Dijck
2011-12-15 16:17                                                             ` Wolfgang
2011-12-16  8:37                                                       ` Kurt Van Dijck
2011-12-16  9:00                                                         ` Wolfgang
2011-12-16  9:33                                                           ` Kurt Van Dijck
2011-12-16 14:29                                                             ` Wolfgang
2011-12-17 19:20                                                               ` Kurt Van Dijck
2011-12-20 10:35                                                                 ` API calls Wolfgang
2011-12-20 11:00                                                                   ` Kurt Van Dijck
2011-12-20 14:49                                                                     ` Wolfgang
2011-12-20 15:05                                                                       ` Kurt Van Dijck
2011-12-20 15:43                                                                         ` Wolfgang
2011-12-20 16:32                                                                           ` Kurt Van Dijck
2011-12-21 10:46                                                                             ` Wolfgang
2011-12-21 13:43                                                                               ` using can-j1939 Kurt Van Dijck
2011-12-21 15:11                                                                                 ` Wolfgang
2011-12-21 15:53                                                                                   ` Kurt Van Dijck
2011-12-22 13:06                                                                                     ` Wolfgang
2011-12-23 11:04                                                                                       ` Kurt Van Dijck
2011-12-28 10:49                                                                                         ` Wolfgang
2012-01-04  9:47                                                                                           ` Kurt Van Dijck
2012-01-04 16:28                                                                                             ` recv list Wolfgang
2012-01-04 20:41                                                                                               ` Kurt Van Dijck
2012-01-05 10:55                                                                                                 ` Wolfgang
2012-01-05 12:09                                                                                                   ` Kurt Van Dijck
2012-01-05 21:24                                                                                                     ` Wolfgang [this message]
2012-01-06 12:25                                                                                                       ` Kurt Van Dijck
2012-01-06 18:25                                                                                                         ` Wolfgang
2012-01-09  9:33                                                                                                           ` Kurt Van Dijck
2012-01-09 10:02                                                                                                             ` Changing addr with bind() Kurt Van Dijck
2012-01-09 10:23                                                                                                               ` Kurt Van Dijck
2012-01-09 10:46                                                                                                         ` recv list Wolfgang
  -- strict thread matches above, loose matches on Subject: below --
2012-01-09 13:26 Kurt Van Dijck
2012-01-09 16:35 ` Wolfgang
2012-01-10  8:51   ` Kurt Van Dijck
2012-01-10 10:45     ` Wolfgang
2012-01-10 15:23       ` Kurt Van Dijck
2012-01-12 15:23         ` Wolfgang
2012-01-12 15:43           ` Kurt Van Dijck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20120105T215714-788@post.gmane.org \
    --to=wutz@unterderbruecke.de \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).